What You’ll Need
- Admin access to your Shopify store
- Your Grain tenant ID from grainql.com/dashboard
- 10 minutes
Step 1: Open Theme Code
- Log into Shopify admin
- Click Online Store → Themes
- Find your active theme (has “Current theme” badge)
- Click Actions → Edit code
Step 2: Edit theme.liquid
- In the file list, find Layout folder
- Click theme.liquid
- Find the
</head>tag (use Ctrl+F / Cmd+F to search) - Add this code right before
</head>:
your-tenant-id with your tenant identifier (not UUID)!
Step 3: Save
Click Save (top right). You’ll see a confirmation message. That’s it! Grain is now tracking your store. 🎉Track E-commerce Events
Let’s track the important stuff: cart additions, checkouts, and purchases.Track “Add to Cart”
Still in theme.liquid, add this just before</body>:
Track Checkout Started
Track Purchases
For completed orders, add this to Settings → Checkout → Order status page → Additional scripts:Order status scripts: Available in Settings → Checkout on Shopify Plus or certain themes.
Track Product Views
Add this in theme.liquid to track product page visits:Track Search
Test Your Integration
- Open your store in an incognito/private window
- Browse a product, add to cart, go to checkout
- Open browser console (F12 → Console)
- Type
window.grain— you should see the Grain object - Check your Grain dashboard for events
Troubleshooting
Code Not Working
- Check for typos in your tenant ID
- Clear cache (Ctrl+Shift+R / Cmd+Shift+R)
- Check browser console for errors (F12)
- Verify code is before
</head>or</body>tags
Events Not in Dashboard
- Wait 1-2 minutes (slight delay is normal)
- Check that
window.grainexists in console - Verify tenant ID matches your dashboard
- Make sure you saved the theme file
Theme Broke
- Revert to backup: Themes → Actions → Unpublish, then publish your backup
- Double-check you didn’t delete any Liquid tags (
{{ }}or{% %})
What’s Next?
Tracks & Funnels
Analyze customer journeys from landing to purchase
E-commerce Guide
Best practices for e-commerce analytics
Remote Config
A/B test pricing, messaging, and layouts
Query API
Build custom reports