Skip to main content
Both SDKs start to collect data as soon as they load. The Grain Tag collects the most. Analytics Web collects page views, sessions, and heartbeats, and adds heatmap tracking as an option. Every automatic feature adapts to consent: before consent it sends a minimal payload, and after consent it sends the full one. Automatic tracking runs only in a browser. The SDK looks for window and starts tracking on the client side. The TypeScript types of the published packages win over this page when they disagree.

What is collected

Every Grain Tag option above defaults to true. In Analytics Web, enableAutoPageView and enableHeartbeat default to true. Read Configuration options. Read Heatmaps for what the dashboard shows from clicks, scroll depth, and snapshots. Automatic events carry device, attribution, and session properties. Read Automatic properties.

Page views

The SDK sends a page_view event on the first load, on pushState and replaceState, on popstate, and on hashchange. React Router, Vue Router, Next.js App Router and Pages Router, and hash routing need no extra configuration. Query parameters are removed from the page property by default. A URL of https://example.com/products?search=shoes is sent as /products. Set stripQueryParams to false to keep them. stripHash removes the hash in the same way.
Analytics Web
With enableAutoPageView set to false, call trackPageView yourself.

Heartbeat

The heartbeat measures whether a session is active. The SDK watches mouse, keyboard, touch, and scroll events. It sends _grain_heartbeat with status set to active or inactive. The first heartbeat is sent on page load. The heartbeat starts when the SDK initializes and stops on destroy.
Analytics Web
Set enableHeartbeat to false to turn the heartbeat off. The listeners are passive and debounced, and the heartbeat runs on a timer, not on every event. Before consent, the SDK uses a session ID that lives only in memory. It sets no cookie and writes no identifier to localStorage. After consent, it uses a persistent user ID in localStorage or a cookie. A heartbeat before consent:
The same heartbeat after consent:
When a user is identified with identify or login, or the SDK uses JWT authentication, the SDK uses the persistent identifier before consent too. This use is functional, not analytical. Read Privacy and consent for the consent modes of both SDKs and the legal basis for minimal tracking. When the user grants consent, the SDK moves from the minimal payload to the full one on its own.
  1. Before consent, events carry the session ID that lives in memory.
  2. On grant, the SDK sends _grain_consent_granted with the old session ID and the new user ID.
  3. After the grant, every event carries the persistent user ID.
With this event, a backend can join the events from before and after consent.
After revoke, automatic tracking continues with the minimal payload or stops. The consent mode in the configuration decides which.

Read the session

Analytics Web exposes the identifiers that automatic tracking uses.
Analytics Web
getSessionId returns the in-memory session ID before consent and the persistent one after. getEffectiveUserId returns the persistent ID when one exists.

Rules for the client

  1. Keep the defaults on. The dashboard reads sessions, page views, and heartbeats from these events.
  2. Keep stripQueryParams set to true. Query strings hold search terms and tokens.
  3. State in your privacy policy what Grain collects before and after consent, from the table above.
  4. Test the site with consent denied. Make sure that only the minimal payload leaves the page.
  5. To stop every automatic feature at run time, call destroy. To stop one feature, set its option to false at initialization.