6 min read

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.

Imtiaz Rayhan
Imtiaz RayhanCo-Founder & Lead Engineer, DotCamp & TrimStats
Verified against live TrimStats APIs
Quick reference

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.

ApproachExampleWhy it matters
Avoid event explosionclicked_starter_hero, clicked_growth_pricing, clicked_scale_footerCreates dozens of noisy rows that are hard to aggregate into a single goal or funnel step.
Recommended: 1 verb + propertiessignup_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.

track-signup.tsts
1// Simple event with no properties
2window.trimstats?.('event', 'newsletter_subscribe');
3
4// Event with structured flat properties
5window.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)Required

Stable 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>Optional

Optional 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.

Never send sensitive PII in event properties

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.

Site analytics / Overview / Event Properties
Clicking 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 null are not counted.
  • Outbound link and file download events carry a url property, so the same view shows which exact links were clicked.
Not available on public share links

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>;
2
3export 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 booting
10 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?
If you initialize the tiny pre-load stub (window.trimstats = window.trimstats || function(){(window.trimstats.q = window.trimstats.q || []).push(arguments)}), t.js drains every queued command in order immediately on load.
What data types are allowed inside TrimStats custom event properties?
Pass flat key-value objects containing strings, finite numbers, or booleans. Avoid nested objects and never place raw emails, passwords, phone numbers, or payment tokens inside event properties.

Related guides