EventTracker: Time on Page
Development of a time-measurement mechanism for landing pages within EventTracker, Landingi’s behavioural analytics tool. The project involved implementing two independent counters: page visibility time and actual user activity time.
– enlargeWhere it started
EventTracker let users analyse visitor behaviour on landing pages, but there was no data on how long visitors actually spent on them. Measuring from page open to close alone did not reflect real engagement, because users could switch tabs, leave the page open without interacting, or return to it within the same session.
The challenge
My task was to build a time-measurement mechanism in the EventTracker script that distinguished page visibility from user activity, accounted for browser behaviour and kept API request volume low. I was also responsible for presenting the collected data in the application dashboard.
How I built it
In the EventTracker script written in TypeScript I implemented two independent counters: page visibility time and user activity time, detected from interactions such as clicks, scrolling, cursor movement, keyboard and touch. After 5 seconds of inactivity I paused the activity counter, and when the tab was hidden I paused both counters.
I introduced an adaptive data-sending interval that lengthened with visit duration (from 1 to 60 seconds), reducing request volume during longer sessions. When the tab was hidden or the page was left I used navigator.sendBeacon with a fetch fallback. I added localStorage persistence so measurement could continue after a page refresh or re-entry within the same session.
I also handled back/forward cache (bfcache) returns, guarded against duplicate sends and covered edge cases such as disabling measurement on thank-you pages and keeping the active time from exceeding the total.
In the SPA I integrated the API data and added a dashboard panel showing average page visibility time and user activity time, also broken down by device.
The outcome
Landingi users gained access to statistics showing not only how long their landing pages were visible, but also the actual activity of visitors, giving a clearer picture of engagement. The mechanism accounts for tab switching, inactivity and within-session returns, while local data persistence and on-leave sending reduce the risk of losing results.
The adaptive interval also cuts server request volume during longer visits.