Tracking
Custom events
Count signups, clicks and downloads with track(), and attach a few properties to them.
Use custom events to count things that are not pageviews: signups, button clicks, downloads, checkout steps. Call track with a name:
track('signup')Events appear in the Custom events panel on your dashboard, with the number of times each was recorded.
Examples
// a button
document.querySelector('#download').addEventListener('click', () => track('download'))
// a form
form.addEventListener('submit', () => track('newsletter_subscribe'))
// after something succeeds in your code
await createAccount()
track('signup')Naming rules
- 1 to 64 characters: letters, numbers, spaces, and the characters
_ . : -. - A name that breaks the rules is dropped, not recorded. Names are case sensitive, so
Signupandsignupare different events. - Pick a consistent scheme such as
checkout:startandcheckout:complete. You can filter and group by name in the dashboard and with the AI analyst.
Things to know
- Always pass a name.
track()with no name is recorded as a pageview. - Events carry the page they happened on, so you can see which page produced them. To record extra detail, such as which plan was chosen, add properties.
- Wait for the script. Because of
defer,trackexists once the page has loaded. Code that runs earlier should check first:window.track && window.track('signup') - Do not put personal data, such as an email address or a user ID, in an event name or a property. Event names are stored as written, and the checks on properties catch only the obvious cases.
- Do Not Track and Global Privacy Control apply to events too.
Event properties
Add a second argument to track to attach a few details to an event:
track('signup', { plan: 'pro', period: 'year' })
track('download', { file: 'guide.pdf' })On Pro, the Event properties card on your dashboard shows, for the event you pick, the most common values of each property. The AI analyst can read them too, so you can ask which plan signups choose.
- Up to 5 properties per event. Names start with a letter and use up to 32 letters, numbers,
_ . -. Values can be text, numbers or true/false, up to 64 characters, and are stored as text. - Properties are for categories, not people. A property is dropped (the event is still recorded) if its name suggests personal data, such as
email,phone,tokenoruserId, or if its value looks like an email address, a web address, an IP address, a long number, or a long ID. - Only custom events can carry properties. Pageviews ignore them.
- Keep values to a small set, such as plan names. Free text makes a long list of values that is hard to read.
- Properties are included in the CSV export.