Skip to main content
The primary way to install Grain. Perfect for any website — landing pages, static sites, CMSs, or full web apps. No build tools required. Grain Tag automatically tracks page views, clicks, scroll depth, heatmaps, and DOM snapshots with zero code. Just add the script and you’re collecting data.
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>:
Replace 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

You can also use the top-level shortcut:
Events are automatically batched and sent. No manual flushing needed.

Track Form Submissions

Identify Users

Track logged-in users:
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 initialization
Do: Use one script tag per page — Grain handles everything
Don’t: Load Grain multiple times — once per page is enough

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
Using Google Tag Manager instead? Check out the GTM Integration Guide for a no-code setup.
Need remote configuration or feature flags? See @grainql/analytics-web for remote config support.