Skip to main content
This page builds one HTML page that uses Grain Tag for page views, clicks, a form, a user ID, and consent. Every block uses Grain Tag (@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 call init one time. The named exports track and identify work before init completes. Grain Tag queues the calls and replays them.
The rest of this page uses the global 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.
Read Automatic tracking.

Clicks

Grain Tag records every click for heatmaps. A custom event adds the properties that you choose.
For a click on one element, a tracker in the dashboard needs no code. Read Trackers.

Form submissions

A form submission leaves the page. Call flush 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 to identify. Every later event holds this user ID.
Grain Tag has no method that clears the user ID. Read Identify users. 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.
Read Privacy and consent.

The complete page

Open the page in a browser. The dashboard shows the page view and the cta_clicked event within seconds. If an event does not appear, read Troubleshooting.