Instrumenting the Duration Event Property

  • 2 December 2020
  • 6 replies

Userlevel 5
Badge +8

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: 


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.

6 replies


@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 +8

@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.


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”.


@Amplitude Admin

Would this be possible using the amplitude event timestamps of the 2 different timestamps we would derive the “duration” from? 
So for example START_EVENT has a timestamp we send to Amplitude (or if we don’t have a timestamp it is derived by your server)
And END_EVENT has a similar timestamp derived from the the time the event arrived at the server.

So how can I derive the time between the two events (duration) without manually creating a UNIX timestamp custom event property. Is this possible?

Userlevel 5
Badge +2

Hi @n8descript 😃 Thanks for this question. I’ve looped in @ning.chang, who will take a closer look. In the meantime, I ran a search in the community and found these threads that might help. Please keep us posted as you make progress! 


Userlevel 4
Badge +2

hi @n8descript, you can check out the derived properties function to calculate this! this feature is available for customers with the govern add-on!