New to GTM? You’ll need a Google Tag Manager account and container installed on your site.
What You’ll Need
- Access to your Google Tag Manager account
- Your Grain tenant ID from grainql.com/dashboard
- 10 minutes
Step 1: Create a New Tag
- Log into Google Tag Manager
- Select your container
- Click Tags → New
- Click Tag Configuration
- Choose Custom HTML
Step 2: Add the Code
Paste this into the HTML field:'your-tenant-id' with your actual tenant ID from the dashboard!
Step 3: Set the Trigger
- Scroll to Triggering
- Click the trigger area
- Click + to create a new trigger
- Choose Initialization - All Pages
- Name it “All Pages - Initialization”
- Click Save
Why Initialization? This fires before anything else, ensuring Grain loads early and captures all interactions.
Step 4: Name and Save
- Name your tag “Grain Analytics”
- Click Save
Step 5: Test It
Before going live, preview your changes:- Click Preview (top right)
- Enter your website URL
- GTM opens your site with a debug panel
- Check that “Grain Analytics” appears in Tags Fired
- Open browser console (F12)
- Type
window.grain— you should see the Grain object
Step 6: Publish
Everything working? Let’s go live:- Click Submit (top right)
- Name your version (e.g., “Added Grain Analytics”)
- Add a description (optional)
- Click Publish
Track Custom Events
Now that Grain is installed, track specific user actions:Track Button Clicks
- Create a new tag (Custom HTML)
- Add this code:
- Set trigger to All Elements - Click
- Add filters to target specific buttons
{{Click Text}} and {{Click URL}} are built-in GTM variables. Enable them in Variables → Configure.Track Form Submissions
- Create a new tag (Custom HTML)
- Add this code:
- Set trigger to Form Submission
Track Link Clicks
- Create a new tag (Custom HTML)
- Add this code:
- Set trigger to Just Links - All Elements
Troubleshooting
Tag Not Firing
- Check your trigger is set to Initialization - All Pages
- Make sure you published (not just saved)
- Clear browser cache and reload
Events Not Showing in Dashboard
- Verify your tenant ID is correct
- Check browser console for errors (F12 → Console)
- Make sure
window.grainexists (type it in console)
GTM Conflicts
- Move Grain’s tag to higher priority: Tag → Advanced Settings → Tag firing priority
- Try DOM Ready trigger instead of Initialization