# Tracking specific client-side properties
> Add user properties and device information to events using the Subject class in Java tracker v0.12.
> Source: https://docs.snowplow.io/docs/sources/java-tracker/previous-versions/java-tracker-v0-12/tracking-specific-client-side-properties/
> Documentation index: https://docs.snowplow.io/llms.txt
> Status: Previous version
> Current version: https://docs.snowplow.io/docs/sources/java-tracker/

An event describes a single, transient activity. The context in which that event occurs - the relatively persistent environment - is also incredibly valuable data. As discussed on the previous page, the most powerful way to track such data is to use [custom self-describing JSON entities](/docs/sources/java-tracker/previous-versions/java-tracker-v0-12/custom-tracking-using-schemas/). These are sent as JSON in the raw event payload. Depending on your data warehouse, event context entities are loaded into their own tables, or remain as JSON in the loaded event.

The Java tracker provides an additional "primitive" method to track a small subset of contextual data, using the `Subject` class. As with the "primitive" [event](/docs/sources/java-tracker/previous-versions/java-tracker-v0-12/tracking-events/) types, e.g. `PageView`, `Subject` properties directly populate the "atomic" fields of the raw event payload. These data will always end up in individual columns of the main event table in the data warehouse.

The fields tracked using `Subject` tend to be most relevant in client-side tracking. Some are set automatically in all events during enrichment, even when no `Subject` is added. These properties are marked with `*` below, and discussed below. Timezone, marked with `**`, is only set when a `Subject` is tracked with the event.

Add these fields to an event using `Subject`:

| Property         | Field in raw event | Column(s) in enriched event           |
| ---------------- | ------------------ | ------------------------------------- |
| userId           | uid                | user\_id                              |
| ipAddress\*      | ip                 | user\_ipaddress                       |
| timezone\*\*     | tz                 | os\_timezone                          |
| language         | lang               | br\_lang                              |
| useragent\*      | ua                 | useragent                             |
| viewport         | vp                 | br\_viewheight, br\_viewwidth         |
| screenResolution | res                | dvce\_screenheight, dvce\_screenwidth |
| colorDepth       | cd                 | br\_colordepth                        |
| networkUserId\*  | tnuid              | network\_userid                       |
| domainUserId     | duid               | domain\_userid                        |
| domainSessionId  | sid                | domain\_sessionid                     |

Note: the ability to set `domainSessionId` was added in version 0.11.

These properties are especially useful for client-side tracking, or for linking client-side and server-side tracking. We highly recommend tracking in both client-side and server-side, if it's relevant to your application. Read more about this in these [blog](https://snowplow.io/blog/2019/02/05/how-server-side-tracking-fills-holes-in-your-data-and-improves-your-analytics/) [posts](https://snowplow.io/blog/2021/11/09/the-unrivaled-power-of-joining-client-and-server-side-tracking/).

If you are also using the Javascript tracker, it will set [cookies](/docs/sources/web-trackers/cookies-and-local-storage/) in the browser. The `Subject` properties `domainUserId`, and `domainSessionId` are intended to be used for extracted cookie values passed to the Java tracker. If you want to track other identification tokens, we recommend creating schemas and using context entities.

As always, be aware of privacy when tracking [personal identifiable information](https://snowplow.io/blog/2020/09/06/user-identification-and-privacy/) such as email addresses or IP addresses.

### Overriding autogenerated event properties

All enriched Snowplow events contain values for `user_ipaddress`, `useragent`, and `network_userid`.

The `user_ipaddress` is automatically added to all enriched events. To manually override this, use a `Subject` and set a `ipAddress` string; use an empty string to prevent IP address tracking. Alternatively, use the [IP anonymization enrichment](/docs/pipeline/enrichments/available-enrichments/ip-anonymization-enrichment/).

The `useragent` is also automatically added during enrichment. Snowplow pipelines provide multiple useragent-parsing [enrichments](/docs/pipeline/enrichments/available-enrichments/). To manually override the detected useragent, use a `Subject` and set a `useragent` string. For the default Tracker configuration with OkHttp, the default `useragent` will be "okhttp/4.2.2".

The `network_userid` is the cookie value for the event collector’s third-party cookie. It is the server-side user identifier. The cookie is named `sp` (or `micro` for Snowplow Micro pipelines). The default behavior is for the collector to provide a new cookie/`network_userid` for each event it receives. To override the collector cookie’s value with your own generated ID, use a `Subject` object and set `networkUserId`.

A further property, `timezone`, is generated automatically during Subject initialization, based on `Calendar.getInstance().getTimeZone()`. Therefore, this will be added to all events with a `Subject` attached. The default will be overriden if `timezone` is provided explicitly.

### Adding `Subject` properties to events

There are two ways to track the `Subject` "atomic" properties in your events: on an event-by-event basis; or globally, to affect all events. A combination of both methods is also possible.

A simple `Subject` initialisation looks like this:

```java
Subject subject = new Subject.SubjectBuilder()
        .userId("java@snowplow.io")
        .build();
```

There are no required methods for the `SubjectBuilder`.

A `Subject` can be added to any event using the `subject()` `Event.Builder` method:

```java
// This example shows an Unstructured event, but all events can have a Subject
Unstructured unstructured = Unstructured.builder()
            .eventData(dataAsSelfDescribingJson)
            .subject(subject)
            .build();
```

To set `Subject` properties in all subsequent events, add a `Subject` to your `Tracker` object:

```java
// A Subject can be provided at Tracker initialisation
Tracker tracker = new Tracker
        .TrackerBuilder(emitter, "trackerNamespace", "appId")
        .subject(subject)
        .build();

// Alternatively, a Subject can be set later
Tracker tracker = new Tracker
        .TrackerBuilder(emitter, "trackerNamespace", "appId")
        .build();
tracker.setSubject(subject);
```

Subject properties can be updated or added to after initialization, using setter methods. See the [API docs](https://snowplow.github.io/snowplow-java-tracker/index.html?com/snowplowanalytics/snowplow/tracker/Subject.html) for full details.

It's possible to use both `Event`-specific and `Tracker`-associated `Subject` objects simultaneously. Fields from both `Subject` objects are added to the payload, with the `Event`-specific `Subject` having priority.

```java
// Adding a global, Tracker-associated Subject
Subject trackerSubject = new Subject.SubjectBuilder()
        .language("EN")
        .useragent("Snowplow")
        .build();
Tracker tracker = new Tracker
        .TrackerBuilder(emitter, "trackerNamespace", "appId")
        .subject(trackerSubject)
        .build();

// Adding an Event-specific Subject
Subject eventSubject = new Subject.SubjectBuilder()
        .userId("java@snowplow.io")
        .useragent("Mozilla/5.0")
        .build();

Unstructured unstructured = Unstructured.builder()
        .eventData(dataAsSelfDescribingJson)
        .subject(eventSubject)
        .build();

// Tracking the event
tracker.track(unstructured);
```

The resulting enriched event would have these `Subject` atomic columns populated:

| Column in enriched event | Value / example value                       | Source         |
| ------------------------ | ------------------------------------------- | -------------- |
| user\_id                 | "<java@snowplow.io>"                        | eventSubject   |
| os\_timezone             | e.g. "Europe/London"                        | eventSubject   |
| br\_lang                 | "EN"                                        | trackerSubject |
| useragent                | "Mozilla/5.0"                               | eventSubject   |
| network\_userid          | e.g. "8383057f-2769-4321-ad72-58fa1b22e4b3" | pipeline       |
