This guide works with Vue, Svelte, Angular, or plain JavaScript — either via script tag or npm.
Using React or Next.js? Try the React Quick Start or Next.js Quick Start instead.
Option 1: Script Tag (Recommended)
Add the Grain Tag script to your HTML:your-tenant-id with your tenant identifier from your dashboard.
Then get the SDK instance in your JavaScript:
Option 2: npm Package
Install via your package manager:npm
yarn
pnpm
track, identify) directly, or get the instance with getInstance().
Automatic Tracking
Grain Tag automatically tracks the following with zero configuration:- Page views — including SPA navigation via the History API
- Heatmap clicks — click positions with element identification
- Scroll depth — how far users scroll on each page
- DOM snapshots — visual page captures for heatmap overlays
- Sessions — session start/end with duration
- Device, browser, and OS — automatically detected
- UTM parameters and referrer — captured on first visit
page_viewed calls are needed. Grain Tag hooks into pushState and replaceState automatically.
Track Custom Events
Calltrack() with an event name and optional properties:
Identify Users
Associate events with a specific user:Consent Management
Grain is cookieless by default with daily rotating IDs. When you need explicit consent handling:Complete Example
Here’s a small app that puts it all together:Vue.js Example
Using Grain Tag in a Vue component: Script tag approach (add<script src="https://tag.grainql.com/v4/your-tenant-id.js"></script> to your index.html):
main.ts):
Svelte Example
Using Grain Tag in a Svelte component: Script tag approach (add<script src="https://tag.grainql.com/v4/your-tenant-id.js"></script> to your app.html):
What’s Next?
Core API Reference
See all available methods and options
User Identification
Learn about tracking users across sessions
Trackers
Track element clicks without writing code
Event Best Practices
Learn what to track and how to structure events
Need remote configuration or feature flags? See @grainql/analytics-web for remote config support, React hooks, and more.