
function TimeSpentTracker() {
var PING_URL = '/app/reporting/ping/5a2077b95116ca5cc7b08077';
var SECOND = 1000; var MINUTE = SECOND * 60; var HOUR = MINUTE * 60;
var INITIAL_TIME_INTERVAL = 5 * SECOND; var MAX_TRACKING_TIME_LIMIT = 2 * HOUR;
this.pingTimerId; this.pingTimeInterval = INITIAL_TIME_INTERVAL;
this.start = function () { this.ping(); this.runPingLoop() };
this.stop = function () { window.clearInterval(this.pingTimerId); };
this.runPingLoop = function () { var self = this; this.pingTimerId = window.setTimeout(function () { self.ping() }, this.pingTimeInterval); };
this.ping = function () { this.pingServer(); if (this.timeLimitReached()) { this.stop(); } else { this.incrementPingTimeInterval(); this.runPingLoop(); } };
this.timeLimitReached = function () { return this.pingTimeInterval > MAX_TRACKING_TIME_LIMIT; };
/** * 2X time : from 5 sec to 10 min (5, 10, 20, 40, 80, 160, ...) * +10 min : from 10 min to 1 hour * +15 min : from 1 hour to MAX_TRACKING_TIME_LIMIT */ this.incrementPingTimeInterval = function () { if (this.pingTimeInterval >= 10 * MINUTE) { this.pingTimeInterval += 10 * MINUTE; } else if (this.pingTimeInterval >= HOUR) { this.pingTimeInterval += 15 * MINUTE; } else { this.pingTimeInterval *= 2; } };
this.pingServer = function () { var beaconPixel = new Image(); // We use a timestamp to invalidate image cache var timestamp = new Date().getTime(); // Setting the Image.src hits the server beaconPixel.src = PING_URL + '?timestamp=' + timestamp; }; }
try { window.__smoreTimeTracker = new TimeSpentTracker(); window.__smoreTimeTracker.start(); } catch (e) { if (window.addEventListener) { window.addEventListener('time-spent-tracking:stop', function () { window.__smoreTimeTracker.stop(); }); } }
window.pageId = '5a2077b95116ca5cc7b08077'; window.__pageLongKey = '' window.__isSuggestedFlyer = false

