-
Notifications
You must be signed in to change notification settings - Fork 173
Description
I noticed in the /sessions dashboard that the session duration was often inaccurately shown to be 0 seconds. This was an unexpected result because I expected it to be equal to the rrweb recording length which showed a recording of several seconds or minutes long.
It appears that the current method of tracking session duration is calculated by the elapsed time between when the user's first recorded event and the last recorded event. The problem is that there is often only one event to initialize the session and no subsequent events and thus the session duration is calculated to be 0. An example of this is when a user goes directly to our blog post, spends some time reading it, and then closes the tab.
I attempted to solve this by firing an event to posthog in a beforeunload callback (when the user exits the page). Unfortunately this doesn't reliably send an event to posthog. One workaround is to send stubbed capture events to posthog at a regular interval (ex. every few seconds). But this doesn't seem like the best solution. I at least expected the events recorded by /recorder.js to be counted in the session duration calculation