Custom events
A custom event is an action your site reports by name, such as a completed signup or a booked demo. The script counts page views on its own; events are what you add, with one line of JavaScript where the action happens. This guide is for whoever writes your site’s code.
Send an event
With the tag from Install the script on the page, the script defines window.track. Call it once the action has succeeded, with the event’s name and, if you like, a few properties:
// After the signup request succeeds
window.track?.("signup_completed", { plan: "team" });
// Page views, including client-side route changes, are sent automatically.<button type="button" onclick="window.track?.('demo_requested')">
Book a demo
</button>// window.track, as the script defines it
declare global {
interface Window {
track?: (name: string, props?: Record<string, string | number | boolean>) => void;
}
}
export {};The ?. makes the call do nothing when the script isn’t there, for example when a content blocker stopped it, so your page never breaks because of it. track exists once the script has run: with the HTML tag (defer), once the page has been parsed; with the Next.js tag (afterInteractive), after the page has hydrated, so a component’s first effect on a page that loads fresh runs before it. A call before then is lost, not queued, so send events when the action happens, not as a page first renders.
Each call sends one event, as its own request. The request can finish after the page unloads, so an event sent as a link is followed or a form is submitted still goes. With Via your domain, events take the same path as page views.
Names and properties
_ . : -, not starting with a space. Names are case-sensitive: Signup and signup are two events.true or false.revenue makes the event a payment, with currency when it isn’t your site’s; both count among its 10 properties. currency alone stays an ordinary property. See Send revenue with an event.An event that breaks a rule is refused whole, and nothing of it is stored: a name with other characters, more than 10 properties, a property name over 40 characters, or a value that is null, an array, or an object. So is a request over 8 KB in all, the page’s address included: a long text value counts at its full length before it’s cut. Leave a property out rather than sending it as null.
Use one name for each action and put what varies in a property: signup_completed with { plan: "team" }, not signup_team. Goals, funnels, and the other reports find an event by its exact name.
Where events show
Open your site and choose Goals & events in the sidebar, under Behavior (or press G, then E). The Custom events table lists every event sent in the period with its Completions, Converted, Rate, a Revenue column where an amount was sent, and its trend. An event that is also a goal shows the goal’s name beside it. Select an event to open its page:
Events also show in the Overview’s Goals & events panel, as steps of a visit in Sessions (with Individual visits on), and in reports: a step of a funnel or a journey, the start or return in Retention, how a cohort starts, and the goal of Attribution. To count an event as a conversion, make it a goal.
How events count
- Usage. Each event counts toward your plan, as a page view does.
- Bounces. A visit with a custom event isn’t a bounce: bounce rate counts visits with one page view and no events.
- Visits. An event keeps its visit going. One sent after 30 minutes without activity starts a new visit, on the page it was sent from.
- Retries. Each request carries a random ID, so a request sent twice counts once. Calling
tracktwice sends two events. - Bots. Events from bots are left out of every number, as their page views are, and counted in the Bots panel. Send events from the browser: requests from servers, such as curl or Node’s
fetch, are treated as bots. - Hostnames. An event sent from an address your site doesn’t count is turned away, as a page view is (Choose which hostnames count).
Check that it arrives
Do the action on your live site, then open Goals & events and pick Today in the period menu (or press D). Reload it if it was open. When the period leaves out today, an event or goal that has none in the period but some today is named at the top, with Show today. If nothing shows, find the script’s request in your browser’s network panel: to /api/event, or to your own path with Via your domain.
localStorage.removeItem("_aoff") to undo it. Automated browsers, such as test runners, send nothing either.error says which.Retry-After says how many seconds.Privacy
- No personal data. Don’t send names, email addresses, user IDs, or order numbers in event names or properties. We keep them as you send them.
- Consent. Events go through the same script as page views and set no cookies. Whether you need your visitors’ consent depends on the country; in Sweden and Germany, assume you do. Where your tag has
data-remember, events carry the ID it keeps in the browser, which needs consent in the EU and UK (consent, by place). - Who sees properties. Share links, API keys, and AI assistants read an event’s totals, never its property values or single completions.
- How long. Events are kept with the visits: while your workspace has a trial or a plan, and deleted 60 days after it ends (how long we keep it).