Skip to content

Commit

Permalink
Update docs Java tracker version 2.0.0 (#751)
Browse files Browse the repository at this point in the history
  • Loading branch information
matus-tomlein authored Jan 26, 2024
1 parent 9609a28 commit 80602d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,22 @@ The default thread pool uses non-daemon threads. To stop the threads and shut do

### Persisting cookies using a CookieJar

As described [here](/docs/collecting-data/collecting-from-own-applications/java-tracker/tracking-specific-client-side-properties/index.md), the event collector sets a third-party cookie. This cookie is extracted during event processing (enrichment phase) into the `network_userid` property, the server-side user identifier. To persist this cookie across requests, add a `CollectorCookieJar` when creating your `BatchEmitter` or `Tracker`. Note that the `CollectorCookieJar` is an in-memory cookie jar, so the cookies, and `network_userid`, will not persist when it goes out of memory.
:::note
The `OkHttpClientWithCookieJarAdapter` was released in the version 2.0.0 of the Java tracker.
:::

Any custom `OkHttp` `CookieJar` could be used instead.
As described [here](/docs/collecting-data/collecting-from-own-applications/java-tracker/tracking-specific-client-side-properties/index.md), the event collector sets a third-party cookie. This cookie is extracted during event processing (enrichment phase) into the `network_userid` property, the server-side user identifier. To persist this cookie across requests, use the `OkHttpClientWithCookieJarAdapter` when creating your `BatchEmitter` or `Tracker`. Note that the `OkHttpClientWithCookieJarAdapter` uses an in-memory cookie jar, so the cookies, and `network_userid`, will not persist when it goes out of memory.

The simplest implementation looks like this:
```java
Tracker tracker = Snowplow.createTracker(
new TrackerConfiguration("namespace", "appId"),
new NetworkConfiguration("http://collector").cookieJar(new CollectorCookieJar()));
new NetworkConfiguration(new OkHttpClientWithCookieJarAdapter("http://collector")));

// A BatchEmitter can also be created directly
BatchEmitter emitter = new BatchEmitter(networkConfig);
```

The specified `CookieJar` will be ignored if a custom `HttpClientAdapter` is provided. To use a `CookieJar` with a custom `OkHttpClientAdapter`, it must be added using the `OkHttpClient.Builder`:

```java
Expand All @@ -272,6 +275,8 @@ Tracker tracker = Snowplow.createTracker(
new NetworkConfiguration(adapter));
```

Any custom `OkHttp` `CookieJar` (other than the `CollectorCookieJar` provided in the tracker) could be used instead.

### Using the Emitter callback

To gain visibility on tracker activity, you may wish to take advantage of the `EmitterCallback` interface. This interface was added in v1.0.0, and requires `onSuccess()` and `onFailure()` methods.You can use `EmitterCallback` to create your own tracker metrics.
Expand Down
2 changes: 1 addition & 1 deletion src/componentVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const versions = {
golangTracker: '3.0.0',
googleAmpTracker: '1.1.0',
iosTracker: '5.6.0',
javaTracker: '1.0.1',
javaTracker: '2.0.0',
javaScriptTracker: '3.19.0',
luaTracker: '0.2.0',
phpTracker: '0.7.0',
Expand Down

0 comments on commit 80602d9

Please sign in to comment.