Given: Use client-side SDK to track "view_page" events that are triggered every time a page loaded. How can I know the total time on page & average time on page? Should I use client-side SDK to implement timed_events "page_close" with a “duration” property? (e.g. the timer starts at "view_page" and ends at "page_close")
To track total time on page and average time on page using Mixpanel's client-side SDK, you can indeed use timed events as you suggested. Here's how you can implement this:1. Use the track()
method to send a "view_page" event when a page is loaded.
2. Use the timeEvent()
method to start timing the page view.
3. When the user leaves the page, track a "page_close" event, which will automatically include the duration.Here's an example of how you can implement this using the JavaScript SDK:LBKS// When page loads mixpanel.track('view_page', { 'page_name': 'Home' // You can add more properties as needed }); mixpanel.timeEvent('page_close');LBKS// When user leaves the page (you'll need to implement this based on your specific use case) mixpanel.track('page_close');LBKS
This approach will automatically include a "Duration" property in your "page_close" event, which represents the time spent on the page in seconds.To calculate the total time on page and average time on page, you can use Mixpanel's Insights report:1. For total time on page: Use the "page_close" event and set the measurement to "Aggregate Property" > "Sum" of the "Duration" property.
2. For average time on page: Use the "page_close" event and set the measurement to "Aggregate Property" > "Average" of the "Duration" property.This method is indeed a good way to implement time tracking for pages using Mixpanel's client-side SDK. It allows you to accurately measure the time spent on each page and provides flexibility for further analysis.For more details on implementing timed events and using the Insights report, you can refer to:
- Mixpanel SDKs: Javascript Sending Events>
- Insights: Visualize trends and compositions within your data Advanced > Measurements>
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.
kapa.ai In this doc: https://docs.mixpanel.com/changelogs/2023-11-16-duration You mentioned that Mixpanel auto-computes Duration by calculating the time between Page View events. Does it work if my event name is "view_page" instead of "Page View"? When it comes to the "time on page" metrics, what are the pros and cons between implementing timed_event "close_page" through SDK and use Mixpanel's auto-computed property?
Let me check the knowledge base for you again. One moment! 📚
I apologize, but I don't have access to the specific document you're referring to in your question. The knowledge sources provided to me don't include information about Mixpanel auto-computing Duration by calculating time between Page View events. Without this context, I can't accurately comment on whether it would work with a "view_page" event instead of "Page View".However, I can provide some general information about tracking time on page in Mixpanel based on the knowledge sources available to me:1. Mixpanel doesn't automatically track page views. As mentioned in the Install Mixpanel FAQ, you need to pass track_pageview: true
in the mixpanel.init()
call to automatically track a "Page View" event every time a new page is loaded.2. For custom event names like "view_page", you would typically need to implement this tracking manually using the SDK's track method.3. Regarding the pros and cons of implementing a timed event "close_page" through SDK versus using Mixpanel's auto-computed property, I don't have enough information from the provided knowledge sources to make a comparison. The sources don't mention an auto-computed Duration property for page views.4. If you choose to implement timed events manually, you can use the timeEvent()
method followed by a track()
call, as described in the JavaScript SDK documentation. This method allows you to accurately measure the time spent on each page.For the most accurate and up-to-date information about Mixpanel's capabilities regarding auto-computed Duration for page views, I recommend checking the latest documentation or contacting Mixpanel support directly. The information in the changelog you mentioned might reflect recent changes that are not covered in the knowledge sources provided to me.
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.