Skip to content
Guide · Getting started

Custom event tracking: a practical guide

Custom event tracking records the actions that matter on your site, like a button click, a signup or a purchase, in addition to page views. In Linqry you send one with a single HTML attribute or one line of JavaScript, and it becomes something you can count, turn into a goal and use as a funnel step.

Updated · 5 min read

What counts as a custom event

Page views tell you where people went. Events tell you what they did there. If your pricing page gets 2,000 views and 140 clicks on 'Start free trial', the click is the number you can act on.

Linqry records three events for you with no code: pageview (including route changes in single-page apps), pageleave (time spent on the page) and outbound (clicks on links to other hostnames, with the link's href). Everything else, such as signups, plan selections, downloads and video plays, is a custom event that you name and send.

Track a button click with an HTML attribute

The fastest way needs no JavaScript. Add data-linqry-event to any clickable element, and the tracker sends an event with that name when it's clicked. Clicks on child elements (an icon inside the button, say) count too.

<a href="/signup" data-linqry-event="trial-cta-clicked">Start free trial</a>

<!-- Extra data-linqry-event-* attributes become properties -->
<button
  data-linqry-event="plan-selected"
  data-linqry-event-plan="pro"
  data-linqry-event-billing="yearly"
>
  Choose Pro
</button>
<!-- sends: plan-selected { plan: "pro", billing: "yearly" } -->

This works on any site where you can edit HTML, including site builders that let you add custom attributes. It's ideal for marketing pages: call-to-action buttons, download links, 'Book a demo' and pricing toggles.

Track events from JavaScript

When the event should fire on something other than a click, or only after something succeeds, call window.linqry(name, properties?, revenue?):

// After the signup request succeeds, not when the button is clicked
const res = await fetch('/api/signup', { method: 'POST', body: form });
if (res.ok) window.linqry('signup-completed', { plan: 'trial' });

// A video reaching the end
video.addEventListener('ended', () => window.linqry('demo-video-finished'));

// A purchase with revenue in cents: $49.00
window.linqry('purchase', { plan: 'pro' }, 4900);

The first line of the install snippet defines a small queue, so calls made before the tracker has finished loading are kept and sent when it arrives. You don't need to wait for anything before calling window.linqry.

Attribute or JavaScript?

Use an HTML attribute when…Use JavaScript when…
The action is a click on a link or buttonThe action isn't a click: a form succeeding, a video ending, a file upload finishing
You can't or don't want to edit scriptsYou only want to count successes, not attempts
The properties are known when the page rendersProperties depend on runtime state, like the chosen plan or the cart total

A common mistake is putting data-linqry-event="signup-completed" on a submit button. That fires on every click, including clicks that fail validation, so it measures attempts. Name it signup-submitted, or send signup-completed from JavaScript after the server confirms.

Name events so they stay useful

Event names become the values you build goals and funnels from, and they match exactly. Signup, signup and sign-up are three different events. Decide on a scheme before you ship the first one:

  • Use object-action in the past tense: trial-cta-clicked, signup-completed, invoice-paid. It reads well in a list and sorts related events together.
  • Lowercase with hyphens. Names may be 1 to 64 characters of letters, digits, spaces and _ . : / -. Anything else is rejected.
  • One name per meaning. If the header button and the pricing button both start a trial, either share trial-cta-clicked with a location property, or use two names if you want to count them separately (see properties below).
  • Write the list down. A short table of event names, where they fire and what properties they carry saves you from duplicates six months from now.

Properties: context, not identity

Properties add context to an event, like which plan, which page section or which variant. They're a flat object of up to 20 keys, with string values cut at 256 characters; nested values are stored as JSON strings.

Be clear about where properties show up. Linqry stores them on every event and shows them in each visitor's timeline on the Users page, which is handy for debugging. Dashboard tables, goals and funnels count events by name, not by property value. So if you need a separate count, goal or funnel step for each variant, encode it in the name (pricing-trial-clicked and header-trial-clicked) rather than in a property.

Attach revenue to an event

Pass an amount in the smallest currency unit as the third argument, or use data-linqry-revenue on an element. Revenue events feed the revenue figure, revenue per visitor and the revenue-by-source tables.

<button data-linqry-event="tip-sent" data-linqry-revenue="500">Send a $5 tip</button>

Browser revenue is easy to fake, because anyone can call window.linqry() from the console, and Linqry caps how much one browser event may claim. For payments you report on, send them from your backend with the write key; the server-side revenue guide shows how.

Single-page apps: React, Vue, Svelte and friends

Page views in single-page apps are automatic: the tracker listens to history.pushState, replaceState and popstate. Custom events work the same as anywhere else. Call window.linqry from your event handlers, and the data-linqry-event attributes work on components that render plain elements:

// A tiny typed helper so a missing script never throws
export function track(name: string, props?: Record<string, string | number | boolean>, revenueCents?: number) {
  if (typeof window !== 'undefined' && typeof window.linqry === 'function') {
    window.linqry(name, props, revenueCents);
  }
}

declare global {
  interface Window {
    linqry?: (name: string, props?: object, revenueCents?: number) => void;
  }
}

// In a component
<button onClick={() => track('export-clicked', { format: 'csv' })}>Export CSV</button>
<a href="/pricing" data-linqry-event="nav-pricing-clicked">Pricing</a>

Two details to know: paths listed in the snippet's data-exclude attribute suppress custom events as well as page views, and a browser with localStorage.linqry_ignore set to "true" sends nothing at all.

What to track first

Resist tracking every click. Five to ten well-named events answer most questions. A good starting set for a product site:

  1. The main call to action, such as trial-cta-clicked or demo-requested.
  2. The conversion itself, such as signup-completed or purchase, sent after success.
  3. One activation event: the first action that shows a new user got value, like project-created.
  4. Pricing interest: plan-selected with the plan as a property.
  5. A content action if content drives your traffic: newsletter-subscribed or guide-downloaded.

Here is how that plays out on one page. Say your pricing page gets 3,000 views in a month. You add trial-cta-clicked to its two buttons and send signup-completed after the signup API succeeds. A month later the Custom events table shows 360 clicks and 210 completed signups, which tells you two things page views never could: about one in eight visits to pricing ends in a click, and roughly 40% of the people who click don't finish signing up. The second number is the one worth working on, and it points at the signup form rather than the pricing copy.

Then turn the conversion into a goal and string the steps into a funnel. The SaaS onboarding funnel guide walks through a full example.

Check that your events arrive

  1. Trigger the event yourself

    Open your site in a normal browser window (not one where you've set the linqry_ignore flag, and ideally without an ad blocker) and click the button or complete the action.

  2. Watch the Realtime view

    Open Realtime in Linqry. The live event feed lists events from the last hour, newest first, so yours should appear within seconds with its page, country and device.

  3. Check names and properties

    Find your visit on the Users page and open its timeline to see each event with its properties. A typo in a name shows up here as a separate event.

  4. Don't rely on the network tab

    The browser endpoint answers 204 whether or not it accepted an event, so a green request in developer tools doesn't prove the event was stored. Realtime does.

Frequently asked questions

How do I track button clicks without writing JavaScript?

Add a data-linqry-event attribute with the event name to the button or link, for example data-linqry-event="trial-cta-clicked". The tracker sends the event on click. Extra data-linqry-event-* attributes become properties.

Can I track form submissions?

Yes. For attempts, put a data-linqry-event attribute on the submit button. For successful submissions, call window.linqry('form-submitted') in your code after the server confirms, so failed validation isn't counted.

Why don't my events show in the dashboard?

Check the Realtime view first. If nothing appears, confirm the event name uses only letters, digits, spaces and _ . : / -, that the page isn't listed in data-exclude, that your browser hasn't set the linqry_ignore flag, and that an ad blocker isn't blocking the tracker.

Can I see a breakdown by event property?

Properties are stored and shown on each event in a visitor's timeline, but dashboard tables, goals and funnels count events by name. If you need a separate count per variant, put the variant in the event name.

See your own funnels and revenue by channel

No card required · 30-day trial · No cookies