Before you start
You need three things:- Your tenant alias. The dashboard at
https://grainql.com/dashboardshows it. It is not the UUID. - A decision between the script tag and the npm package. The script tag needs no build step. The npm package gives you typed imports.
- A browser with developer tools, to make sure that events arrive.
1. Install by script tag
Put this tag in the<head> of your HTML. Replace your-tenant-id with your tenant alias.
GrainTag object with track, identify,
and getInstance. If you use the script tag, skip step 2.
2. Install by npm
init one time, in the entry point of your app.
init returns a no-op stub, so a server
render or a test does not need a guard. track and identify called before init are queued
and replayed after initialization.
3. Make sure that events arrive
Open the app in a browser. In the developer console, run:installation_test event within 30 seconds. With the npm package, pass
debug: true to init to see the batching and sending activity in the console. If the event
does not appear, read Troubleshooting.
4. Track a custom event
Calltrack with an event name and an optional properties object. The script tag and the npm
package use the same signature.
GrainTag.track with the same arguments. Grain Tag batches events and
sends them in groups. A manual flush is not necessary. Read
Track an event.
5. Identify a user
After a login, pass the user ID toidentify. Every later event holds this user ID.
GrainTag.identify('user_123'). Read
Identify users.
6. 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. status returns the current ConsentState, or null.
Read Privacy and consent.
7. Vue
Callinit in main.ts, then call track from any component.
index.html, call GrainTag.track instead of the import.
8. Svelte
Callinit in src/main.ts, then call track from any component.
app.html, call GrainTag.track instead of the import.
Next steps
Core methods
Every method of both SDKs, with signatures.
Identify users
Anonymous IDs, daily rotating IDs, and
identify.Trackers
Track element clicks from the dashboard, without code.
Track an event
Properties, batching, and delivery.