Skip to content

User Identification

Associate the current browser with a known user (similar to PostHog’s identify). Call once after login or signup; every later push() automatically includes the person context.

Prefer usertrax.identify() as the single call site: when the feedback widget is also on the page, the same call identifies the visitor there too (hides the email field, attaches user metadata). Identity is persisted in localStorage (usertrax_identify), so the widget picks it up even if it loads after the tracker.

// After the user signs in
usertrax.identify("user_xyz", {
email: "jane@example.com",
plan: "team",
seats: 5,
});
// Later conversions inherit user_data + meta snapshot
usertrax.push({ event: "purchase", total: 49.99, currency: "EUR" });
tracker.identify("user_xyz", {
email: "jane@example.com",
plan: "team",
});
  1. Persistence — Stored in localStorage (usertrax_identify) and reused across page loads and sessions.
  2. user_data merge — Canonical trait keys (email, phone, phone_number, first_name, last_name, name, customer_id, address) are merged into each conversion’s user_data. The distinct id becomes customer_id when you do not set one explicitly. Fields on a single push({ user_data: … }) override traits from identify.
  3. Full trait snapshot — All traits (including custom keys like plan or seats) are sent on every conversion under meta_data.$usertrax_identify:
{
"distinct_id": "user_xyz",
"traits": { "email": "jane@example.com", "plan": "team", "seats": 5 }
}
  1. PostHog — When PostHog is loaded and usertraxConfig.posthog is not false, identify also calls posthog.identify(distinctId, traits).
  2. Feedback widget — Dispatches usertrax:identify so a loaded feedback widget applies the same identity (also hydrates from localStorage on boot).
Trait keyMaps to user_data
emailYes
phoneYes
phone_numberYes
first_nameYes
last_nameYes
nameYes
customer_idYes
addressYes
Any other keymeta_data only

Use setUserData() when you only need Google Enhanced Conversions hashing without a stable distinct id — see Ads & Enhanced Conversions. Use identify() when you want a persistent person id and traits on all events.