Customer.io Anonymous ID Not Linked After Identify: Fixes
When Customer.io events stay anonymous after identify, the identify call and the earlier events usually carry different anonymousId values. Compare them in the browser first, then check for duplicate SDK instances, server-side sends, blocked storage, an early reset call and the identifier itself. Next.js code included.
Sohail Hussain9 min readShort answer
- Compare the anonymousId on the earlier events with the one the browser holds right after identify. Whether they match decides everything else.
- If they differ, look for several SDK instances, server-side calls without the browser ID, blocked or unshared cookies, or a reset() that runs too early.
- Do not rely on past anonymous events triggering a campaign after a merge; identify first, then send the trigger event as the identified user.
The report goes like this: you use @customerio/cdp-analytics-browser in a Next.js app, events carry an anonymous_id, you call identify, and the events still show as anonymous. Campaigns triggered by those events never fire.
People on a developer forum reported this for Next.js, and the thread ended without a confirmed fix. So this page works from how Analytics.js-style SDKs behave, not from a verified answer. Treat the steps as a diagnostic order, cheapest check first, and treat Customer.io's documentation as the final word on merge rules.
Why it happens
Most likely first:
- The identify call and the earlier events never shared an anonymous ID. This is the usual cause. The SDK was recreated, the cookie did not persist, or the earlier events came from a different source (for example the server).
- More than one SDK instance. Next.js makes this easy to do by accident.
- Server-side events without the browser ID. They become a separate anonymous person.
- An early
reset(), which creates a new anonymous ID. - The wrong identifier or workspace. The identify goes to a different person key or a different write key than the events.
What is not known: exactly how Customer.io treats past anonymous events after a merge, and whether they can trigger campaigns retroactively. Check its documentation or ask support rather than guessing.
Step 1: Check whether the IDs really match
Do not trust "matching" until you have compared the actual values. In the browser console, with your analytics instance in scope:
const user = await analytics.user();
console.log(user.id(), user.anonymousId());
Run it before login and again right after identify. Then open the event in Customer.io's source event view and compare its anonymousId with what you saw.
| What you see | Meaning | Go to |
|---|---|---|
| The anonymous ID changes after identify | The SDK was reset or recreated | Steps 2 and 5 |
| The browser ID is stable, but earlier events carry a different one | Those events came from another source or context | Steps 3 and 4 |
IDs match everywhere, identify has a userId, events still look anonymous | Identifier, workspace or call order problem | Step 6 |
Step 2: Make sure there is one SDK instance, created in the browser only
Calling AnalyticsBrowser.load more than once is a common self-inflicted cause in Next.js. It happens when you create it inside a component body, in a hook without memoization, or in React Strict Mode's double-invoked effects in development. identify may then go through a different instance than your page and track calls.
- Create the instance once in a module.
- Import that module everywhere you track.
// lib/analytics.ts
import { AnalyticsBrowser } from "@customerio/cdp-analytics-browser";
export const analytics =
typeof window === "undefined"
? undefined
: AnalyticsBrowser.load({
writeKey: process.env.NEXT_PUBLIC_CIO_WRITE_KEY as string,
});
- Call it only from client components.
"use client";
import { useEffect } from "react";
import { analytics } from "@/lib/analytics";
export function IdentifyOnLogin({ userId, email }: { userId: string; email: string }) {
useEffect(() => {
analytics?.identify(userId, { email });
}, [userId, email]);
return null;
}
Server components and API routes have no browser cookies or localStorage for this SDK to read. Any track fired there gets no browser anonymous ID.
Strict Mode
If the problem only appears in development, test a production build before changing anything else. Strict Mode double-invokes effects on purpose and can hide or fake duplicate-instance bugs.
Step 3: Forward the anonymous ID to server-side events
If part of your funnel is tracked server-side (a signup API route, a webhook handler), those events carry whatever ID you pass. Unless you forward the browser's anonymousId, they show up as a separate anonymous person.
- In the browser, read
(await analytics.user()).anonymousId(). - Send it in your request body to the server.
- Pass it as
anonymousIdin the server-side track call, or send the event with the knownuserIdonce the user exists.
Server events recorded before the user was known cannot be matched later unless they carry the same anonymous ID.
Step 4: Rule out cookie and storage problems
Analytics.js-family SDKs keep the anonymous ID in a first-party cookie and localStorage; the key is typically ajs_anonymous_id. It can fail to persist, producing a fresh ID per page load, when:
- the visitor blocks cookies and storage, or uses a privacy browser that clears them
- your marketing site and app live on different registrable domains, so the cookie is not shared
- you compare IDs across incognito windows, which do not share storage
The console check in step 1 makes a per-page-load ID easy to spot. Subdomains of one domain can usually share the ID. Different registrable domains cannot, and you would have to pass the ID through the link yourself.
Step 5: Find an early or accidental reset
analytics.reset() clears the user ID and generates a new anonymous ID. It belongs on logout. If it runs on login, on route change, or in a layout effect that fires after identify, later events carry a new anonymous ID and the stitching breaks.
- Search your codebase for
reset(. - Confirm each call runs only on logout.
- Check auth libraries and wrappers that may call it for you.
Step 6: Check the identify payload and call order
Open your browser's network tab or the source debugger and inspect the identify call.
- It has a non-empty
userId. An identify with only traits does not identify a person. - The
userIdis the one your workspace uses as the person's identifier. If existing people are keyed by email and you identify by a database ID (or the reverse), you can end up with a new person instead of the one you expected. - The identify and the earlier events use the same write key, meaning the same source and workspace. A staging key on one and a production key on the other will never link.
identifyruns before anything depends on it. If your trigger event fires in the same tick as login, it can leave under the anonymous ID.
Why campaigns may still not fire
Even when the merge works, an event-triggered campaign may not fire for events recorded while the person was anonymous. Whether past anonymous events trigger campaigns after a merge is a question for Customer.io's documentation and support. I would not build a flow that depends on it.
The safer pattern: identify first, then send the trigger event as the identified user. If the key action happens before signup, track a second event right after identify.
Mixed trackers
If your site loads the older Customer.io JavaScript snippet alongside the Data Pipelines SDK, each can keep its own visitor identity. Pick one. Another analytics tool that wraps Analytics.js can also create its own instance and cookie handling.
Checklist before you try again
- One
AnalyticsBrowser.loadcall, in a module, guarded for the browser identifycalled from client code with a non-emptyuserIdanonymousIdidentical before and after identify in the console- Server-side events carry the forwarded
anonymousIdor a knownuserId reset()runs only on logout- Same write key and workspace for every call
- Only one Customer.io tracking library on the page
- Trigger event sent after identify
If nothing works
Contact Customer.io support. Include:
- your workspace ID and the source name (never the secret write key)
- one example
anonymousIdand theuserIdit should merge into - timestamps of the anonymous events and of the identify call
- the SDK package name and version, and confirmation that the calls run client-side
- what you already checked from this page
Subject: Anonymous events not merged into identified person
Workspace ID: {your-workspace-id}
Source: {source-name} (browser, @customerio/cdp-analytics-browser {version})
Example anonymousId: {anonymous-id}
Expected userId: {user-id}
Anonymous events: {timestamps, UTC}
Identify call: {timestamp, UTC}
The anonymousId is identical before and after identify (checked in the
browser console). Identify has a non-empty userId and uses the same write
key as the earlier events. There is a single SDK instance and reset() only
runs on logout.
Result: the earlier events still show as anonymous and the event-triggered
campaign does not fire.
Questions: should these events merge into the person, and do past anonymous
events trigger campaigns after a merge?
Common questions
Can past anonymous events trigger a campaign after identify?
I could not confirm this. Ask Customer.io support or check its documentation, and design the flow so the trigger event is sent after identify.
Why does the anonymous ID change on every page load?
The SDK cannot persist its cookie or localStorage value. Blocked storage, a privacy browser, or a different domain are the usual reasons.
Should I identify on the server instead?
You can, but the server has no browser anonymous ID unless you forward it. Identifying in the browser is simpler when the goal is to link earlier browsing to a user.
Does this apply to other Analytics.js-style SDKs?
The checks (one instance, stable anonymous ID, forwarded IDs, reset placement) apply broadly. Merge rules differ by vendor, so confirm them in the vendor's documentation.
Explore: Email Marketing Strategy
Related Articles
Customer.io pricing in 2026: the $100 start and billing disputes
Community threads and reviews describe Customer.io pricing as starting around $100 a month, with billing disputes, no phone support and a steep learning curve. Confirm the live price before you buy. This page covers what can inflate a bill, how to dispute a charge in writing, and what to compare.
Customer.io Supabase "cannot assign requested address" fix
The "cannot assign requested address" error means Customer.io tried Supabase's IPv6-only direct host and could not connect. Use the pooler hostname, or buy Supabase's IPv4 add-on. "Tenant or user not found" usually means the pooler username lacks the project ref suffix, or the region host is wrong.
414 Request-URI Too Large in n8n's Amazon SES node: fix
The error 414 Request-URI Too Large in n8n's AWS SES node means a server in the path refused a request whose URL was too long, which a long HTML body can cause when it travels in the URL. Send through the SES v2 API with an HTTP Request node, or use SES SMTP.
Access denied, bad outbound sender: Outlook cold email fix
"Access denied, bad outbound sender" (550 5.1.8) means Microsoft 365 has put your mailbox on its restricted users list for spam-like sending. An admin must unblock it under Restricted entities in the Microsoft Defender portal. Then clean your list, lower your volume and resume gradually.
Ready to supercharge your email marketing?
Start sending smarter emails with AI-powered campaigns. No credit card required.
Get Started Free