common-web
common-web copied to clipboard
Track time on page
Under the assumption that CommonWeb is loaded at the initial page load, and not loaded dynamically, we should be able to tell how long the user has been on the page when a certain event hits.
Yes! Could see a few variants here: time_since_page_load, time_since_session_start, time_since_last_event, etc. I don't think we have to go overboard, just throwing out a few possibilities :)
On Fri, Mar 6, 2015 at 1:55 PM, Joe Wegner [email protected] wrote:
Under the assumption that CommonWeb is loaded at the initial page load, and not loaded dynamically, we should be able to tell how long the user has been on the page when a certain event hits.
Reply to this email directly or view it on GitHub: https://github.com/keen/common-web/issues/17
@josephwegner what do you think about a timer utility with start/pause/resume methods? You could register and manage various timers, toggle them on/off based on window or user events, and pull their value out in various formats.
pseudo code:
var totalTime = new Timer().start();
var activeTime = new Timer().start();
// window loses focus:
activeTime.pause();
// window regains focus
activeTime.resume();
console.log("Active: " + activeTime.total() + " of " totalTime.total() + "seconds");
Hah - I'm having a hard time believing that's not already a common part of a library somewhere. It seems so obviously useful. But, somehow I'm not finding it. Clearly you're a genius.
I'm trying to relate that concept into analytics and CommonWeb.. what do you think of:
var timeSinceLoad = new CommonWeb.timer('since_load').start();
var timeSinceNavClick = new CommonWeb.timer('since_nav_click').start();
var timeUntilScroll = new CommonWeb.timer('time_to_scroll').start();
// Resets timer to 0 whenever a nav item is clicked
timeSinceNavClick.resetOn('click', 'li.nav-item', [optional callback])
// Freezes the timer after the user starts scrolling
timeUntilScroll.stopOn('scroll', [optional callback])
And then any event tracked with CommonWeb would automatically populate a timers object:
{
...
"timers": {
"since_load": 19238,
"since_nav_click": 13765,
"time_to_scroll": 739
},
...
}
That's a really cool interface for this! That timers object would be it super easy to include values when an event is sent.. or to just include them all by default. Really like the ease of access :+1:
:+1: Definitely Something that should exist.
@tankerkiller125 this now exists in keen-tracking.js :) https://github.com/keen/keen-tracking.js#timers