What Are Template Events?
Template events are pre-built methods for common tracking scenarios. Instead of remembering property names and structure, use ready-made methods: Without templates:Why Use Templates?
Type Safety: TypeScript knows which properties are available:grain.track() for custom events. Templates are optional helpers for common cases.
Authentication Events
trackLogin()
Track when users log in:method: ‘email’, ‘google’, ‘github’, etc.success: Whether login succeedederrorMessage: If login failed, why?rememberMe: Whether “remember me” was checkedtwoFactorEnabled: If 2FA was used
trackSignup()
Track new user registrations:method: How they signed upsource: Where they came fromplan: Which plan they chosesuccess: Whether signup completedreferralCode: If they used a referral
E-commerce Events
trackCheckout()
Track when users start or complete checkout:orderId: Unique order identifiertotal: Total amountcurrency: Currency code (USD, EUR, etc.)items: Array of products (see below)paymentMethod: How they’re payingcouponCode: Any discount codes used
trackPurchase()
Track completed purchases:trackAddToCart()
Track when items are added to cart:trackRemoveFromCart()
Track when items are removed:Navigation Events
trackPageView()
Track page views:page: Page pathtitle: Page titleurl: Full URLreferrer: Where user came from
trackSearch()
Track search queries:query: What user searched forresults: Number of results foundfilters: Any filters appliedsortBy: Sort order used
Using Template Events
All template methods work liketrack():
Creating Custom Events
For events not covered by templates, usetrack():
Real-World Example
Here’s a complete user flow with template events:Available Templates
Current template methods:trackLogin()- User logintrackSignup()- User registrationtrackCheckout()- Checkout processtrackPurchase()- Completed purchasetrackAddToCart()- Add to carttrackRemoveFromCart()- Remove from carttrackPageView()- Page viewstrackSearch()- Search queries