Merging anonymous activity

Updated

When a person visits your website or uses your app, you can track their activity with an anonymous_id. Later, when you identify them, we’ll automatically merge their anonymous activity with their profile.

How it works

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, Customer.io will associate anonymous events with the person. You can use a person’s previously anonymous activity to add them to segments, trigger campaigns, and personalize their experiences.

If you use our JavaScript SDK, or any of our mobile SDKs that support anonymous activity, we’ll do this automatically!

If you use our server-side libraries or our APIs, you’ll have to set a person’s anonymous_id and send events manually. When you identify a person, you’ll need to pass their anonymous_id so we know which anonymous events to associate with the person you identified.

flowchart LR a(Person visits
website) a-->b{Are they already
identified?} b-....->|Yes|c(Activity
isn't anonymous) b-->|No|d(Activity is anonymous) d-->e subgraph e[Anonymous activity] direction LR f(Person visits page) g(Person adds
item to cart) h(Person starts video) end e-->i{Is person identified
within 30 days?} i-->|Yes, anonymous activity
associated with profile|c i-.->|No|j(Anonymous activity
is deleted)

Change anonymous event merging settings

Anonymous event merging is enabled by default, and we recommend that you leave it enabled. If you disable anonymous event merging, you won’t be able to associate anonymous events with people you identify; anonymous events will remain anonymous and they won’t be very useful to you.

If you created your workspace before July 2021, you must enable Anonymous event merging to associate anonymous activity with people you identify.

  1. Go to Settings > Workspace Settings and click Merge Options.
    Find merge settings under workspace settings
    Find merge settings under workspace settings
  2. Toggle the Anonymous event merge setting.
    Toggle the anonymous event merge setting
    Toggle the anonymous event merge setting

Using anonymous events as campaign triggers

Customer.io retains anonymous events for 30 days. These events don’t do anything while they’re anonymous—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. While an older event can’t trigger a campaign, you can still use it to add people to segmentsA group of people who match a series of conditions. People enter and exit the segment automatically when they match or stop matching conditions., which can also trigger campaigns.

flowchart LR a(identify a person) a-->c{Did anonymous event happen
within the past 72 hours?} c-->|yes|d(Event triggers campaign) c-.->|no|e(Event does not
trigger campaign)

Anonymous event merge in the activity log

The Activity Log reports an Anonymous Data Merged activity for a person when we merge anonymous events 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}}.. 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
An anonymous data merged activity in the activity log

Merging anonymous events with JavaScript SDKs

Using either of our JavaScript SDKs, you can send anonymous events with the track method. We’ll automatically associate these events with people when you identify them (as long as you haven’t disabled anonymous event merging).

So, for example, if a person adds items to their cart before they log in, the snippet automatically associates that event with a person when they log in.

// Send an anonymous event
analytics.track('addedToCart', {
  product: "shoes",
  price: 39.95,
  qty: 1
  size: 9
});

// Identify the person
// The addedToCart event is now associated with this person
analytics.identify('coolperson1234', {
  email: 'cool.person@example.com',
  name: 'Cool Person',
  email: 'cool.person@example.com',
  totalSpent: 0
});
// Send an anonymous event
_cio.track("addedToCart", {
  product: "shoes",
  price: 39.95,
  qty: 1
  size: 9
});

// Identify the person
// The addedToCart event is now associated with this person
_cio.identify({
    id: 'coolperson1234',
    email: 'cool.person@example.com',
    name: 'Cool Person',
    email: 'cool.person@example.com',
    totalSpent: 0
});

Server-side API implementation

If you send events to us using the API, you need to set an anonymous ID manually—both in your anonymous track events and in your identify calls. Anonymous event IDs must be unique and are not reusable.

flowchart LR A(Unidentified
person)-->|performs activity| B[/Event with
anonymous ID/] B-->|person logs in| C[/identify call
w/anonymous ID/] D-->|no|G(Events belong
to someone else) C-->D{Does
anonymous_id
match?}-->|yes|F(Events merged w/
Identified Person) F-->H[/Events use
ID or email/] F-->|Person logs out| A

The example event below has an event with an anonymous ID. The corresponding identify request contains the same anonymous ID as the event, so we’ll associate the even with the person identified by the email address person@example.com. We’ll use our Node.js server-side libraries for this example, but the same principles apply for any of our server-side SDKs.

  // Send a track event with an anonymous ID
  analytics.track({
    anonymousId: '019mr8mf4r',
    event: 'addedToCart',
    properties: {
      product: "shoes",
      price: 39.95,
      qty: 1
      size: 9
    }
  });

  // Send an identify call with the same anonymous ID
  analytics.identify({
    userId: 'coolperson1234',
    traits: {
      name: 'Cool Person',
      email: 'cool.person@example.com',
      totalSpent: 0
    }
  });    
  // Send a track event with an anonymous ID
  cio.track('019mr8mf4r', {
    name: "addedToCart",
    data: {
      product: "shoes",
      price: 39.95,
      qty: 1
      size: 9
    },
  });

  // Send an identify call with the same anonymous ID
  cio.identify('coolperson1234', {
    anonymous_id: '019mr8mf4r',
    email: 'cool.person@example.com',
    name: 'Cool Person',
    email: 'cool.person@example.com',
    totalSpent: 0
  });   

Sending anonymous events after identifying someone

After you identify someone, you can send events with the anonymous ID for up to 5 minutes, and we’ll associate them with the person you identified. 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.

Copied to clipboard!
  Contents
Is this page helpful?