Skip to main content

Method reference

MethodParametersReturnsDescription
identify()userId: string, attributes?: UserAttributesvoidAssociate session with a known user
track()event: string, data?: Record<string, unknown>voidSend a custom behavioural event

identify()

Associate the current browser session with a known user ID and optional attributes.
Full reference: identify()

track()

Send a custom behavioural event. Events are stored in analytics and can be used in targeting rules.
Full reference: track()

Internal properties

_q

The pre-init call queue. Before the snippet has evaluated, calls to identify() and track() are pushed here as tuples. After initialisation, the queue is drained and _q is an empty array. Do not write to _q directly — use the methods above.

TypeScript declaration

Copy this global declaration into your project to get full type safety:

Error handling

All methods catch errors internally. If the Zenstep snippet encounters an error processing an identify() or track() call, it logs a warning to the browser console ([Zenstep] identify error: ...) and continues. Your application code will never throw due to a Zenstep call.

Versioning

The snippet API follows semantic versioning. Breaking changes to the public API surface will increment the major version and be announced in the changelog. The CDN URL (/v1/snippet.js) pins you to the v1 major version — you will receive backward-compatible updates automatically.