GrainConfig.
1. Page visibility
Rule: tracking stops while the page is hidden. Reason: a page in a background tab or a minimized window receives no attention. Events sent during that time inflate time on section. How it is applied: the SDK readsdocument.visibilityState through the Page Visibility API.
Tracking pauses at the moment the page becomes hidden. When the page becomes visible again,
tracking resumes and every section timer starts from zero.
2. User activity
Rule: tracking stops after 30 seconds without user input. Reason: a user who has not moved the mouse, touched the screen, pressed a key, or scrolled for 30 seconds is not reading the page. How it is applied: the SDK listens formousemove, mousedown, keydown, scroll,
touchstart, and click. It records the time of the last input, debounced to one update per
500 milliseconds. Before it sends an event, the SDK compares the current time with that
record. If the gap is more than 30 seconds, the event is not sent. Tracking resumes on the
next input.
3. Section duration cap
Rule: a section collects at most 9 seconds of attention before a scroll is required. Reason: a user who stays on one section without a scroll is either reading it, or has stopped looking. The cap keeps the first case and drops the second. A user who reads scrolls to the next part. How it is applied: the SDK sends a section view event every 3 seconds while a section is visible and adds the duration to a total for that section. When the total reaches 9 seconds, the SDK stops sending events for that section. The total returns to zero when the user scrolls 100 pixels or more, when the user moves to another section, or when the page becomes visible again.4. Scroll distance
Rule: a scroll counts only when it moves 100 pixels or more. Reason: a small movement, such as a touchpad drift or a view adjustment, is not a sign that the user reads on. 100 pixels is about 13 percent of a small mobile screen and about 9 percent of a desktop screen. How it is applied: the SDK stores the scroll position of each section at the last reset. Before it sends an event, the SDK computes the distance from that position. If the distance is 100 pixels or more, the section total returns to zero and tracking continues. If the distance is less than 100 pixels and the total has reached 9 seconds, the event is not sent.Thresholds
The values in the SDK are
maxSectionDuration: 9000, minScrollDistance: 100, and
idleThreshold: 30000, in milliseconds and pixels. They are the same for every tenant.
Events
The rules filter two events. An event is sent only when all four rules pass.
For
_grain_heatmap_scroll, the viewport section takes the place of the section name in rule
3. A change of viewport section resets the total.
Read Automatic tracking for the other events that the SDK sends
without code.
One reading session
- The user opens the page. Section tracking starts.
- After 3 seconds, the SDK sends the first segment. After 6 and 9 seconds, the second and third. The total is 9 seconds.
- The user stays without a scroll. The fourth segment is not sent.
- The user scrolls 150 pixels. The total returns to zero.
- After 3 seconds on the new section, the SDK sends a segment.
- The user switches tabs. Tracking pauses.
- The user returns after 5 minutes. Tracking resumes and every total returns to zero.
- The user leaves the desk for 35 seconds. Tracking pauses after 30.
- The user moves the mouse. Tracking resumes.
Debug output
Setdebug: true to write each rule decision to the console.