Skip to content
Extraits de code Groupes Projets
Valider 85e52d5c rédigé par Matthieu Aubry's avatar Matthieu Aubry
Parcourir les fichiers

Merge pull request #9045 from piwik/request_processor_change

Allow tracker requests to be manipulated before handled
parents f1580505 65526f32
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -394,6 +394,12 @@ class Request ...@@ -394,6 +394,12 @@ class Request
return $this->paramsCache[$name]; return $this->paramsCache[$name];
} }
public function setParam($name, $value)
{
$this->params[$name] = $value;
unset($this->paramsCache[$name]);
}
private function hasParam($name) private function hasParam($name)
{ {
return isset($this->params[$name]); return isset($this->params[$name]);
......
...@@ -35,12 +35,15 @@ use Piwik\Tracker\Visit\VisitProperties; ...@@ -35,12 +35,15 @@ use Piwik\Tracker\Visit\VisitProperties;
* When Piwik handles a single tracking request, it gathers all available RequestProcessors and * When Piwik handles a single tracking request, it gathers all available RequestProcessors and
* invokes their methods in sequence. * invokes their methods in sequence.
* *
* The first method called is {@link self::processRequestParams()}. RequestProcessors should use * The first method called is {@link self::manipulateRequest()}. By default this is a no-op, but
* RequestProcessors can use it to manipulate tracker requests before they are processed.
*
* The second method called is {@link self::processRequestParams()}. RequestProcessors should use
* this method to compute request metadata and set visit properties using the tracking request. * this method to compute request metadata and set visit properties using the tracking request.
* An example includes the ActionRequestProcessor, which uses this method to determine the action * An example includes the ActionRequestProcessor, which uses this method to determine the action
* being tracked. * being tracked.
* *
* The second method called is {@link self::afterRequestProcessed()}. RequestProcessors should * The third method called is {@link self::afterRequestProcessed()}. RequestProcessors should
* use this method to either compute request metadata/visit properties using other plugins' * use this method to either compute request metadata/visit properties using other plugins'
* request metadata, OR override other plugins' request metadata to tweak tracker behavior. * request metadata, OR override other plugins' request metadata to tweak tracker behavior.
* An example of the former can be seen in the GoalsRequestProcessor which uses the action * An example of the former can be seen in the GoalsRequestProcessor which uses the action
...@@ -48,7 +51,7 @@ use Piwik\Tracker\Visit\VisitProperties; ...@@ -48,7 +51,7 @@ use Piwik\Tracker\Visit\VisitProperties;
* conversions. An example of the latter can be seen in the PingRequestProcessor, which on * conversions. An example of the latter can be seen in the PingRequestProcessor, which on
* ping requests, aborts conversion recording and new visit recording. * ping requests, aborts conversion recording and new visit recording.
* *
* After these two methods are called, either {@link self::onNewVisit()} or {@link self::onExistingVisit()} * After these methods are called, either {@link self::onNewVisit()} or {@link self::onExistingVisit()}
* is called. Generally, plugins should favor defining Dimension classes instead of using these methods, * is called. Generally, plugins should favor defining Dimension classes instead of using these methods,
* however sometimes it is not possible (as is the case with the CustomVariables plugin). * however sometimes it is not possible (as is the case with the CustomVariables plugin).
* *
...@@ -83,6 +86,19 @@ abstract class RequestProcessor ...@@ -83,6 +86,19 @@ abstract class RequestProcessor
/** /**
* This is the first method called when processing a tracker request. * This is the first method called when processing a tracker request.
* *
* Derived classes can use this method to manipulate a tracker request before the request
* is handled. Plugins could change the URL, add custom variables, etc.
*
* @param Request $request
*/
public function manipulateRequest(Request $request)
{
// empty
}
/**
* This is the second method called when processing a tracker request.
*
* Derived classes should use this method to set request metadata based on the tracking * Derived classes should use this method to set request metadata based on the tracking
* request alone. They should not try to access request metadata from other plugins, * request alone. They should not try to access request metadata from other plugins,
* since they may not be set yet. * since they may not be set yet.
...@@ -99,7 +115,7 @@ abstract class RequestProcessor ...@@ -99,7 +115,7 @@ abstract class RequestProcessor
} }
/** /**
* This is the second method called when processing a tracker request. * This is the third method called when processing a tracker request.
* *
* Derived classes should use this method to set request metadata that needs request metadata * Derived classes should use this method to set request metadata that needs request metadata
* from other plugins, or to override request metadata from other plugins to change * from other plugins, or to override request metadata from other plugins to change
......
...@@ -113,6 +113,12 @@ class Visit implements VisitInterface ...@@ -113,6 +113,12 @@ class Visit implements VisitInterface
*/ */
public function handle() public function handle()
{ {
foreach ($this->requestProcessors as $processor) {
Common::printDebug("Executing " . get_class($processor) . "::manipulateRequest()...");
$processor->manipulateRequest($this->request);
}
$this->visitProperties = new VisitProperties(); $this->visitProperties = new VisitProperties();
foreach ($this->requestProcessors as $processor) { foreach ($this->requestProcessors as $processor) {
......
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