Identify and track
Attach a name to an anonymous visitor, and record the events only your app knows about.
The install gets you replays, autocaptured clicks, and errors. Two more calls turn anonymous rows into named people and let you count the things that matter to your business.
Name the person
Call identifyUser once you know who someone is — right after sign-in, and on
page load for an already-authenticated session. Everything the visitor did
before that call stays attached to them.
import { HumanBehaviorTracker } from "humanbehavior-js";
const tracker = HumanBehaviorTracker.init(apiKey);
await tracker.identifyUser({
email: "alex@example.com",
name: "Alex Nakamura",
plan: "pro",
});In React, the same thing without threading the tracker through props:
import { useHumanBehavior } from "humanbehavior-js/react";
const tracker = useHumanBehavior();
await tracker.identifyUser({ email: user.email, name: user.name });If you do not pass an explicit user id, the email property becomes the
identifier. Any other properties you include become filterable attributes on the
person.
On sign-out, call tracker.logout() so the next visitor on that browser is not
merged into the account that just left.
Record your own events
Autocapture sees a click on a button. It does not know that the click meant a
subscription was created. That is what customEvent is for:
await tracker.customEvent("subscription_created", {
plan: "pro",
seats: 12,
mrr: 240,
});Events show up on Dashboard, are usable as funnel steps, and appear in a person's timeline in Visitors.
What makes a good property
Properties are what let you split a number instead of just watching it move.
plan, seats, and mrr above are why you can ask which plan is churning
rather than only that churn went up.
Keep out anything you would not want in an analytics tool: passwords, tokens, full card numbers. For text on screen rather than in your event payloads, see Masking and PII.