Skip to main content
Grain has two packages for your site: Grain Tag, the browser script, and Analytics Web, the TypeScript SDK. This page picks one for your situation, shows the install command, and shows how to make sure that events arrive. Every install needs the tenant alias from the dashboard.

Your situation

Grain Tag or Analytics Web

The script tag and the npm package are the same Grain Tag code. The script tag is an IIFE build with the tenant alias injected. Read Authentication for the strategies.

Install Grain Tag with a script tag

Add one tag to the HTML of every page:
Grain Tag then collects page views, clicks, scroll depth, heatmaps, rage clicks, dead clicks, sessions, and DOM snapshots. GrainTag.track sends a custom event, and GrainTag.identify sets the user ID after a login:

Install Grain Tag with npm

For an app with a build step, install @grainql/tag:
Call init one time. track and identify are safe to call before init completes. The package queues the calls and replays them:
The package ships TypeScript types. Read TypeScript.

Install Analytics Web

For a server, or for React hooks and remote configuration, install @grainql/analytics-web:
Read Node.js and servers for the server configuration and React hooks for the provider.

The tenant alias

Every install uses the tenant alias, not the tenant UUID. The alias is the human-readable identifier that the dashboard shows at https://grainql.com/dashboard. Replace your-tenant-id with it in every example on this site. Grain Tag is cookieless by default. Its consentMode has three values: consent.grant() moves the visitor to a persistent ID in localStorage, not in a cookie. consent.revoke() clears the stored ID and returns to daily rotating IDs. Read Privacy and consent.

Platform support

Make sure that Grain receives events

For a script tag install:
  1. Open the browser console on a page that loads the script. Grain Tag writes its initialization logs there.
  2. Run GrainTag.track('installation_test') in the console.
  3. Open the dashboard at https://grainql.com/dashboard. The event shows within 30 seconds.
For an npm install, set debug: true and send one event:
The console then shows the batching and sending activity. If no event arrives, read Troubleshooting.