Skip to content
Extraits de code Groupes Projets
Valider 2ba74fba rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Add new RequestProcessor to Actions plugin for action detection + new...

Add new RequestProcessor to Actions plugin for action detection + new RequestProcessor for ping request handling. Ping request handling is performed in new Heartbeat plugin. Also added a new method to Plugin, isTrackerPlugin for plugins to override if they are tracker plugins, but don't have a dimension or implement a tracker method.
parent aeb17d59
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -777,6 +777,7 @@ Plugins[] = TestRunner ...@@ -777,6 +777,7 @@ Plugins[] = TestRunner
Plugins[] = BulkTracking Plugins[] = BulkTracking
Plugins[] = Resolution Plugins[] = Resolution
Plugins[] = DevicePlugins Plugins[] = DevicePlugins
Plugins[] = Heartbeat
Plugins[] = Intl Plugins[] = Intl
[PluginsInstalled] [PluginsInstalled]
......
...@@ -450,6 +450,19 @@ class Plugin ...@@ -450,6 +450,19 @@ class Plugin
} }
} }
/**
* Override this method in your plugin class if you want your plugin to be loaded during tracking.
*
* Note: If you define your own dimension or handle a tracker event, your plugin will automatically
* be detected as a tracker plugin.
*
* @return bool
*/
public function isTrackerPlugin()
{
return false;
}
/** /**
* @param $directoryWithinPlugin * @param $directoryWithinPlugin
* @param $expectedSubclass * @param $expectedSubclass
......
...@@ -1102,6 +1102,10 @@ class Manager ...@@ -1102,6 +1102,10 @@ class Manager
return true; return true;
} }
if ($plugin->isTrackerPlugin()) {
return true;
}
return false; return false;
} }
......
...@@ -114,29 +114,16 @@ class Visit implements VisitInterface ...@@ -114,29 +114,16 @@ class Visit implements VisitInterface
/** /**
* Goals & Ecommerce conversions * Goals & Ecommerce conversions
*/ */
$isManualGoalConversion = $requestIsEcommerce = false; /** @var Action $action */
$action = null; $action = $this->visitProperties->getRequestMetadata('Actions', 'action');
$goalManager = null;
if($this->isPingRequest()) { $goalManager = new GoalManager($this->request);
// on a ping request that is received before the standard visit length, we just update the visit time w/o adding a new action $isManualGoalConversion = $goalManager->isManualGoalConversion();
Common::printDebug("-> ping=1 request: we do not track a new action nor a new visit nor any goal."); $requestIsEcommerce = $goalManager->requestIsEcommerce;
$action = null; if (!empty($action)) {
$this->visitProperties->setRequestMetadata('Goals', 'someGoalsConverted', false);
$this->visitProperties->setRequestMetadata('Goals', 'visitIsConverted', false);
} else {
$goalManager = new GoalManager($this->request);
$isManualGoalConversion = $goalManager->isManualGoalConversion();
$requestIsEcommerce = $goalManager->requestIsEcommerce;
if (!$requestIsEcommerce && !$isManualGoalConversion) { if (!$requestIsEcommerce && !$isManualGoalConversion) {
// normal page view, potentially triggering a URL matching goal
$action = Action::factory($this->request);
$action->writeDebugInfo();
$someGoalsConverted = $goalManager->detectGoalsMatchingUrl($this->request->getIdSite(), $action); $someGoalsConverted = $goalManager->detectGoalsMatchingUrl($this->request->getIdSite(), $action);
$this->visitProperties->setRequestMetadata('Goals', 'someGoalsConverted', $someGoalsConverted); $this->visitProperties->setRequestMetadata('Goals', 'someGoalsConverted', $someGoalsConverted);
......
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\Actions\Tracker;
use Piwik\Tracker\Action;
use Piwik\Tracker\Request;
use Piwik\Tracker\RequestProcessor;
use Piwik\Tracker\Visit\VisitProperties;
/**
* TODO
*
* TODO: document request metadata here (ie, 'actions')
*/
class ActionsRequestProcessor extends RequestProcessor
{
public function processRequestParams(VisitProperties $visitProperties, Request $request)
{
// normal page view, potentially triggering a URL matching goal
$action = Action::factory($request);
$action->writeDebugInfo();
$visitProperties->setRequestMetadata('Actions', 'action', $action);
}
}
\ No newline at end of file
<?php
return array(
'tracker.request.processors' => DI\add(array(
DI\get('Piwik\Plugins\Actions\Tracker\ActionsRequestProcessor'),
)),
);
...@@ -29,6 +29,8 @@ class EcommerceRequestProcessor extends RequestProcessor ...@@ -29,6 +29,8 @@ class EcommerceRequestProcessor extends RequestProcessor
if ($goalManager->isGoalAnOrder()) { if ($goalManager->isGoalAnOrder()) {
$visitProperties->setRequestMetadata('Goals', 'visitIsConverted', true); $visitProperties->setRequestMetadata('Goals', 'visitIsConverted', true);
} }
$visitProperties->setRequestMetadata('Actions', 'action', null); // don't track actions when tracking ecommerce orders
} }
} }
} }
\ No newline at end of file
...@@ -32,6 +32,8 @@ class GoalsRequestProcessor extends RequestProcessor ...@@ -32,6 +32,8 @@ class GoalsRequestProcessor extends RequestProcessor
$visitProperties->setRequestMetadata('Goals', 'someGoalsConverted', $someGoalsConverted); $visitProperties->setRequestMetadata('Goals', 'someGoalsConverted', $someGoalsConverted);
$visitProperties->setRequestMetadata('Goals', 'visitIsConverted', $someGoalsConverted); $visitProperties->setRequestMetadata('Goals', 'visitIsConverted', $someGoalsConverted);
$visitProperties->setRequestMetadata('Actions', 'action', null); // don't track actions when doing manual goal conversions
// if we find a idgoal in the URL, but then the goal is not valid, this is most likely a fake request // if we find a idgoal in the URL, but then the goal is not valid, this is most likely a fake request
if (!$someGoalsConverted) { if (!$someGoalsConverted) {
Common::printDebug('Invalid goal tracking request for goal id = ' . $goalManager->idGoal); Common::printDebug('Invalid goal tracking request for goal id = ' . $goalManager->idGoal);
......
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\Heartbeat;
use Piwik\Plugin;
class Heartbeat extends Plugin
{
public function isTrackerPlugin()
{
return true;
}
}
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\Heartbeat\Tracker;
use Piwik\Common;
use Piwik\Tracker\Request;
use Piwik\Tracker\RequestProcessor;
use Piwik\Tracker\Visit\VisitProperties;
/**
* TODO
*/
class PingRequestProcessor extends RequestProcessor
{
public function processRequestParams(VisitProperties $visitProperties, Request $request)
{
if ($this->isPingRequest($request)) {
// on a ping request that is received before the standard visit length, we just update the visit time w/o adding a new action
Common::printDebug("-> ping=1 request: we do not track a new action nor a new visit nor any goal.");
$visitProperties->setRequestMetadata('Actions', 'action', null);
$visitProperties->setRequestMetadata('Goals', 'someGoalsConverted', false);
$visitProperties->setRequestMetadata('Goals', 'visitIsConverted', false);
}
}
private function isPingRequest(Request $request)
{
return $request->getParam('ping') == 1;
}
}
\ No newline at end of file
<?php
return array(
'tracker.request.processors' => DI\add(array(
DI\get('Piwik\Plugins\Heartbeat\Tracker\PingRequestProcessor'),
)),
);
{
"description": "Handles ping tracker requests."
}
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter