Skip to content
Extraits de code Groupes Projets
Valider 1600e344 rédigé par mattab's avatar mattab
Parcourir les fichiers

Fixes #5123 PHP Tracker, added new method setForceNewVisit() to force...

Fixes  #5123 PHP Tracker, added new method setForceNewVisit() to force creation of a new visit + with test

Close https://github.com/piwik/piwik/pull/218
parent 7e617f1b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -170,6 +170,7 @@ class PiwikTracker ...@@ -170,6 +170,7 @@ class PiwikTracker
$this->eventCustomVar = false; $this->eventCustomVar = false;
$this->customData = false; $this->customData = false;
$this->forcedDatetime = false; $this->forcedDatetime = false;
$this->forcedNewVisit = false;
$this->token_auth = false; $this->token_auth = false;
$this->attributionInfo = false; $this->attributionInfo = false;
$this->ecommerceLastOrderTimestamp = false; $this->ecommerceLastOrderTimestamp = false;
...@@ -902,6 +903,21 @@ class PiwikTracker ...@@ -902,6 +903,21 @@ class PiwikTracker
$this->forcedDatetime = $dateTime; $this->forcedDatetime = $dateTime;
} }
/**
* Forces Piwik to create a new visit for the tracking request.
*
* By default, Piwik will create a new visit if the last request by this user was more than 30 minutes ago.
* If you call setForceNewVisit() before calling doTrack*, then a new visit will be created for this request.
*
* Allowed only for Super User, must be used along with setTokenAuth()
*
* @see setTokenAuth()
*/
public function setForceNewVisit()
{
$this->forcedNewVisit = true;
}
/** /**
* Overrides IP address * Overrides IP address
* *
...@@ -1274,6 +1290,7 @@ class PiwikTracker ...@@ -1274,6 +1290,7 @@ class PiwikTracker
(!empty($this->ip) ? '&cip=' . $this->ip : '') . (!empty($this->ip) ? '&cip=' . $this->ip : '') .
(!empty($this->forcedVisitorId) ? '&cid=' . $this->forcedVisitorId : '&_id=' . $this->getVisitorId()) . (!empty($this->forcedVisitorId) ? '&cid=' . $this->forcedVisitorId : '&_id=' . $this->getVisitorId()) .
(!empty($this->forcedDatetime) ? '&cdt=' . urlencode($this->forcedDatetime) : '') . (!empty($this->forcedDatetime) ? '&cdt=' . urlencode($this->forcedDatetime) : '') .
(!empty($this->forcedNewVisit) ? '&new_visit=1' : '') .
((!empty($this->token_auth) && !$this->doBulkRequests) ? '&token_auth=' . urlencode($this->token_auth) : '') . ((!empty($this->token_auth) && !$this->doBulkRequests) ? '&token_auth=' . urlencode($this->token_auth) : '') .
// Values collected from cookie // Values collected from cookie
...@@ -1324,6 +1341,9 @@ class PiwikTracker ...@@ -1324,6 +1341,9 @@ class PiwikTracker
$this->pageCustomVar = false; $this->pageCustomVar = false;
$this->eventCustomVar = false; $this->eventCustomVar = false;
// force new visit only once, user must call again setForceNewVisit()
$this->forcedNewVisit = false;
return $url; return $url;
} }
......
...@@ -84,5 +84,11 @@ class Piwik_Test_Fixture_SomeVisitsAllConversions extends Fixture ...@@ -84,5 +84,11 @@ class Piwik_Test_Fixture_SomeVisitsAllConversions extends Fixture
// 1st goal should Now be tracked // 1st goal should Now be tracked
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.61)->getDatetime()); $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.61)->getDatetime());
self::checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 656)); self::checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 656));
// few minutes later, create a new_visit
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.7)->getDatetime());
$t->setTokenAuth($this->getTokenAuth());
$t->setForceNewVisit();
$t->doTrackPageView('This is tracked in a new visit.');
} }
} }
...@@ -43,7 +43,10 @@ class Test_Piwik_Integration_TrackGoals_AllowMultipleConversionsPerVisit extends ...@@ -43,7 +43,10 @@ class Test_Piwik_Integration_TrackGoals_AllowMultipleConversionsPerVisit extends
public function getApiForTesting() public function getApiForTesting()
{ {
$apiToCall = array('VisitTime.getVisitInformationPerServerTime', 'VisitsSummary.get'); $apiToCall = array(
'VisitTime.getVisitInformationPerServerTime',
'VisitsSummary.get'
);
return array( return array(
array($apiToCall, array('idSite' => self::$fixture->idSite, 'date' => self::$fixture->dateTime)) array($apiToCall, array('idSite' => self::$fixture->idSite, 'date' => self::$fixture->dateTime))
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
<row> <row>
<label>0h</label> <label>0h</label>
<nb_uniq_visitors>1</nb_uniq_visitors> <nb_uniq_visitors>1</nb_uniq_visitors>
<nb_visits>1</nb_visits> <nb_visits>2</nb_visits>
<nb_actions>1</nb_actions> <nb_actions>2</nb_actions>
<max_actions>1</max_actions> <max_actions>1</max_actions>
<sum_visit_length>1120</sum_visit_length> <sum_visit_length>1120</sum_visit_length>
<bounce_count>1</bounce_count> <bounce_count>2</bounce_count>
<goals> <goals>
<row idgoal='1'> <row idgoal='1'>
<nb_conversions>2</nb_conversions> <nb_conversions>2</nb_conversions>
......
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<result> <result>
<nb_uniq_visitors>1</nb_uniq_visitors> <nb_uniq_visitors>1</nb_uniq_visitors>
<nb_visits>1</nb_visits> <nb_visits>2</nb_visits>
<nb_actions>1</nb_actions> <nb_actions>2</nb_actions>
<nb_visits_converted>1</nb_visits_converted> <nb_visits_converted>1</nb_visits_converted>
<bounce_count>1</bounce_count> <bounce_count>2</bounce_count>
<sum_visit_length>1120</sum_visit_length> <sum_visit_length>1120</sum_visit_length>
<max_actions>1</max_actions> <max_actions>1</max_actions>
<bounce_rate>100%</bounce_rate> <bounce_rate>100%</bounce_rate>
<nb_actions_per_visit>1</nb_actions_per_visit> <nb_actions_per_visit>1</nb_actions_per_visit>
<avg_time_on_site>1120</avg_time_on_site> <avg_time_on_site>560</avg_time_on_site>
</result> </result>
\ No newline at end of file
Subproject commit 579b7c4c928800115d35e6474e0c43c29a8e1c97 Subproject commit 8c15feb00dd40880d1872680cb84b330fd56c6ff
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter