how to collect page duration of last page?
Hi 고병찬, Please stand by as I search the Mixpanel knowledge base for an AI-powered answer. I normally take about 15 seconds or so. In case AI cannot answer your question, feel free to reach out to Mixpanel support at mixpanel.com/get-support. If you have follow-up questions for this thread, please tag me again with your question: @kapa.ai <follow-up question> 👋
Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai
To collect the duration a user spends on the last page of their session in Mixpanel, you need to track the time between when the user lands on the page and when they leave (or the session ends). However, the knowledge sources do not provide a built-in Mixpanel feature that automatically tracks the duration of the last page view in a session.Here’s what is available: - Mixpanel’s session analytics provides a “Session Duration (Seconds)” property, which measures the total time spent in a session, but not specifically the duration of the last page viewed in that session Session Properties.
- You can track page view events and use the “Duration” property to measure the time between two events of the same type (e.g., between two page views), but this does not directly give you the duration of the last page, since there is no subsequent page view to mark its end Computed Properties.Possible Approach:
- On each page, use Mixpanel’s timing feature to start a timer when the page loads and send a “Page View” event with a “Duration” property when the user navigates away or the session ends. For the last page, you would need to trigger this event when the user leaves the site (e.g., using the beforeunload event in JavaScript).
- Note: This approach requires custom implementation and careful handling of edge cases (e.g., abrupt browser closes).Example (JavaScript):Limitation:
If the user closes the browser or loses connection abruptly, the event may not be sent. There is no Mixpanel-native solution that guarantees capturing the last page duration in all scenarios.If you need more robust tracking, consider using a combination of session duration and custom event tracking as described above. The knowledge sources do not mention a built-in property or report for “last page duration” specifically.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
