Skip to content

Commit

Permalink
Fixes #3803
Browse files Browse the repository at this point in the history
New config setting for tracker:

; The window to look back for a previous visit by this current visitor. Defaults to visit_standard_length.
; If you are looking for higher accuracy of "returning visitors" metrics, you may set this value to 86400 or more.
; This is especially useful when you use the Tracking API where tracking Returning Visitors often depends on this setting.
; The value window_look_back_for_visitor is used only if it is set to greater than visit_standard_length
window_look_back_for_visitor = 0
  • Loading branch information
mattab committed Mar 8, 2013
1 parent 62402bd commit b089eac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions config/global.ini.php
Expand Up @@ -356,6 +356,12 @@
; after his last page view, it will be recorded as a new visit
visit_standard_length = 1800

; The window to look back for a previous visit by this current visitor. Defaults to visit_standard_length.
; If you are looking for higher accuracy of "returning visitors" metrics, you may set this value to 86400 or more.
; This is especially useful when you use the Tracking API where tracking Returning Visitors often depends on this setting.
; The value window_look_back_for_visitor is used only if it is set to greater than visit_standard_length
window_look_back_for_visitor = 0

; visitors that stay on the website and view only one page will be considered as time on site of 0 second
default_time_one_page_visit = 0

Expand Down
25 changes: 23 additions & 2 deletions core/Tracker/Visit.php
Expand Up @@ -1169,8 +1169,9 @@ protected function recognizeTheVisitor()
$from = "FROM ".Piwik_Common::prefixTable('log_visit');

$bindSql = array();

$timeLookBack = date('Y-m-d H:i:s', $this->getCurrentTimestamp() - Piwik_Config::getInstance()->Tracker['visit_standard_length']);


$timeLookBack = $this->getWindowLookupPreviousVisit();

$shouldMatchOneFieldOnly = $this->shouldLookupOneVisitorFieldOnly($isVisitorIdToLookup);

Expand Down Expand Up @@ -1313,6 +1314,26 @@ protected function recognizeTheVisitor()
}
}

/**
* By default, we look back 30 minutes to find a previous visitor (for performance reasons).
* In some cases, it is useful to look back and count unique visitors more accurately. You can set custom lookback window in
* [Tracker] window_look_back_for_visitor
*
* @return string
*
*/
protected function getWindowLookupPreviousVisit()
{
$lookbackNSeconds = Piwik_Config::getInstance()->Tracker['visit_standard_length'];

$lookbackNSecondsCustom = Piwik_Config::getInstance()->Tracker['window_look_back_for_visitor'];
if ($lookbackNSecondsCustom > $lookbackNSeconds) {
$lookbackNSeconds = $lookbackNSecondsCustom;
}
$timeLookBack = date('Y-m-d H:i:s', $this->getCurrentTimestamp() - $lookbackNSeconds);
return $timeLookBack;
}

protected function shouldLookupOneVisitorFieldOnly($isVisitorIdToLookup)
{
// This setting would be enabled for Intranet websites, to ensure that visitors using all the same computer config, same IP
Expand Down

0 comments on commit b089eac

Please sign in to comment.