How to track user visit duration in sitecore analytics

466 Views Asked by At

We need to track all users(anonymous and authenticated) who spent more than 2 minutes on the site? Is it possible through OOB ways of Sitecore or do we need to write any custom pipeline\processor?

If custom way, what's the best pipeline to override(Session End or VisitEnd pipeline of analytics) and also how to calculate the user session duration?which attribute would give the exact time details?

2

There are 2 best solutions below

0
Gatogordo On

Sitecore will keep track of the time spent for you in the tracker. In Tracker.Current.Interaction you will find the StartDateTime, EndDateTime and even the SaveDateTime if you would need that.

Of course, this measurement is only final when the user ends his visit. So how to handle this information depends on what you actually want to do with it. You say "track", so that is done. The data is in the database..

0
Aleksey Shevchenko On

Concerning how to calculate the user session duration:

Tracker.Current.Session.Interaction.Pages.Sum((Page page) => page.Duration / 1000);

It will return number of seconds.

If your scenario is something like "after user spent 2 minutes on the site we want to show him advertisement" you should use Sitecore rules engine and exactly VisitDuration condition.