diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2018-10-17 00:52:43 +0300 |
---|---|---|
committer | diosmosis <diosmosis@users.noreply.github.com> | 2018-10-17 00:52:43 +0300 |
commit | f89ad7bb265ed9ebf5c46b4433f033c2adec601c (patch) | |
tree | 496ceaebfbb6259a37b2411c7c3b40bbda895fc2 | |
parent | b7d9f11b1a95739317fac37d7e00a474f3b9b504 (diff) |
let plugins modify the JS tracker (#13615)
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | plugins/CustomPiwikJs/TrackingCode/PiwikJsManipulator.php | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 44c9cb987f..c6cf30f4b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The Product Changelog at **[matomo.org/changelog](https://matomo.org/changelog)* ### New APIs * Added new event `Access.modifyUserAccess` which lets plugins modify current user's access levels/permissions. +* Added new event `CustomMatomoJs.manipulateJsTracker` which lets plugins modify the JavaScript tracker. ### New Developer Features diff --git a/plugins/CustomPiwikJs/TrackingCode/PiwikJsManipulator.php b/plugins/CustomPiwikJs/TrackingCode/PiwikJsManipulator.php index affac1fd46..6e2e4c5500 100644 --- a/plugins/CustomPiwikJs/TrackingCode/PiwikJsManipulator.php +++ b/plugins/CustomPiwikJs/TrackingCode/PiwikJsManipulator.php @@ -8,6 +8,8 @@ namespace Piwik\Plugins\CustomPiwikJs\TrackingCode; +use Piwik\Piwik; + class PiwikJsManipulator { const HOOK = '/*!!! pluginTrackerHook */'; @@ -36,6 +38,24 @@ class PiwikJsManipulator $this->content = str_replace(array(self::HOOK, '/*!! pluginTrackerHook */'), self::HOOK . $trackerExtension, $this->content); } + $content = $this->content; + + /** + * Triggered after the Matomo JavaScript tracker has been generated and shortly before the tracker file + * is written to disk. You can listen to this event to for example automatically append some code to the JS + * tracker file. + * + * **Example** + * + * function onManipulateJsTracker (&$content) { + * $content .= "\nPiwik.DOM.onLoad(function () { console.log('loaded'); });"; + * } + * + * @param string $content the generated JavaScript tracker code + */ + Piwik::postEvent('CustomMatomoJs.manipulateJsTracker', array(&$content)); + $this->content = $content; + return $this->content; } |