Instrumenting the Duration Event Property

  • 2 December 2020
  • 3 replies
  • 2144 views

Userlevel 5
Badge +2

Media customers that are interested in tracking the amount of time users spend on their products would be interested in instrumenting a property that measures the duration between two events. With this property, users can then measure various items such as Average Property Value, Median Property Value, or use the duration values in complex formulas in our Event Segmentation: Formulas chart. 

 

To track duration, you would need to capture the timestamp of a Start Event and timestamp of an End Event, calculate the difference between the two timestamps, and then pass in the duration as an event property for the End Event. In our demo account this End Event is called Played Song, and here is an example chart: https://analytics.amplitude.com/demo/chart/new/snewb09 

 

As an example for Page View events, let's say you have a Start Event = 'Viewed Home Page' and an End Event = 'Clicked Signup'. When the user fires the 'Viewed Home Page' event, you can create a variable in your code called first_timestamp and pass in the current timestamp. When the user is going to fire the 'Clicked Signup' event, you would calculate the difference between the current timestamp and first_timestamp and pass that value into the 'duration' event property. You would then send the 'Clicked Signup' event with the 'duration' event property. This way, you can segment and filter on the value of the 'duration' event property for the 'Clicked Signup' event to see how long it took users to click that button after viewing your home page.

 

We also recommend normalizing the 'duration' event property to a numerical value like seconds so that you can perform functions such as property average in the UI.


3 replies

Badge

@daniel.balan if there are multiple exit points from the home page besides sign up (say Viewed Help Site), then it might make more sense to associate duration with the “Viewed Home Page” event, instead of “Clicked Signup”. Otherwise it would be difficult to figure out time spent on home page, by adding up durations sent in all the exits events from the home page.

I am wondering if there is a way to “update” duration in the Viewed Home Page event after it has been logged. May be takings event id and using some api to update duration in it, either from the client itself or server.

Or may be another way.

Userlevel 5
Badge +2

@dadude  hey! any update to the duration property would have to be done before the event is fired and reaches Amplitude. Once the event reaches Amplitude, the event cannot be updated, since historical data cannot be tampered with.

Badge

Thanks for the response @daniel.balan . For now we have added an additional generic event which contains duration and the screen for which duration is sent. Its of course going to double our screen view count.

I started learning and using amplitude about a month back. And it’s totally awesome, after the dark ages I spent using ga and firebase. But this one little thing has proven to be quite an irritant. Tracking time spent on screen is a pretty basic requirement for measuring “engagement”.

Reply