Before you start
You need three things:- Your tenant alias. The dashboard at
https://grainql.com/dashboardshows it. It is not the UUID. - Write access to the HTML of your site, or to a tag manager. For Google Tag Manager, read Google Tag Manager.
- A browser with developer tools, to make sure that events arrive.
1. Add the script
Put this tag in the<head> of every page. Replace your-tenant-id with your tenant alias.
GrainTag object. Add the tag
one time per page. A second tag on the same page is not necessary.
2. Make sure that events arrive
Open the page in a browser. In the developer console, run:installation_test event within 30 seconds. If the event does not
appear, read Troubleshooting.
3. Track a custom event
Calltrack with an event name and an optional properties object.
GrainTag.track and GrainTag.identify work before initialization completes. Grain Tag queues
the calls and replays them after initialization. Read Track an event and
Name events.
4. Identify a user
After a login, pass the user ID toidentify. Every later event holds this user ID.
5. Grant consent
Grain Tag is cookieless by default and uses daily rotating IDs. When your site asks for consent, call theconsent methods on the instance.
grant enables persistent tracking. Grain Tag stores the persistent ID in localStorage, not in
a cookie. status returns the current ConsentState, or null. Read
Privacy and consent.
6. Single-page applications
Grain Tag tracks the first page view and every navigation through the History API (pushState and replaceState). A router that uses the History API needs no extra code.
If your router does not use the History API, track the navigation yourself:
Next steps
Core methods
Every method of both SDKs, with signatures.
Trackers
Track element clicks from the dashboard, without code.
Plain JavaScript, Vue, and Svelte
Grain Tag through npm in any framework.
Automatic tracking
What Grain Tag collects without code.