Event tracking and custom events

datacub captures page views, clicks and form submits on its own, and you add custom events for the outcomes that matter with one line of code.

Two kinds of events

Automatic events arrive as soon as you add the script tag, which is about 6 KB gzipped. datacub records page views, clicks and form submits (autocapture), and follows route changes in single-page apps built on React Router, Next.js, Vue Router or SvelteKit. You can turn autocapture off if you prefer to send only your own events.

Custom events are the facts only your code knows: a sign-up that succeeded, a payment that went through, a report that was exported. You send them with datacub.track. They drive funnels, retention, A/B tests and each user's journey.

Track events and identify users

With the script tag on your page, the global datacub is ready to use:

// after the sign-up succeeded
datacub.track('signup_completed', { plan: 'free' })

// at login, with your own internal user ID
datacub.identify('user_123', { plan: 'free' })

track takes an event name and a few properties. identify tells datacub who is signed in, so one person on a phone and a laptop is one user, and their earlier visits as a Guest join their profile. Prefer npm? The same calls work from the @datacub/web package.

Name events so they stay useful

Event names are the vocabulary your team will read for years. A few rules keep them clear:

  • Use object_action in snake case, past tense: signup_completed, invoice_paid, report_exported. Write names in English, whatever your interface language.
  • One event with a property beats many events. Send onboarding_step_completed with { step: 'profile' }, not a separate event for every step.
  • Never rename an event. A renamed event is a new event, and its history starts from zero.
  • Keep properties few, flat and repeatable: a plan, a step, a count, true or false. Never a person's name or what they typed.

Track after success, not on the click

Send an event when the action actually happened: when the server answered or the payment was confirmed. A click on "Pay" happens whether or not the card was declined, so tracking the click makes your conversion look better than it is. If you also want the click, datacub already has it from autocapture.

Identify with your own ID

Call identify at login with your own stable internal user ID, such as the ID in your database. Never use an email address or phone number as the ID; datacub refuses IDs that look like an email, phone, national or Iqama ID, card number or token. If you want to see names on the People page, pass name or email as traits instead. Call datacub.reset() at logout so the next person on a shared device is not counted as the last one.

Good first events

Start with five to eight events, not fifty:

EventWhen to send it
signup_completedthe account was created
onboarding_step_completeda setup step finished, with step
project_createdthe first moment of value in your product
checkout_completeda payment was confirmed
subscription_starteda paid plan began
invite_senta user invited a teammate

Not sure where to start? Use Install with AI: copy one prompt into Claude Code, Cursor or Codex, and it installs datacub, identifies users and adds business events like these to your code.

Safe by default

datacub drops event properties named like secrets or personal data, such as password, card number, Iqama or national ID, and token, and redacts values that contain an email or a long number, on the device and again on the server. That is a safety net, not a plan: send product facts, never who someone is or what they typed. Raw IP addresses are used in memory only and never stored.

See your events in the dashboard

Your events appear on the Overview page next to traffic, inside each user's journey on user profiles, and as steps in funnels. For the full picture of what you can learn from them, see product analytics and user behavior analytics.

The events and users guide lists every naming rule and limit, and the web SDK reference covers installation.

Frequently asked questions

Do I need to write code to track events?

No. Page views, clicks and form submits are captured automatically once the script tag is on your site. Custom events need one line of code each.

How should I name custom events?

Use object_action in snake case and past tense, in English, such as signup_completed or invoice_paid. Use properties for variations instead of new event names.

Should I track the button click or the result?

The result. Send the event after the server confirms the action, because a click happens even when the action fails.

Can I use the user's email as their ID?

No. Use your own internal user ID. datacub refuses IDs that look like an email, phone number, national or Iqama ID, card number or token. Pass the email as a trait if you want to see it on the People page.