Track custom events
Send your own events from code with Spectry.track(), including e-commerce events.
Custom events let you record any meaningful action — a button click, a signup, a purchase — beyond automatic page views.
Spectry.track()
Spectry.track('subscribed', {
plan: 'pro',
price: 29,
currency: 'USD',
});
The first argument is the event name; the second is an optional object of properties. Properties can be strings, numbers or booleans.
Events are only sent after analytics consent is granted. If there's no consent the call is silently dropped — events are not queued and replayed later, because buffering would mean writing to storage before consent. Don't fire a purchase event from a page that runs before your banner is answered.
E-commerce events
For revenue reporting and checkout funnels, send standard commerce events:
Spectry.track('begin_checkout', { value: 120, currency: 'USD' });
Spectry.track('add_to_cart', { product_id: 'SKU1', price: 40, quantity: 1 });
Spectry.track('purchase', { order_total: 120, currency: 'USD', items: 3 });
Sending order_total/value and currency on purchase enables revenue, AOV and purchase counts in funnel results.
Cart value for targeting
Separately from events, tell Spectry the visitor's current cart total so optin display rules and the {{cart_total}} merge tag can use it:
Spectry.setCartValue(129.90, 'EUR');
Call it whenever the cart changes. The value is kept for the session — so an exit-intent popup two pages later still sees it — and is stored locally only; this call sends nothing to the server.
Form & multi-step events
Spectry.track('field_error', { field_name: 'email', error: 'invalid' });
Spectry.track('form_step_completed', { step_index: 2, completion_rate: 0.66 });
These power AI insights such as form-abandonment detection.
Naming events
Event names are matched exactly, so decide on a convention before you scatter track() calls across a codebase. snake_case, present tense, no site or page prefix — signup_completed, not Homepage - Signup Completed!. Renaming an event later doesn't rewrite history: you get two events, and every funnel built on the old name quietly stops counting.
No-code alternative
Prefer not to write code? Use the no-code event builder to define events from CSS selectors, scroll depth or time on page.
Where events appear
Tracked events show up under Events for your site, and can be used as funnel steps, A/B test goals, and dashboard widgets.