Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattpiwik <matthieu.aubry@gmail.com>2007-08-07 15:56:25 +0400
committermattpiwik <matthieu.aubry@gmail.com>2007-08-07 15:56:25 +0400
commitd94998d4b6ea972c4dd4f4ecf95972f89662a886 (patch)
treebd14a1b1a3f0ba2066098a316abc85b6faac2e6d /modules/LogStats.php
parent9b49c4bb488ce375972001fca03b39eb0c76a8b9 (diff)
Improved the script for visits generation => now handles partner/newsletter/campaign generation, and also download/outlink fake generation.
Update config file with documentation. git-svn-id: http://dev.piwik.org/svn/trunk@29 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'modules/LogStats.php')
-rw-r--r--modules/LogStats.php89
1 files changed, 58 insertions, 31 deletions
diff --git a/modules/LogStats.php b/modules/LogStats.php
index 753e70dbef..711e780375 100644
--- a/modules/LogStats.php
+++ b/modules/LogStats.php
@@ -565,14 +565,13 @@ class Piwik_LogStats_Action
array($idVisit, $this->idAction, $idRefererAction, $timeSpentRefererAction)
);
}
-
}
class Piwik_LogStats_Visit
{
- private $cookieLog = null;
- private $visitorInfo = array();
- private $userSettingsInformation = null;
+ protected $cookieLog = null;
+ protected $visitorInfo = array();
+ protected $userSettingsInformation = null;
function __construct( $db )
{
@@ -587,6 +586,23 @@ class Piwik_LogStats_Visit
$this->idsite = $idsite;
}
+ protected function getCurrentDate( $format = "Y-m-d")
+ {
+ return date($format, $this->getCurrentTimestamp() );
+ }
+
+ protected function getCurrentTimestamp()
+ {
+ return time();
+ }
+
+ protected function getDatetimeFromTimestamp($timestamp)
+ {
+ return date("Y-m-d H:i:s",$timestamp);
+ }
+
+
+
// test if the visitor is excluded because of
// - IP
// - cookie
@@ -609,6 +625,7 @@ class Piwik_LogStats_Visit
return Piwik_LogStats_Config::getInstance()->LogStats['cookie_name'] . $this->idsite;
}
+
/**
* This methods tries to see if the visitor has visited the website before.
*
@@ -648,12 +665,12 @@ class Piwik_LogStats_Visit
* We make sure all the data that should saved in the cookie is available.
*/
- if( false !== ($idVisitor = $this->cookieLog->get( Piwik_LogStats::COOKIE_INDEX_IDVISITOR )) )
+ if( false !== ($idVisitor = $this->cookieLog->get( Piwik_LogStats_Controller::COOKIE_INDEX_IDVISITOR )) )
{
- $timestampLastAction = $this->cookieLog->get( Piwik_LogStats::COOKIE_INDEX_TIMESTAMP_LAST_ACTION );
- $timestampFirstAction = $this->cookieLog->get( Piwik_LogStats::COOKIE_INDEX_TIMESTAMP_FIRST_ACTION );
- $idVisit = $this->cookieLog->get( Piwik_LogStats::COOKIE_INDEX_ID_VISIT );
- $idLastAction = $this->cookieLog->get( Piwik_LogStats::COOKIE_INDEX_ID_LAST_ACTION );
+ $timestampLastAction = $this->cookieLog->get( Piwik_LogStats_Controller::COOKIE_INDEX_TIMESTAMP_LAST_ACTION );
+ $timestampFirstAction = $this->cookieLog->get( Piwik_LogStats_Controller::COOKIE_INDEX_TIMESTAMP_FIRST_ACTION );
+ $idVisit = $this->cookieLog->get( Piwik_LogStats_Controller::COOKIE_INDEX_ID_VISIT );
+ $idLastAction = $this->cookieLog->get( Piwik_LogStats_Controller::COOKIE_INDEX_ID_LAST_ACTION );
if( $timestampLastAction !== false && is_numeric($timestampLastAction)
&& $timestampFirstAction !== false && is_numeric($timestampFirstAction)
@@ -694,7 +711,7 @@ class Piwik_LogStats_Visit
AND config_md5config = ?
ORDER BY visit_last_action_time DESC
LIMIT 1",
- array( date("Y-m-d"), $this->idsite, $md5Config));
+ array( $this->getCurrentDate(), $this->idsite, $md5Config));
if($visitRow
&& count($visitRow) > 0)
{
@@ -793,7 +810,8 @@ class Piwik_LogStats_Visit
*/
private function isLastActionInTheSameVisit()
{
- return $this->visitorInfo['visit_last_action_time'] >= time() - Piwik_LogStats::VISIT_STANDARD_LENGTH;
+ return $this->visitorInfo['visit_last_action_time']
+ >= ($this->getCurrentTimestamp() - Piwik_LogStats_Controller::VISIT_STANDARD_LENGTH);
}
private function isVisitorKnown()
@@ -831,53 +849,57 @@ class Piwik_LogStats_Visit
// known visitor
if($this->isVisitorKnown())
{
+ // the same visit is going on
if($this->isLastActionInTheSameVisit())
{
$this->handleKnownVisit();
}
+ // new visit
else
{
$this->handleNewVisit();
}
}
- // new visitor
+ // new visitor => new visit
else
{
$this->handleNewVisit();
}
+ // we update the cookie with the new visit information
$this->updateCookie();
}
}
-
+
private function updateCookie()
{
printDebug("We manage the cookie...");
// idcookie has been generated in handleNewVisit or we simply propagate the old value
- $this->cookieLog->set( Piwik_LogStats::COOKIE_INDEX_IDVISITOR,
+ $this->cookieLog->set( Piwik_LogStats_Controller::COOKIE_INDEX_IDVISITOR,
$this->visitorInfo['visitor_idcookie'] );
// the last action timestamp is the current timestamp
- $this->cookieLog->set( Piwik_LogStats::COOKIE_INDEX_TIMESTAMP_LAST_ACTION,
+ $this->cookieLog->set( Piwik_LogStats_Controller::COOKIE_INDEX_TIMESTAMP_LAST_ACTION,
$this->visitorInfo['visit_last_action_time'] );
// the first action timestamp is the timestamp of the first action of the current visit
- $this->cookieLog->set( Piwik_LogStats::COOKIE_INDEX_TIMESTAMP_FIRST_ACTION,
+ $this->cookieLog->set( Piwik_LogStats_Controller::COOKIE_INDEX_TIMESTAMP_FIRST_ACTION,
$this->visitorInfo['visit_first_action_time'] );
// the idvisit has been generated by mysql in handleNewVisit or simply propagated here
- $this->cookieLog->set( Piwik_LogStats::COOKIE_INDEX_ID_VISIT,
+ $this->cookieLog->set( Piwik_LogStats_Controller::COOKIE_INDEX_ID_VISIT,
$this->visitorInfo['idvisit'] );
// the last action ID is the current exit idaction
- $this->cookieLog->set( Piwik_LogStats::COOKIE_INDEX_ID_LAST_ACTION,
+ $this->cookieLog->set( Piwik_LogStats_Controller::COOKIE_INDEX_ID_LAST_ACTION,
$this->visitorInfo['visit_exit_idaction'] );
$this->cookieLog->save();
}
+
/**
* In the case of a known visit, we have to do the following actions:
*
@@ -898,8 +920,8 @@ class Piwik_LogStats_Visit
printDebug("idAction = $actionId");
- $serverTime = time();
- $datetimeServer = Piwik_Common::getDatetimeFromTimestamp($serverTime);
+ $serverTime = $this->getCurrentTimestamp();
+ $datetimeServer = $this->getDatetimeFromTimestamp($serverTime);
$this->db->query("UPDATE ". $this->db->prefixTable('log_visit')."
SET visit_last_action_time = ?,
@@ -951,11 +973,11 @@ class Piwik_LogStats_Visit
$userInfo = $this->getUserSettingsInformation();
// General information
- $localTime = Piwik_Common::getRequestVar( 'h', date("H"), 'numeric')
- .':'. Piwik_Common::getRequestVar( 'm', date("i"), 'numeric')
- .':'. Piwik_Common::getRequestVar( 's', date("s"), 'numeric');
- $serverDate = date("Y-m-d");
- $serverTime = time();
+ $localTime = Piwik_Common::getRequestVar( 'h', $this->getCurrentDate("H"), 'numeric')
+ .':'. Piwik_Common::getRequestVar( 'm', $this->getCurrentDate("i"), 'numeric')
+ .':'. Piwik_Common::getRequestVar( 's', $this->getCurrentDate("s"), 'numeric');
+ $serverDate = $this->getCurrentDate();
+ $serverTime = $this->getCurrentTimestamp();
if($this->isVisitorKnown())
{
@@ -996,8 +1018,8 @@ class Piwik_LogStats_Visit
'visitor_localtime' => $localTime,
'visitor_idcookie' => $idcookie,
'visitor_returning' => $returningVisitor,
- 'visit_first_action_time' => Piwik_Common::getDatetimeFromTimestamp($serverTime),
- 'visit_last_action_time' => Piwik_Common::getDatetimeFromTimestamp($serverTime),
+ 'visit_first_action_time' => $this->getDatetimeFromTimestamp($serverTime),
+ 'visit_last_action_time' => $this->getDatetimeFromTimestamp($serverTime),
'visit_server_date' => $serverDate,
'visit_entry_idaction' => $actionId,
'visit_exit_idaction' => $actionId,
@@ -1292,7 +1314,7 @@ class Piwik_LogStats_Visit
}
-class Piwik_LogStats
+class Piwik_LogStats_Controller
{
private $stateValid;
@@ -1389,14 +1411,14 @@ class Piwik_LogStats
// main algorithm
// => input : variables filtered
// => action : read cookie, read database, database logging, cookie writing
- function main()
+ function main( $class_LogStats_Visit = "Piwik_LogStats_Visit")
{
$this->initProcess();
if( $this->processVisit() )
{
$this->connectDatabase();
- $visit = new Piwik_LogStats_Visit( $this->db );
+ $visit = new $class_LogStats_Visit( $this->db );
$visit->handle();
}
$this->endProcess();
@@ -1420,7 +1442,7 @@ class Piwik_LogStats
case self::STATE_TO_REDIRECT_URL:
- header('Location: ' . $this->getUrlToRedirect());
+ $this->sendHeader('Location: ' . $this->getUrlToRedirect());
break;
@@ -1431,6 +1453,11 @@ class Piwik_LogStats
}
printDebug("End of the page.");
}
+
+ protected function sendHeader($header)
+ {
+ header($header);
+ }
}