@grainql/tag or the script tag). Grain Tag has
no remote configuration and no template events. For those, read React app.
Install by script tag
Put the tag in the<head> of every page. The script initializes itself when it loads and
exposes the global GrainTag object.
Install by npm
For a bundled app, install the package and callinit one time. The named exports track
and identify work before init completes. Grain Tag queues the calls and replays them.
GrainTag object. With npm, replace GrainTag.track
with the track export and GrainTag.getInstance() with the getInstance export.
Page views
Grain Tag tracks the first page view and every navigation through the History API (pushState and replaceState). A page view needs no code. If your router does not use the
History API, track the navigation yourself.
Clicks
Grain Tag records every click for heatmaps. A custom event adds the properties that you choose.Form submissions
A form submission leaves the page. Callflush on the instance before you submit, so the event
reaches Grain before the page unloads.
Identify a user
After a login, pass the user ID toidentify. Every later event holds this user ID.
Consent
Grain Tag is cookieless by default and uses daily rotating IDs.grant switches to a
persistent ID in localStorage. revoke returns to daily rotating IDs. status returns the
current ConsentState, or null.
The complete page
cta_clicked event
within seconds. If an event does not appear, read Troubleshooting.