Frontend IntegrationWeb ObjectSophiTracker API

SophiTracker API

After the bundle loads, window.SophiTracker exposes the public imperative API for SPAs, batched updates, login/logout events, and multi-object pushes such as add_to_cart.

After the bundle loads, window.SophiTracker exposes the public imperative API. Use it for SPAs, batched updates, login/logout, and multi-object events (e.g. add_to_cart with both product and basket).

SophiTracker.push(partial)

SophiTracker.push(
  partial: Partial<Omit<SophiObjectShape, 'config'>>
): void
  • Merges every key in partial into window.sophi_object.
  • Processes the update once per watched key present in partial (page, user, product, basket, listing, transaction), which may produce one event per key.
  • If partial.event_type is set, it overrides the default event_type for all triggers in that single push call.
  • If called before the SDK has finished starting, it no-ops and warns.

Typical use: route changes, add-to-cart, or syncing several objects atomically.

SophiTracker.updateUser(userId)

SophiTracker.updateUser(userId: string | undefined): void
  • Clears the current session (cookies and local session state).
  • Sets config.userId to the new value (or clears it when undefined / empty).
  • Establishes a new session with Sophi so subsequent events use fresh credentials.

Call after your auth layer confirms login (pass stable external id) or logout (pass undefined for an anonymous session).

SophiTracker.setConsent(granted)

SophiTracker.setConsent(granted: boolean): void

Grants or withdraws storage consent at runtime. Use it together with config.storageConsent: false to run the Web Object in Cookie Consent Management.

  • setConsent(true) — activates the previously passive Web Object: it creates a session, writes cookies, and starts sending events (including the current sophi_object snapshot).
  • setConsent(false) — makes it passive again and clears the session cookies.
// Visitor accepted cookies in your consent banner
window.SophiTracker.setConsent(true);

Until setConsent(true) is called (or config.storageConsent is true), the Web Object sends no events. push(...) calls are dropped while passive.

SophiTracker.getSession()

SophiTracker.getSession(): Promise<SophiSession>

Returns a promise for the SDK’s active session object. Intended for debugging or advanced integrations; normal storefront tracking does not require calling this.

On this page