Using React or Next.js? Try React Quick Start or Next.js Quick Start for framework-specific integration.
Add the Script Tag
Add this to your HTML<head>:
your-tenant-id with your tenant identifier (not UUID) from your dashboard.
That’s it! Grain is now loaded and tracking page views, heatmap clicks, scroll depth, and DOM snapshots automatically.
Complete HTML Example
Track Custom Events
Track Form Submissions
Track Link Clicks
Identify Users
Track logged-in users:Consent Management
Grain is cookieless by default with daily rotating IDs. When you need explicit consent handling:SPA Navigation
Grain Tag automatically tracks page views on initial load and hooks into the History API (pushState / replaceState) to track navigation in single-page apps. No manual page view tracking is needed for most SPAs.
If your app uses custom routing that does not go through the History API, you can track navigation manually:
Performance Tips
Do: Place Grain in the
<head> for early initializationDo: Use one script tag per page — Grain handles everything
What’s Next?
Core API Reference
See all available methods and options
Event Tracking Guide
Learn what to track and best practices
Trackers
Track element clicks without code
Vanilla JS, Vue & Svelte
Integration with other frameworks
Need remote configuration or feature flags? See @grainql/analytics-web for remote config support.