Skip to main content
A template event is a track call with a fixed event name and a TypeScript type for its properties. trackLogin({ method: 'email' }) sends the same event as track('login', { method: 'email' }). The type tells your editor which properties exist, and every part of your code sends the event with the same name. Analytics Web has eight template methods. Grain Tag has none. It sends every event with track.

Methods

Every method has the signature (properties?, options?) and returns Promise<void>. options is SendEventOptions, which holds one field, flush. With flush: true, the SDK sends the event at once instead of the next batch. Read Track an event.
Every property is optional. Every property type extends Record<string, unknown>, so you can add your own keys next to the typed ones. The types in @grainql/analytics-web win over the tables on this page.

trackLogin

trackSignup

trackCheckout

trackPurchase

checkout marks the start or the end of a checkout. purchase marks a completed transaction. Send both, and the dashboard shows the checkout completion rate as a track. Read Tracks.

trackAddToCart

trackRemoveFromCart

RemoveFromCartEventProperties has the same fields as AddToCartEventProperties.

trackPageView

Both SDKs track page views without code. Call trackPageView only when automatic page views are off, or when a route change is not visible to the SDK. Read Automatic tracking.

trackSearch

For an event that no template covers, call track with your own name. Read Name events. A full shop flow with these methods is in E-commerce tracking.