Get started pages

Identify users and track your own events

Two lines of code that turn anonymous visitors into named people and make your business moments queryable.

Autocapture gets you page views and clicks for free. It cannot know who someone is, or that a click meant "upgraded to Pro". Those two things are one line of code each, and they are what make the rest of the product sharp.

Before you start

The SDK should already be installed and verified. Both calls below are made on the tracker instance that init returns:

const tracker = HumanBehaviorTracker.init(apiKey);

Calling init again anywhere in the same page returns the same instance, so you can grab the tracker wherever you need it rather than threading it through your app.

Tell Human Behavior who someone is

Everyone who visits gets an anonymous id stored in their browser. Call identifyUser after login and that anonymous person becomes a named person:

await tracker.identifyUser({
  email: "ada@example.com",
  name: "Ada Lovelace",
  plan: "pro",
});

Pass identifying traits, commonly an email, inside the properties object. The server matches or creates the end user from them.

There is no `identifyUser(userId, traits)` form

The SDK takes a single object. A two-argument call is a common mistake carried over from other analytics SDKs, and it will not do what you expect.

Call it again whenever traits change, or update one at a time:

tracker.setUserProperty("plan", "enterprise");

What changes in the product

Rows in Visitors gain names and emails instead of anonymous ids, replay headers show who you are watching, and the affected-user counts on issues start meaning something.

Log out on shared devices

When someone signs out of your app, tell the SDK:

tracker.logout();

That clears the stored identity, mints a fresh anonymous id and session, and takes a new snapshot so the next person's replay starts clean. Without it, the next person on that browser is merged into the previous person's identity.

Track the moments that matter to you

Autocapture cannot tell that a particular button click was a signup. Name those moments yourself:

await tracker.customEvent("signed_up", {
  plan: "pro",
  source: "pricing_page",
});

Custom events are batched in the browser, so a burst of them is one request rather than ten. You can await the call or fire and forget.

Naming them well

You will live with these names, because funnels and charts are built on them.

  • Use stable snake_case names and keep them stable. Renaming an event after a funnel ships breaks the funnel.
  • Keep properties small and enumerable: plan: "pro" is useful, a free-text blob is not.
  • Do not put secrets, tokens, or passwords in properties.
  • Avoid the $ prefix. That namespace belongs to the SDK's own events: $pageview, $click, $rageclick, $deadclick, $form_submitted, $web_vitals.

You do not need to attach browser or URL details yourself. The SDK adds those automatically.

What good looks like

Trigger the event in a real session, then check:

  1. Dashboard → Events lists it under custom events
  2. Open the replay of that session and find it in the activity Custom tab
  3. Visitors shows the identified person rather than an anonymous row

Events in the first five seconds

With the default settings, events fired in the first five seconds of a session are queued and sent once the session passes that gate. They are not lost, just delayed. Set minimumDurationMilliseconds: 0 in init if you need them immediately.

Next

Where to go next — pick the path that matches what you are trying to do with the data.