# Anonymous tracking for the React Native tracker
> Enable anonymous tracking to disable user and session identifiers with client-side and server-side anonymization options.
> Source: https://docs.snowplow.io/docs/sources/react-native-tracker/anonymous-tracking/
> Documentation index: https://docs.snowplow.io/llms.txt

Anonymous tracking is a feature that enables anonymization of various user and session identifiers, to support user privacy when consent for tracking the identifiers isn't given.

On React Native, the following [user and session identifiers](/docs/events/identifiers/) can be anonymized:

- Client-side user identifiers:

  - `user_id`, `domain_userid`, `network_userid`, and `user_ipaddress`, set by you in `Subject`
  - `userId`, a device ID, set automatically in the [session](/docs/sources/web-trackers/tracking-events/session/) entity
  - For mobile only, IDFA identifiers (`appleIdfa` and `appleIdfv` for iOS, `androidIdfa` for Android) in the mobile entity [if configured](/docs/sources/react-native-tracker/tracking-events/platform-and-application-context/#platform-context)

- Client-side session identifiers:
  - `previousSessionId` in the session entity, set automatically by the tracker

- Server-side user identifiers:
  - `network_userid` and `user_ipaddress`, set by the [Collector](/docs/pipeline/collector/)

> **Note: User-set properties**
>
> The Collector captures the IP address from the request HTTP headers, and updates the `user_ipaddress` event property. However, if you set the `user_ipaddress` property in the `Subject`, that value has priority.
>
> Similarly, if you set the `network_userid` property in the `Subject`, that value is used instead of the Collector cookie value.

Read more about anonymous tracking in the [overview page](/docs/events/anonymous-tracking/).

There are several levels to the anonymization depending on which of the categories are affected.

## Available anonymization options

Because of a change in architecture, the anonymous tracking options for the React Native tracker changed between version 2.x and version 4.x.

| Feature                                         | Version 4.x | Version 1.3 - 2.x |
| ----------------------------------------------- | ----------- | ----------------- |
| Full client-side anonymization                  | ❌           | ✅                 |
| Client-side anonymization with session tracking | ❌           | ✅                 |
| Toggle anonymous tracking at runtime            | ❌           | ✅                 |
| Server-side anonymization                       | ✅           | ✅                 |

## 1. Full client-side anonymization

In this case, you anonymize both client-side user identifiers and client-side session identifiers. This means disabling the session entity altogether.

**Version 4.x:**

```typescript
const tracker = await newTracker({
    namespace: 'appTracker',
    endpoint: COLLECTOR_URL,
    sessionContext: false, // Session entity won't be added to events
    platformContext: false, // Mobile entity won't be added to events

});
```

| Identifier          | Location in event        | Included in event?  |
| ------------------- | ------------------------ | ------------------- |
| `user_id`           | Atomic                   | ✅ if set            |
| `domain_userid`     | Atomic                   | ✅ if set            |
| `userId`            | Session entity           | ❌ no session entity |
| `sessionId`         | Session entity           | ❌ no session entity |
| `previousSessionId` | Session entity           | ❌ no session entity |
| `appleIdfa`         | Mobile (platform) entity | ❌ no mobile entity  |
| `appleIdfv`         | Mobile (platform) entity | ❌ no mobile entity  |
| `androidIdfa`       | Mobile (platform) entity | ❌ no mobile entity  |
| `network_userid`    | Atomic                   | ✅                   |
| `user_ipaddress`    | Atomic                   | ✅                   |

**Version 1.3 - 2.x:**

```typescript
const tracker = createTracker(
    'appTracker',
    { endpoint: COLLECTOR_URL },
    {
        trackerConfig: {
            sessionContext: false,   // Session entity won't be added to events
            userAnonymisation: true, // Remove user identifiers from Subject and platform entity
        },
    }
);
```

| Identifier          | Location in event        | Included in event?                            |
| ------------------- | ------------------------ | --------------------------------------------- |
| `user_id`           | Atomic                   | ❌                                             |
| `domain_userid`     | Atomic                   | ❌                                             |
| `userId`            | Session entity           | ❌ no session entity                           |
| `sessionId`         | Session entity           | ❌ no session entity                           |
| `previousSessionId` | Session entity           | ❌ no session entity                           |
| `appleIdfa`         | Mobile (platform) entity | ❌                                             |
| `appleIdfv`         | Mobile (platform) entity | ❌                                             |
| `androidIdfa`       | Mobile (platform) entity | ❌                                             |
| `network_userid`    | Atomic                   | ✅/❌ removed if you provided this in `Subject` |
| `user_ipaddress`    | Atomic                   | ✅/❌ removed if you provided this in `Subject` |

***

## 2. Client-side anonymization with session tracking

This setting disables client-side user identifiers but tracks session information.

**Version 4.x:**

Newer versions of the React Native tracker don't support client-side anonymization with session tracking. Unlike in version 2.x, you can't track the session entity with an anonymized `userId`.

**Version 1.3 - 2.x:**

```typescript
const tracker = createTracker(
    'appTracker',
    { endpoint: COLLECTOR_URL },
    {
        trackerConfig: {
            sessionContext: true,    // Session entity is tracked
            userAnonymisation: true, // User identifiers anonymized
        },
    }
);
```

With `userAnonymisation: true` and `sessionContext: true`, events include the session entity but the `userId` property is set to a null UUID (`00000000-0000-0000-0000-000000000000`). The IDFA identifiers are also removed from the platform entity.

| Identifier          | Location in event        | Included in event?                            |
| ------------------- | ------------------------ | --------------------------------------------- |
| `user_id`           | Atomic                   | ❌                                             |
| `domain_userid`     | Atomic                   | ❌                                             |
| `userId`            | Session entity           | ❌ null UUID                                   |
| `sessionId`         | Session entity           | ✅                                             |
| `previousSessionId` | Session entity           | ❌                                             |
| `appleIdfa`         | Mobile (platform) entity | ❌                                             |
| `appleIdfv`         | Mobile (platform) entity | ❌                                             |
| `androidIdfa`       | Mobile (platform) entity | ❌                                             |
| `network_userid`    | Atomic                   | ✅/❌ removed if you provided this in `Subject` |
| `user_ipaddress`    | Atomic                   | ✅/❌ removed if you provided this in `Subject` |

> **Note: Toggling anonymous tracking**
>
> When anonymous tracking is enabled or disabled using `tracker.setUserAnonymisation(true | false)`, the tracker starts a new session. This results in a new `sessionId`.

***

## 3. Server-side anonymization

Server-side anonymization affects user identifiers set by the Collector: the `network_userid` property (set in the server-side cookie) and the user IP address. Use the `serverAnonymization` flag to prevent the Collector from setting these values.

> **Note: Spelling**
>
> The new API uses the US English spelling "anonymization", rather than the British English "anonymisation" seen in the older API.

**Version 4.x:**

```typescript
const tracker = await newTracker({
    namespace: 'appTracker',
    endpoint: COLLECTOR_URL,
    serverAnonymization: true,
});
```

**Version 1.3 - 2.x:**

```typescript
const tracker = createTracker(
    'appTracker',
    { endpoint: COLLECTOR_URL },
    {
        emitterConfig: {
            serverAnonymisation: true,
        },
    }
);
```

***

Setting this flag adds an `SP-Anonymous` HTTP header to requests sent to the Collector. The Snowplow pipeline then anonymizes the `network_userid` and `user_ipaddress` identifiers.

| Identifier          | Location in event        | Included in event?                                  |
| ------------------- | ------------------------ | --------------------------------------------------- |
| `user_id`           | Atomic                   | ✅ if set                                            |
| `domain_userid`     | Atomic                   | ✅ if set                                            |
| `userId`            | Session entity           | ✅                                                   |
| `sessionId`         | Session entity           | ✅                                                   |
| `previousSessionId` | Session entity           | ✅                                                   |
| `appleIdfa`         | Mobile (platform) entity | ✅ if set                                            |
| `appleIdfv`         | Mobile (platform) entity | ✅ if set                                            |
| `androidIdfa`       | Mobile (platform) entity | ✅ if set                                            |
| `network_userid`    | Atomic                   | ❌/✅ still present if you provided this in `Subject` |
| `user_ipaddress`    | Atomic                   | ❌/✅ still present if you provided this in `Subject` |

## 4. Full anonymization

Full anonymization combines client-side and server-side anonymization to remove all user and session identifiers from events.

**Version 4.x:**

Avoid configuring unwanted identifiers for full anonymization in version 4.x of the React Native tracker.

```typescript
const tracker = await newTracker({
    namespace: 'appTracker',
    endpoint: COLLECTOR_URL,
    sessionContext: false,     // No session entity
    serverAnonymization: true, // Collector won't set network_userid or capture IP
    },
});
```

| Identifier          | Location in event        | Included in event?                                  |
| ------------------- | ------------------------ | --------------------------------------------------- |
| `user_id`           | Atomic                   | ✅ if set                                            |
| `domain_userid`     | Atomic                   | ✅ if set                                            |
| `userId`            | Session entity           | ❌ no session entity                                 |
| `sessionId`         | Session entity           | ❌ no session entity                                 |
| `previousSessionId` | Session entity           | ❌ no session entity                                 |
| `appleIdfa`         | Mobile (platform) entity | ✅ if set                                            |
| `appleIdfv`         | Mobile (platform) entity | ✅ if set                                            |
| `androidIdfa`       | Mobile (platform) entity | ✅ if set                                            |
| `network_userid`    | Atomic                   | ❌/✅ still present if you provided this in `Subject` |
| `user_ipaddress`    | Atomic                   | ❌/✅ still present if you provided this in `Subject` |

**Version 1.3 - 2.x:**

```typescript
const tracker = createTracker(
    'appTracker',
    { endpoint: COLLECTOR_URL },
    {
        trackerConfig: {
            sessionContext: false,     // Session entity won't be added to events
            userAnonymisation: true,   // Remove user identifiers from Subject and platform entity
        },
        emitterConfig: {
            serverAnonymisation: true, // Collector won't set network_userid or capture IP
        },
    }
);
```

| Identifier          | Location in event        | Included in event?  |
| ------------------- | ------------------------ | ------------------- |
| `user_id`           | Atomic                   | ❌                   |
| `domain_userid`     | Atomic                   | ❌                   |
| `userId`            | Session entity           | ❌ no session entity |
| `sessionId`         | Session entity           | ❌ no session entity |
| `previousSessionId` | Session entity           | ❌ no session entity |
| `appleIdfa`         | Mobile (platform) entity | ❌                   |
| `appleIdfv`         | Mobile (platform) entity | ❌                   |
| `androidIdfa`       | Mobile (platform) entity | ❌                   |
| `network_userid`    | Atomic                   | ❌                   |
| `user_ipaddress`    | Atomic                   | ❌                   |

***
