diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/ExampleTracker/Columns/ExampleVisitDimension.php | 11 | ||||
-rw-r--r-- | plugins/ExampleTracker/ExampleTracker.php | 19 | ||||
-rw-r--r-- | plugins/ExampleTracker/VisitorDetails.php | 27 | ||||
-rw-r--r-- | plugins/ExampleTracker/templates/_visitorLogIcons.twig | 1 | ||||
-rw-r--r-- | plugins/ExampleTracker/tracker.js | 50 |
5 files changed, 108 insertions, 0 deletions
diff --git a/plugins/ExampleTracker/Columns/ExampleVisitDimension.php b/plugins/ExampleTracker/Columns/ExampleVisitDimension.php index f153e4faca..be294660d5 100644 --- a/plugins/ExampleTracker/Columns/ExampleVisitDimension.php +++ b/plugins/ExampleTracker/Columns/ExampleVisitDimension.php @@ -8,6 +8,7 @@ */ namespace Piwik\Plugins\ExampleTracker\Columns; +use Piwik\Common; use Piwik\Piwik; use Piwik\Plugin\Dimension\VisitDimension; use Piwik\Plugin\Segment; @@ -76,6 +77,11 @@ class ExampleVisitDimension extends VisitDimension */ public function onNewVisit(Request $request, Visitor $visitor, $action) { + $paramValue = Common::getRequestVar('myCustomVisitParam', '', 'string', $request->getParams()); + if (!empty($paramValue)) { + return $paramValue; + } + if (empty($action)) { return 0; } @@ -100,6 +106,11 @@ class ExampleVisitDimension extends VisitDimension */ public function onExistingVisit(Request $request, Visitor $visitor, $action) { + $paramValue = Common::getRequestVar('myCustomVisitParam', '', 'string', $request->getParams()); + if (!empty($paramValue)) { + return $paramValue; + } + if (empty($action)) { return false; // Do not change an already persisted value } diff --git a/plugins/ExampleTracker/ExampleTracker.php b/plugins/ExampleTracker/ExampleTracker.php index 22af517aaa..1eb40ce15d 100644 --- a/plugins/ExampleTracker/ExampleTracker.php +++ b/plugins/ExampleTracker/ExampleTracker.php @@ -8,6 +8,25 @@ */ namespace Piwik\Plugins\ExampleTracker; +use Piwik\Common; +use Piwik\Plugins\Live\Visitor; + class ExampleTracker extends \Piwik\Plugin { + public function getListHooksRegistered() + { + return [ + 'Live.getAllVisitorDetails' => 'getAllVisitorDetails', + ]; + } + + public function isTrackerPlugin() + { + return true; + } + + public function getAllVisitorDetails(&$visitor, $visitorRawData) + { + $visitor['myCustomVisitParam'] = isset($visitorRawData['example_visit_dimension']) ? $visitorRawData['example_visit_dimension'] : 'no-value'; + } } diff --git a/plugins/ExampleTracker/VisitorDetails.php b/plugins/ExampleTracker/VisitorDetails.php new file mode 100644 index 0000000000..530fbf0287 --- /dev/null +++ b/plugins/ExampleTracker/VisitorDetails.php @@ -0,0 +1,27 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ + +namespace Piwik\Plugins\ExampleTracker; + +use Piwik\Plugins\Live\VisitorDetailsAbstract; +use Piwik\View; + +class VisitorDetails extends VisitorDetailsAbstract +{ + public function renderIcons($visitorDetails) + { + if (empty($visitorDetails['myCustomVisitParam'])) { + return ''; + } + + $view = new View('@ExampleTracker/_visitorLogIcons'); + $view->myCustomVisitParam = $visitorDetails['myCustomVisitParam']; + return $view->render(); + } +}
\ No newline at end of file diff --git a/plugins/ExampleTracker/templates/_visitorLogIcons.twig b/plugins/ExampleTracker/templates/_visitorLogIcons.twig new file mode 100644 index 0000000000..c582382f9a --- /dev/null +++ b/plugins/ExampleTracker/templates/_visitorLogIcons.twig @@ -0,0 +1 @@ +<span>{{ myCustomVisitParam }}</span>
\ No newline at end of file diff --git a/plugins/ExampleTracker/tracker.js b/plugins/ExampleTracker/tracker.js new file mode 100644 index 0000000000..0383efc9e1 --- /dev/null +++ b/plugins/ExampleTracker/tracker.js @@ -0,0 +1,50 @@ +/** + * Piwik - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ + +(function () { + + var configs = {}; + + function init() { + if ('object' === typeof window && 'object' === typeof window.Piwik && 'object' === typeof window.Piwik.ExampleTracker) { + // do not initialize twice + return; + } + + if ('object' === typeof window && !window.Piwik) { + // piwik is not defined yet + return; + } + + Piwik.ExampleTracker = { + // empty + }; + + Piwik.addPlugin('ExampleTracker', { + log: function (eventParams) { + if (!eventParams || !eventParams.tracker) { + return ''; + } + + return '&myCustomVisitParam=' + 500 + eventParams.tracker.getSiteId(); + }, + }); + } + + if ('object' === typeof window.Piwik) { + init(); + } else { + // tracker is loaded separately for sure + if ('object' !== typeof window.piwikPluginAsyncInit) { + window.piwikPluginAsyncInit = []; + } + + window.piwikPluginAsyncInit.push(init); + } + +})();
\ No newline at end of file |