Before you start
You need three things:- Access to your Google Tag Manager account. The container must be installed on your site.
- Your tenant alias from the dashboard. It is the alias shown at the top of the dashboard, not the UUID.
- 10 minutes.
1. Create a tag
- Log in to Google Tag Manager.
- Select your container.
- Click Tags, then New.
- Click Tag Configuration.
- Select Custom HTML.
2. Add the code
Paste this code into the HTML field:your-tenant-id with your tenant alias.
3. Set the trigger
- Scroll to Triggering.
- Click the trigger area.
- Click + to create a new trigger.
- Select Initialization - All Pages.
- Name the trigger “All Pages - Initialization”.
- Click Save.
4. Name and save the tag
- Name the tag “Grain Analytics”.
- Click Save.
5. Test the tag
- Click Preview (top right).
- Enter the URL of your website. Google Tag Manager opens your site with a debug panel.
- Make sure that “Grain Analytics” is in Tags Fired.
- Open the browser console (F12).
- Type
window.GrainTag. The console shows theGrainTagobject.
GrainTag object, the installation works.
6. Publish
- Click Submit (top right).
- Name the version, for example “Added Grain Analytics”.
- Add a description. This step is optional.
- Click Publish.
Track custom events
After the Grain Tag is installed, you can send an event for a specific user action. Each event is a new Custom HTML tag with its own trigger.{{Click Text}}, {{Click URL}}, and {{Form ID}} are built-in Google Tag Manager variables.
Enable them in Variables, then Configure.
Button clicks
- Create a new Custom HTML tag.
- Add this code:
- Set the trigger to All Elements - Click.
- Add filters to select the buttons that you want to track.
Form submissions
- Create a new Custom HTML tag.
- Add this code:
- Set the trigger to Form Submission.
Link clicks
- Create a new Custom HTML tag.
- Add this code:
- Set the trigger to Just Links - All Elements.
Troubleshooting
Read Troubleshooting for cases that are not specific to Google Tag Manager.
Next steps
Trackers
Track clicks on specific elements from the dashboard, without code.
Heatmaps
See where visitors click and how far they scroll.
Tracks
Build funnels and paths from the events that the Grain Tag records.
Privacy and consent
What Grain stores, cookieless mode, and consent modes.