Custom Events & Properties
Learn when to use custom events instead of pageviews, how to avoid event explosion with flat properties, and how to inspect property breakdowns.
How do you track custom events and metadata properties in TrimStats?
Call window.trimstats?.("event", "event_name", { plan: "growth", annual: true }) from any browser handler. Event names accept up to 120 characters, flat string/number/boolean properties serialize cleanly into ClickHouse, and an inline pre-load queue captures calls fired before t.js finishes loading.
When to use custom events vs pageviews
Use automatic pageviews whenever an action loads a distinct URL (like /pricing or /thank-you). Use custom events for interactions that happen without changing the URL: opening a modal, submitting an AJAX signup form, toggling annual billing, or clicking a specific upgrade CTA.
| Approach | Example | Why it matters |
|---|---|---|
| Avoid event explosion | clicked_starter_hero, clicked_growth_pricing, clicked_scale_footer | Creates dozens of noisy rows that are hard to aggregate into a single goal or funnel step. |
| Recommended: 1 verb + properties | signup_completed with { plan: "growth", billing_cycle: "annual", source_cta: "pricing_table" } | Keeps reports clean and lets you break down one event across up to 20 flat property keys in TrimStats. |
Sending a custom event
Call window.trimstats?.('event', name, props) from any click handler, form submission, or API callback. Event names are trimmed to 120 characters and appear in your Overview -> Events card, Conversion Goals, Funnels, and individual Visitor Timelines.
1// Simple event with no properties2window.trimstats?.('event', 'newsletter_subscribe');34// Event with structured flat properties5window.trimstats?.('event', 'signup_completed', {6 plan: 'growth',7 billing_cycle: 'annual',8 seats: 5,9 trial: true,10});Property types & naming conventions
namestring (max 120 chars)RequiredStable machine-readable event identifier (for example signup, cta_clicked, checkout_started). Avoid embedding dynamic user IDs or timestamps in the event name.
propsRecord<string, string | number | boolean | null>OptionalOptional flat key-value object serialized as JSON. Keep values primitive (string, number, boolean, or null) so they display cleanly in the property breakdown and inside Visitor Timelines.
Avoid placing email addresses, passwords, payment card details, or tokens inside custom event props. Use opaque internal IDs via identify() instead.
Breaking an event down by its properties
Click any event in the Overview -> Custom Events & Links card to see the properties sent with it. Each property key is a tab, and each tab lists the most common values with the number of visitors and events for that value. The breakdown uses the dashboard date range and any active filters.
signup_completed opens its property breakdown modal so you can inspect plan, billing_cycle, and source_cta distributions under your active dashboard filters.- Up to 20 property keys are shown per event, ordered by how many events carried them.
- Up to 25 values are listed per key. The footer shows how many distinct values exist.
- Values longer than 160 characters are grouped by their first 160 characters.
- Properties sent as
nullare not counted. - Outbound link and file download events carry a
urlproperty, so the same view shows which exact links were clicked.
The property breakdown is visible only to signed-in members of the workspace that owns the site. Public share links show event names and visitor counts without property values.
Typed helper & pre-load queue
Because t.js loads with defer, a user could click a button before the script finishes downloading. TrimStats natively drains window.trimstats.q on boot, so a tiny wrapper guarantees zero dropped early events.
1type EventProps = Record<string, string | number | boolean | null>;23export function trackEvent(name: string, props?: EventProps) {4 if (typeof window === 'undefined') return;5 if (typeof window.trimstats === 'function') {6 window.trimstats('event', name, props);7 return;8 }9 // Queue before deferred t.js finishes booting10 const stub = (window.trimstats =11 window.trimstats ||12 ((...args: unknown[]) => {13 (stub.q = stub.q || []).push(args);14 }));15 (stub.q = stub.q || []).push(['event', name, props]);16}Common technical questions
What happens if window.trimstats("event", ...) runs before t.js finishes downloading?
What data types are allowed inside TrimStats custom event properties?
Related guides
Learn how conversion goals and conversion rate work, configure exact/wildcard paths or custom events, and monitor automatic conversion dips.
Learn how multi-step conversion funnels and weekly retention cohorts work, how to spot your biggest drop-off leaks, and how TrimStats computes them in ClickHouse.
Complete client-side reference for window.trimstats commands, attribution snapshots, command queueing, and browser storage keys.