All articles

Tutorials

Custom events: naming them well and tracking clicks without code

Track signups, clicks and form submissions in PureStats with one JavaScript call or two HTML attributes, and name events so reports stay readable.

3 min readUpdated
Custom events: naming them well and tracking clicks without code cover image

Key takeaways

  • Use a few stable event names and put the variants in properties.
  • Two HTML attributes track a click or a form without JavaScript.
  • Never put personal data in event names or properties.

When a pageview is not enough

Pageviews tell you which pages were loaded. Many outcomes do not load a page: a click on a pricing toggle, a submitted form, a started trial inside an app. Custom events record those actions, and any event can become a goal.

Before adding an event, write down the question it answers. An event without a question becomes a row in a table nobody reads.

Track an event from JavaScript

One call sends an event: window.purestats?.('Signup Completed'). Add properties as a second argument when the same action comes in variants, for example window.purestats?.('Plan Selected', { plan: 'pro', billing_cycle: 'annual' }). The question mark keeps the call harmless if the tracker is blocked or not loaded yet.

When the browser is the wrong place, for example after a payment webhook, send the event from your server with the Measurement Protocol, directly or through one of the SDKs for JavaScript, PHP, Kotlin and Swift.

Name events so reports stay readable

Good names describe what happened, in the past tense, and stay the same across releases. Signup Completed is a good name; Clicked blue button v2 is not, because it describes the implementation and breaks the next time the design changes.

Put variants in properties instead of in the name. Plan Selected with a plan property gives one row you can break down; Plan Selected Pro, Plan Selected Team and Plan Selected Free give three rows you have to add up yourself.

  • Object and action in the past tense, in one style you keep everywhere: Trial Started or trial_started, not both.
  • Properties in lowercase snake case: plan_id, billing_cycle.
  • A short list of agreed names, kept next to your code.
  • No email addresses, names, phone numbers or free text in names or properties.

Track clicks and forms without code

For links, buttons and forms you do not need JavaScript. Add the attribute data-purestats-event with the event name, for example data-purestats-event="Signup Clicked" on the signup button; a class such as purestats-event-signup_clicked does the same. Properties come from data-purestats-prop- attributes: data-purestats-prop-plan="pro" sends plan: pro.

On a form, the same attributes record the submission, not what was typed into it. That keeps form tracking free of personal data by design.

From event to goal

An event becomes a goal when it stands for an outcome. Create the goal in the site settings, choose the event name and give it a business name such as Trial started. Reports then show conversions, conversion rate and the sources, campaigns and landing pages behind them.

Review your event list every few months. Remove events nobody uses and merge names that mean the same thing; a short list is easier to trust.

  1. Write the question the event answers.
  2. Pick a past-tense name and the properties you need.
  3. Send it with purestats() or the no-code attributes.
  4. Check it in tracking test mode or the Events report.
  5. Turn it into a goal if it is an outcome.

Frequently asked questions

How do I track an event?

Call window.purestats?.() with a name and optional properties, or add the no-code attributes to a link, button or form.

Can events contain personal data?

They should not. Use stable categories or IDs instead of names, email addresses or form input.

Can I send events from my server?

Yes, with the Measurement Protocol, directly or through an SDK.

Track your first event

Add a site, send one event and turn it into a goal in a few minutes.

Start free