diff options
author | diosmosis <benaka@piwik.pro> | 2015-07-08 23:45:27 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-08-06 17:37:58 +0300 |
commit | c4e3b909dad7e56a0c27298bbda0d92665be71e4 (patch) | |
tree | 9da3e462cb6374ec720e4e7ebe61df9f33634a01 /plugins/CustomVariables | |
parent | dd2a99a734f7e3596564e9b68d88c8a466ab92d4 (diff) |
Move CustomVariables tracking logic to CustomVariablesRequestProcessor. Includes two methods in RequestProcessor, onNewVisit and onExistingVisit (matches Dimension methods).
Diffstat (limited to 'plugins/CustomVariables')
-rw-r--r-- | plugins/CustomVariables/Tracker/CustomVariablesRequestProcessor.php | 54 | ||||
-rw-r--r-- | plugins/CustomVariables/config/config.php | 9 |
2 files changed, 63 insertions, 0 deletions
diff --git a/plugins/CustomVariables/Tracker/CustomVariablesRequestProcessor.php b/plugins/CustomVariables/Tracker/CustomVariablesRequestProcessor.php new file mode 100644 index 0000000000..066e332440 --- /dev/null +++ b/plugins/CustomVariables/Tracker/CustomVariablesRequestProcessor.php @@ -0,0 +1,54 @@ +<?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\CustomVariables\Tracker; + +use Piwik\Common; +use Piwik\Tracker\Request; +use Piwik\Tracker\RequestProcessor; +use Piwik\Tracker\Visit\VisitProperties; + +/** + * TODO + * + * TODO: document request metadata + */ +class CustomVariablesRequestProcessor extends RequestProcessor +{ + public function processRequestParams(VisitProperties $visitProperties, Request $request) + { + // TODO: re-add optimization where if custom variables exist in request, don't bother selecting them in Visitor + $visitorCustomVariables = $request->getCustomVariables($scope = 'visit'); + if (!empty($visitorCustomVariables)) { + Common::printDebug("Visit level Custom Variables: "); + Common::printDebug($visitorCustomVariables); + } + + $visitProperties->setRequestMetadata('CustomVariables', 'visitCustomVariables', $visitorCustomVariables); + } + + public function onNewVisit(VisitProperties $visitProperties, Request $request) + { + $visitCustomVariables = $visitProperties->getRequestMetadata('CustomVariables', 'visitCustomVariables'); + + if (!empty($visitCustomVariables)) { + $visitProperties->visitorInfo = array_merge($visitProperties->visitorInfo, $visitCustomVariables); + } + } + + public function onExistingVisit(&$valuesToUpdate, VisitProperties $visitProperties, Request $request) + { + $visitCustomVariables = $visitProperties->getRequestMetadata('CustomVariables', 'visitCustomVariables'); + + if (!empty($visitCustomVariables)) { + $valuesToUpdate = array_merge($valuesToUpdate, $visitCustomVariables); + } + } + + +}
\ No newline at end of file diff --git a/plugins/CustomVariables/config/config.php b/plugins/CustomVariables/config/config.php new file mode 100644 index 0000000000..82a0058e02 --- /dev/null +++ b/plugins/CustomVariables/config/config.php @@ -0,0 +1,9 @@ +<?php + +return array( + + 'tracker.request.processors' => DI\add(array( + DI\get('Piwik\Plugins\CustomVariables\Tracker\CustomVariablesRequestProcessor'), + )), + +); |