Integration
Browser API reference
track, conversion, page, identify, experiments, and flush.
window.Tracuto is the hosted-loader API. Always check isReady() before other methods.
Method reference
| Method | Signature | When | Notes |
|---|---|---|---|
| track | track(name, { category?, label?, value?, blockId?, elementId?, metadata? }) | Explicit business or product events | Use after isReady(); not required for automatic contextual clicks |
| conversion | conversion(name, value?, metadata?) | Funnel outcomes with optional revenue in value | Put currency, order id, and line items in metadata |
| page | page(metadata?) | SPA or soft navigations without full reload | Fires a page view with optional route metadata |
| identify | identify(attributes) | After login or when session fields change | String, number, or boolean keys; user_name sets display label |
| setUserId | setUserId(userId) | Stable account id from your auth system | Stitches sessions; call before or with identify |
| clearUserId | clearUserId() | Logout | Pair with flush() so pending events send before navigation |
| error | error(error, metadata?) | Uncaught or handled client errors you want in analytics | Pass Error object; add context in metadata |
| flush | flush() | Before redirect or after identify/logout | Sends queued analytics promptly |
| isReady | isReady() | Before any other call on hosted loader | False until bundle loaded and tracker started |
| getExperimentVariant | getExperimentVariant(experimentKey) | Branch UI by variant id or name | Returns assignment or null; matches dashboard experiment key |
| isExperimentEnabled | isExperimentEnabled(experimentKey, mode?) | Gate treatment vs control UI | mode: 'any-assignment' | 'non-control' | 'control' (default any-assignment) |
| getInstance | getInstance() | Advanced debugging only | Returns underlying PearTracking; prefer window.Tracuto methods |
Guard pattern
javascript
if (window.Tracuto?.isReady?.()) {
window.Tracuto.track('cta_signup_click', { category: 'hero', label: 'Get started' });
window.Tracuto.conversion('signup_completed', undefined, { source: 'integration_guide' });
}SPA page views
Full page loads are automatic. After client-side route changes, call:
javascript
// SPA page views are tracked automatically when using the Tracuto loader
// or AnalyticsPlugin with autoTrackPageViews (default). History API navigations
// (pushState, replaceState, popstate) emit page_view events for funnel analytics.
// Manual call only needed for custom routers without History API, or when
// autoTrackPageViews / trackSpaNavigations is disabled:
if (window.Tracuto?.isReady?.()) {
window.Tracuto.page({ route: '/settings/billing', source: 'spa' });
}