# Anonymous events

Start logging events before people sign up or log into your site, app, or service. When people sign up or log in, you can associate those events with people. Anonymous events help you do things like personalize your onboarding campaigns based on things people did before they signed up. For example, if a customer viewed a pricing plan before signing up for a trial, your onboarding campaign might cover features relevant to the plan they viewed.

An **anonymous event** is an event associated with a person you don’t recognize. The event bears an `anonymous_id`—a value representing the unknown person, like a cookie. We store these events for up to 30 days.

The **Anonymous event merge** feature lets you associate these events with a person after you identify them. You can enable anonymous event merging in your workspace settings.

*   **If you use the JavaScript snippet (client-side)**: we automatically log anonymous events and associate them with people you identify.
*   **If you use the API (server-side)**: When you log anonymous events, you’ll set an `anonymous_id` on the event. When you [identify](/integrations/api/track/#operation/identify) people, you can set an `anonymous_id` attribute, and we’ll associate any events with the matching `anonymous_id` that we received up to five minutes after your `identify` call. If you identify a person then try to merge anonymous events more than five minutes after the `identify` call, the anonymous events will not merge into the profile. If you want to merge anonymous events more than 5 minutes after the initial identify call, you must resend the events by updating the anonymous id of the event then sending another identify call where you update the anonymous id of the identified profile to the new anonymous event id.

[![Flow to associate anonymous events with people](https://docs.customer.io/images/anonymous-event-chart.jpg)](#903d044e5886b8ac49b0a32bcc8d8c1a-lightbox)

## Turn on anonymous event merging[](#turn-on-merging)

 When you create a new workspace, anonymous event merging is on by default

If you created your workspace before July 2021, you must [enable Anonymous event merging](/journeys/anonymous-events/#turn-on-merging) to associate anonymous events with people you identify.

Anonymous event merging is the act of associating anonymous events—events with an `anonymous_id`—with a person. When you assign an `anonymous_id` attribute to a person, any anonymous events with that same ID are associated with the person.

1.  Go to [**Settings** > **Workspace Settings**](https://fly.customer.io/workspaces/last/settings/) and click **Merge Options**.
    
    [![Find merge settings under workspace settings](https://docs.customer.io/images/advanced-settings-merge.png)](#8b2d3d6362ba414987e0cd5aabd4526a-lightbox)
    
2.  Turn on the *Anonymous event merge* setting.
3.  Set up an integration that sends events to Customer.io. While we have plenty of integrations, our [JavaScript snippet](#js-anonymous-events) makes this easy!

Now, any events with an `anonymous_id` are merged with people bearing the same `anonymous_id` attribute.

## JavaScript implementation (client-side)[](#js-anonymous-events)

You’ll use the `track` method to send anonymous events using our [JavaScript snippet (recommended)](/integrations/data-in/connections/javascript/) or our [classic JavaScript SDK](/integrations/data-in/connections/javascript/legacy-js/getting-started/).

If you’ve enabled [Anonymous event merging](/journeys/anonymous-events/), the JavaScript snippet automatically associates events (that occurred in the past 30 days) with people when you identify them.

So, for example, if a person adds items to their cart before they log in, we’ll automatically associate relevant anonymous `addedToCart` events with a person when they log in.

 JavaScript Source (Recommended)

#### JavaScript Source (Recommended)[](#JavaScript Source \(Recommended\))

```javascript
// track an anonymous event
cioanalytics.track("addedToCart", {
    product: "cool-shoes"
});

// identify the person
// if "anonymous event merging" is enabled, we'll associate the
// event with the person
cioanalytics.identify('userId', {
    // additional attributes go here
    first_name: 'cool',
    last_name: 'person',
    shipping_address: {
        city: 'San Francisco',
        state: 'CA',
        country: 'USA'
    }
});
```

 Classic JavaScript SDK

#### Classic JavaScript SDK[](#Classic JavaScript SDK)

```javascript
// track an anonymous event
_cio.track("addedToCart", { product: "cool-shoes" });

// identify the person
// if "anonymous event merging" is enabled, we'll associate the
// event with the person
_cio.identify({
    id: 'YOUR_USER_ID_HERE',
});
```

## Server-side API implementation[](#api-anonymous-events)

If you send anonymous events to us using the API or our [server-side integrations](/integrations/data-in/connections/servers/), you’ll set a person’s anonymous ID and send that ID whenever a person performs an event.

When you identifyThe Customer.io operation that adds or updates a person. When you identify a person, Customer.io either adds a person if they don’t exist in your workspace, or updates them if they do. Before you identify someone (by their email address or an ID), you can track them anonymously. a person, you can pass a person’s anonymous ID [attributeA key-value pair that you associate with a person or an object—like a person’s name, the date they were created in your workspace, or a company’s billing date etc. Use attributes to target people and personalize messages.](/journeys/attributes/). This tells us to associate events with the matching anonymous ID with the person you identify. This covers the anonymous events you sent before you identified the person and up to five minutes after that.

*After* you identify a person, you should send events using their known identifiersThe attributes you use to add, modify, and target people. Each unique identifier value represents an individual person in your workspace. until they log out (or otherwise become unidentifiable), and *not* the anonymous ID that you previously used.

You cannot reuse an anonymous ID after you have assigned it to a person. If you send an event with an anonymous ID that you already assigned to a person more than five minutes ago, the event will not be associated with the identified person; it will remain anonymous.

If you send events with a new anonymous ID for a person you identified more than five minutes ago, you’ll need to send a new `identify` request with the new anonymous ID to associate those events with a person.

The example event below has an `anonymousId` of `abc123`. Anonymous event IDs must be unique and are not reusable. The corresponding `identify` request will associate events with the `anonymousId` of `abc123` with the person identified by the email address `person@example.com`.

Here’s an example using our [Node.JS integration](/integrations/data-in/connections/servers/node/):

```javascript
// track the anonymous event
cioanalytics.track({
  anonymousId: '48d213bb-95c3-4f8d-af97-86b2b404dcfe',
  event: 'added_to_cart',
  properties: {
    product: "shoes",
    revenue: 39.95,
    qty: 1,
    size: 9
  }
});

// identify the person
// The anonymousId matches so the anonymous event
// is associated with the identified person
cioanalytics.identify({
  userId: '019mr8mf4r',
  anonymousId: '48d213bb-95c3-4f8d-af97-86b2b404dcfe',
  traits: {
    first_name: 'Cool',
    last_name: 'Person',
    email: 'cool.person@example.com',
    purchases: 0
  }
});
```

## Anonymous event retention and campaign triggers[](#uses-and-retention)

Customer.io retains anonymous events for 30 days. These events don’t do anything—they cannot trigger campaigns or segment membership—**until they are associated with a person**. They appear in the activity log in the *Anonymous* tab, but they’re otherwise unusable until you associate them with a person by `anonymous_id`.

When an anonymous event is associated with a person, it can trigger a campaign if it occurred within the past 72 hours.

### Anonymous event merge in the activity log[](#merge-events-activity-log)

The **Activity Log** reports an **Anonymous Data Merged** activity for a person when anonymous events are merged to an identified person’s [profileAn instance of a person. Generally, a person is synonymous with their profile; there should be a one-to-one relationship between a real person and their profile in Customer.io. You reference a person’s profile attributes in liquid using `customer`—e.g. `{{customer.email}}`.](/merge-people). This activity records the number of anonymous events merged with a profile, the unix timestamp for the oldest event, and the anonymous ID for the events.

[![An anonymous data merged activity in the activity log](https://docs.customer.io/images/anonymous-data-merged.png)](#b16bc835f9a181cd9c82c887e6667b5f-lightbox)

### Third-party support for anonymous events[](#third-party-support)

The following third-parties support anonymous events:

*   [Segment Destination Actions](/journeys/segment-destination/)
*   Segment Destination (Device mode only)

To request support for anonymous events from other third-party platforms, email the third party directly and CC [product@customer.io](mailto:product@customer.io).

## Anonymous events in the Activity log[](#activity-log)

The activity log shows **Identified** and **Anonymous** events. Identified events are events associated with a person in your workspace. Anonymous events are associated with an unknown person. While we capture anonymous events, these events don’t do anything until you associate (or merge) them with a person.

When events are merged to a person’s profile, they become “identified” and appear in the **Identified** tab. Events with a icon next to the person, were previously anonymous events that are now associated with a person.

[![identified events](https://docs.customer.io/images/identified-events.png)](#841813e01768a79888c0092313c29bcc-lightbox)