Using google analytics user timings api to track the Page Usage ( Time to track how long the user stays on the Specific Page ). Have achieved the following by using the Logic.
Initialize the start Time when user navigate to Page ( Eg. User Details Page )
document.onreadystatechange = function () { var startUserTrackTime = new Date(); }
User will fill up few data ( Name , Email, Age ) FYI - No post back / no operations performed as simple as that.
User navigate to other pages ( Have to Track the time now )
window.onunload = function () { trackPageUsage(); } function trackPageUsage() { if (startUserTrackTime) { ga('send', { timingCategory: 'xx', timingVar: 'xx', timingValue: new Date().getTime() - startUserTrackTime.getTime(), timingLabel: 'xxx' }); } }
Few doubts points are :
Considering the user stays for 10 minutes on ( User Details Page ). Will the code work to get correct milliseconds :
timingValue: new Date().getTime() - startUserTrackTime.getTime()
Is the approach taken to track time for specific page is correct or possible fault is seen.
I don't want to use the Performance API ( Does not suit my requirement )