# Identity Stitching

**Identity Stitching** is a feature that allows you to attribute all events received from an anonymous user to a known user after logging in.

Jitsu retroactively updates anonymous events in supported destinations with user traits. 

Identity Stitching relies on Deduplication feature and is available for the following destinations:

- [ClickHouse](/docs/destinations/warehouse/clickhouse)
- [BigQuery](/docs/destinations/warehouse/bigquery)
- [PostgreSQL](/docs/destinations/warehouse/postgres)
- [Redshift](/docs/destinations/warehouse/redshift)
- [Snowflake](/docs/destinations/warehouse/snowflake)
- [MySQL](/docs/destinations/warehouse/mysql)

## How it works

For each unidentified user Jitsu client library generates a unique anonymous ID and tries to store it in browser's cookies (If cookies consent was granted).
If it is allowed to store anonymous ID, Jitsu client will add `anonymousId` field to all events produced with that.

Jitsu server uses separate intermediate storage to keep the last **30 days** of events for each anonymous user. 

When `identify` method is called Jitsu client adds `userId` field and `traits` to the events while keeping `anonymousId` in place.

Jitsu server loads all events for that `anonymousId` from storage, enriches them with `userId` field and user `traits`, and sends them to the destination.

Thanks to the [Deduplication](/docs/features/deduplication) feature, instead of producing duplicated events, Jitsu will update existing events with enriched data.

### Example

Let's say we have a website with a following events flow:

Anonymous user had some activity on the website at Jan 1, then 23 days later he decided to signed up.

Without Identity Stitching, we could have the following table in a data warehouse:

| timestamp           | type     | path    | anonymous_id | user_id | context_traits_email |
|---------------------|----------|---------|--------------|---------|----------------------|
| 2023-01-01 00:00:00 | page     | /shop   | abc123       |         |                      |
| 2023-01-01 00:01:00 | page     | /order  | abc123       |         |                      |
| 2023-01-23 00:00:00 | page     | /signup | abc123       |         |                      |
| 2023-01-23 00:01:00 | identify | /signup | abc123       | 1001    | test@example.com     |

With **Identity Stitching**, Jitsu will reprocess events with `anonymous_id=abc123` and we will have the following table:

| timestamp           | type     | path    | anonymous_id | user_id | context_traits_email |
|---------------------|----------|---------|--------------|---------|----------------------|
| 2023-01-01 00:00:00 | page     | /shop   | abc123       | 1001    | test@example.com     |
| 2023-01-01 00:01:00 | page     | /order  | abc123       | 1001    | test@example.com     |
| 2023-01-23 00:00:00 | page     | /signup | abc123       | 1001    | test@example.com     |
| 2023-01-23 00:01:00 | identify | /signup | abc123       | 1001    | test@example.com     |

## How to enable

You can enable Identity Stitching on the **Connection** editing page in the **Advanced** section:

(For a self-hosted Jitsu, there are [additional requirements](http://localhost:4112/self-hosting/production-deployment#mongodb_url-optional).
)

<Screenshot src="/docs/screenshots/identity-stitching.png" />