diff options
author | diosmosis <benaka@piwik.pro> | 2015-10-19 02:30:54 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-10-19 02:30:54 +0300 |
commit | ddfb2863dee378b37a84bc75d1a4d8f2289426e8 (patch) | |
tree | 250924e269f6dd5438b672b17f1586a2a24a2329 /core | |
parent | f1580505636149bec159af2f02fa101daac9e675 (diff) |
Add new method to RequestProcessor called before the request is processed, manipulateRequest(). Allows plugins to change the request before it is processed.
Diffstat (limited to 'core')
-rw-r--r-- | core/Tracker/RequestProcessor.php | 24 | ||||
-rw-r--r-- | core/Tracker/Visit.php | 6 |
2 files changed, 26 insertions, 4 deletions
diff --git a/core/Tracker/RequestProcessor.php b/core/Tracker/RequestProcessor.php index e96ae36be6..3a8b01549a 100644 --- a/core/Tracker/RequestProcessor.php +++ b/core/Tracker/RequestProcessor.php @@ -35,12 +35,15 @@ use Piwik\Tracker\Visit\VisitProperties; * When Piwik handles a single tracking request, it gathers all available RequestProcessors and * 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. * An example includes the ActionRequestProcessor, which uses this method to determine the action * 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' * 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 @@ -48,7 +51,7 @@ use Piwik\Tracker\Visit\VisitProperties; * conversions. An example of the latter can be seen in the PingRequestProcessor, which on * 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, * however sometimes it is not possible (as is the case with the CustomVariables plugin). * @@ -83,6 +86,19 @@ abstract class RequestProcessor /** * 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 * request alone. They should not try to access request metadata from other plugins, * since they may not be set yet. @@ -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 * from other plugins, or to override request metadata from other plugins to change diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php index 84b702449e..a78bb30b40 100644 --- a/core/Tracker/Visit.php +++ b/core/Tracker/Visit.php @@ -113,6 +113,12 @@ class Visit implements VisitInterface */ public function handle() { + foreach ($this->requestProcessors as $processor) { + Common::printDebug("Executing " . get_class($processor) . "::manipulateRequest()..."); + + $processor->manipulateRequest($this->request); + } + $this->visitProperties = new VisitProperties(); foreach ($this->requestProcessors as $processor) { |