From fe4ee5dd88542796c29dd0a246eeb301f5488b3d Mon Sep 17 00:00:00 2001 From: mattab Date: Mon, 28 Oct 2013 18:22:19 +1300 Subject: Fixes #4248 this should help with making segments visitCount and daysSinceLastVisit more accurate! --- js/piwik.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/piwik.js b/js/piwik.js index 10da96ea67..88a9f19bfb 100644 --- a/js/piwik.js +++ b/js/piwik.js @@ -1614,7 +1614,6 @@ if (typeof Piwik !== 'object') { visitCount = id[3]; currentVisitTs = id[4]; lastVisitTs = id[5]; - // case migrating from pre-1.5 cookies if (!isDefined(id[6])) { id[6] = ""; @@ -1641,10 +1640,18 @@ if (typeof Piwik !== 'object') { referralUrl = attributionCookie[3]; if (!ses) { - // new session (aka new visit) - visitCount++; + // cookie 'ses' was not found: we consider this the start of a 'session' + + // here we make sure that if 'ses' cookie is deleted few times within the visit + // and so this code path is triggered many times for one visit, + // we only increase visitCount once per Visit window (default 30min) + var visitDuration = configSessionCookieTimeout / 1000; + if (!lastVisitTs + || (nowTs - lastVisitTs) > visitDuration) { + visitCount++; + lastVisitTs = currentVisitTs; + } - lastVisitTs = currentVisitTs; // Detect the campaign information from the current URL // Only if campaign wasn't previously set -- cgit v1.2.3