diff options
author | diosmosis <benaka@piwik.pro> | 2015-07-07 04:53:42 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-08-06 17:37:57 +0300 |
commit | 7d8ae6adf53851fea1714bdc174390bcaac498e3 (patch) | |
tree | 535e03873a1627dc792241b1c8f3df9ab091ab25 /plugins | |
parent | 08f113d9c4edae6182bfd458e63016f49a7dd024 (diff) |
Add initial RequestProcessor base + DI entry + use in Visit::handle(). Moving some core visit handling logic to a new RequestProcessor in CoreHome plugin.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/CoreHome/Tracker/VisitRequestProcessor.php | 58 | ||||
-rw-r--r-- | plugins/CoreHome/config/config.php | 9 |
2 files changed, 67 insertions, 0 deletions
diff --git a/plugins/CoreHome/Tracker/VisitRequestProcessor.php b/plugins/CoreHome/Tracker/VisitRequestProcessor.php new file mode 100644 index 0000000000..513b78b54a --- /dev/null +++ b/plugins/CoreHome/Tracker/VisitRequestProcessor.php @@ -0,0 +1,58 @@ +<?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\CoreHome\Tracker; + +use Piwik\EventDispatcher; +use Piwik\Tracker\Request; +use Piwik\Tracker\RequestProcessor; +use Piwik\Tracker\Visit\VisitProperties; +use Piwik\Tracker\VisitExcluded; + +/** + * Encapsulates core tracking logic related to visits. + */ +class VisitRequestProcessor extends RequestProcessor +{ + /** + * @var EventDispatcher + */ + private $eventDispatcher; + + public function __construct(EventDispatcher $eventDispatcher) + { + $this->eventDispatcher = $eventDispatcher; + } + + public function processRequestParams(VisitProperties $visitProperties, Request $request) + { + // the IP is needed by isExcluded() and GoalManager->recordGoals() + $visitProperties->visitorInfo['location_ip'] = $request->getIp(); + + // TODO: move VisitExcluded logic to here (or break into other request processors) + $excluded = new VisitExcluded($request, $visitProperties->visitorInfo['location_ip']); + if ($excluded->isExcluded()) { + return true; + } + + return false; + } + + public function manipulateVisitProperties(VisitProperties $visitProperties) + { + /** + * Triggered after visits are tested for exclusion so plugins can modify the IP address + * persisted with a visit. + * + * This event is primarily used by the **PrivacyManager** plugin to anonymize IP addresses. + * + * @param string &$ip The visitor's IP address. + */ + $this->eventDispatcher->postEvent('Tracker.setVisitorIp', array(&$visitProperties->visitorInfo['location_ip'])); + } +} diff --git a/plugins/CoreHome/config/config.php b/plugins/CoreHome/config/config.php new file mode 100644 index 0000000000..0e966ece0f --- /dev/null +++ b/plugins/CoreHome/config/config.php @@ -0,0 +1,9 @@ +<?php + +return array( + + 'tracker.request.processors' => DI\add(array( + DI\get('Piwik\Plugins\CoreHome\Tracker\VisitRequestProcessor'), + )), + +); |