Skip to main content
The Tolstoy SDK sends your own events to Tolstoy analytics. Use it to count anything that shoppers do on your storefront, for example how many times shoppers click Expand product details.
Your events never count toward Shoppable Videos view billing, and they never change the numbers of your Tolstoy widgets: they are not opens, engaged shoppers, try-ons, add to carts or revenue.

Add the SDK

The SDK is an ES module on the Tolstoy CDN. Create one SDK on the page, and send each event with tolstoy.analytics.track():
The SDK throws an error when appKey or the event name is empty. It sends the events in batches: every 10 seconds, when 10 events are in the queue, and when the shopper leaves the page. Tolstoy drops an event that is larger than the limits above. The SDK sends no event and stores no shopper ID until the shopper allows analytics. It drops the events from before that; it does not keep them for later. At each event, the SDK reads the tolstoy-cookie-policy value in localStorage: accepted allows analytics, and rejected blocks it. Your page sets this value from the consent tool of your store, before the first event and again when the shopper changes the answer. The SDK does not load a consent tool and does not wait for one. See Cookie Consent for what the SDK does without the value. On Shopify, get the answer from Shopify’s Customer Privacy API:
Put this code after startTracking and the code that it uses: when the page already loaded the API, Shopify calls the callback at once. With a different consent tool, call passConsent from the consent callback of that tool.

Read the results

The report reads tables that Tolstoy builds each night. It covers full UTC days before today. The events of today show after the next build, from about 06:30 UTC. With the Tolstoy CLI:
In the details, events lists each of your events with the widget type tolstoy-sdk, its name, the number of events and the number of shoppers who sent it:
  • --app-url selects a store from tolstoy stores list. Without it, the CLI uses your default store.
  • --channel (web or app) limits the report to your website or your Tapcart app.
With the Tolstoy MCP, the get_store_analytics tool returns the same report. Ask for the details section. The CLI and the MCP read only the stores of the workspace that you signed in to.