Product guides

Identify — know which customer did what

Connect product activity to your own customer IDs with one call after login.

What identify does

Out of the box, analytics tells you *someone* signed up, upgraded, or churned. Identify tells you *who*, using the ID your own database already has for them. Once it is called, every later event on that page carries the customer, the Users tab fills in, and revenue can be read per customer instead of per visit.

The one line

Call it from your app after login — and again on each page load while signed in, which is free. Traits merge on later calls, so sending only a plan today does not erase the company you sent yesterday.

On WordPress the plugin does this automatically for logged-in users, and on Shopify the theme snippet from the install guide does — the code on this page is for custom-built sites.

javascript
spx('identify', user.id, {
  plan: user.plan,
  company: user.company,
});

What to use as the ID

Your own stable customer ID — the primary key from your users table is ideal. Never an email address: analytics is not a customer database, and an ID that means nothing outside your systems is exactly the point.

If your IDs are sensitive

Some teams prefer not to put their database’s primary keys anywhere outside their own systems — a reasonable instinct. The fix is an alias: hash the ID on your server with a secret only your server holds, and identify with the hash.

The same user always produces the same alias, so Users, journeys, and revenue-per-customer all still join. But nothing on the analytics side can be traced back to a real ID, nobody who merely knows a user’s ID can forge that user’s events, and rotating the secret unlinks all history at once.

Use the same alias everywhere you send a user key — identify in the browser, server events, and spx_user in checkout metadata — or the joins fall apart. Asuito’s own dashboard identifies its users exactly this way.

javascript
// On your server — the secret must never reach the browser.
const crypto = require('node:crypto');

// Any long random string, kept in your server's environment.
const secret = 'load me from your env';

function analyticsAlias(userId) {
  return crypto.createHmac('sha256', secret)
    .update(userId)
    .digest('hex')
    .slice(0, 24);
}

// Then, in the page you render for that signed-in user:
// spx('identify', '<the alias>', { plan: user.plan });

How it behaves

Identify is a call, not an event — it records nothing by itself, so it never buries your event stream in noise.

The identity is held in memory for the life of the page and stored nowhere on the visitor’s device. Events fired before the first identify on a page are anonymous, and they should be: you did not know who it was yet.

It joins with revenue: a purchase carrying the same ID — from the browser, your server, or a payment webhook — shows up against that customer.