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 apage_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
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
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 and after consent
Before consent, the SDK uses a session ID that lives only in memory. It sets no cookie and writes no identifier tolocalStorage. After consent, it uses a persistent user ID in
localStorage or a cookie.
A heartbeat before consent:
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.
Consent upgrade
When the user grants consent, the SDK moves from the minimal payload to the full one on its own.- Before consent, events carry the session ID that lives in memory.
- On grant, the SDK sends
_grain_consent_grantedwith the old session ID and the new user ID. - After the grant, every event carries the persistent user ID.
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
- Keep the defaults on. The dashboard reads sessions, page views, and heartbeats from these events.
- Keep
stripQueryParamsset totrue. Query strings hold search terms and tokens. - State in your privacy policy what Grain collects before and after consent, from the table above.
- Test the site with consent denied. Make sure that only the minimal payload leaves the page.
- To stop every automatic feature at run time, call
destroy. To stop one feature, set its option tofalseat initialization.