You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Negative engagementDuration Values Due to Time Synchronization Issues #40
We use Cloudflare Zaraz to integrate GA4 for event monitoring. While analyzing the underlying GA4 event data, we discovered an interesting phenomenon: a significant number of engagement_time_msec values are appearing as negative.
Root Cause Analysis
After investigating, we identified that this occurs when there's a time synchronization discrepancy between the user's device and Cloudflare Worker (Zaraz's execution environment). Specifically, negative engagement_time_msec values appear when the user's device time is ahead of the Worker time.
When the user leaves the page, a visibilitychange event triggers, and engagementDuration is calculated on the worker side as approximately now - engagementStart. In cases where the client time is ahead of the server time, this results in a negative engagementDuration
This can be verified by querying the underlying event data in BigQuery for GA4, where engagement_time_msec reflects this time difference
It's worth noting that the issue also affects accuracy when client time lags behind server time, resulting in inflated engagement duration values.
Suggested Solution
It might be worth considering using timestamps consistently (either all client-side or all edge-side) when calculating engagementDuration. This could help address potential issues since client-side time discrepancies are fairly common.
Reacted by Simona Badoiu, Haochuan Guo, Siqi Liu, liyanan666, Jiahao Lu, matthew-abbott and bigmac44
changed the title [-]Negative `engagement_time_msec` Values Due to Time Synchronization Issues[/-][+]Negative `engagementDuration` Values Due to Time Synchronization Issues[/+]on Feb 13, 2025
Activity
[-]Negative `engagement_time_msec` Values Due to Time Synchronization Issues[/-][+]Negative `engagementDuration` Values Due to Time Synchronization Issues[/+]