1<?php 2 3use dokuwiki\Extension\ActionPlugin; 4use dokuwiki\Extension\EventHandler; 5 6class action_plugin_piwiktagmanager extends ActionPlugin 7{ 8 public const PWTMID = 'PWTMID'; 9 public const PWTMHOST = 'PWTMHOST'; 10 11 /** 12 * Register its handlers with the DokuWiki's event controller 13 */ 14 public function register(EventHandler $controller) 15 { 16 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'addHeaders'); 17 } 18 19 public function addHeaders(&$event, $param) 20 { 21 22 if (!$this->getConf(self::PWTMID)) return; 23 24 $event->data['script'][] = ['type' => 'text/javascript', '_data' => " 25 var _mtm = window._mtm = window._mtm || []; 26 _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'}); 27 (function() { 28 var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; 29 g.async=true; g.src='https://" . 30 $this->getConf(self::PWTMHOST) . 31 "/piwik/js/container_" . 32 $this->getConf(self::PWTMID) . 33 ".js'; s.parentNode.insertBefore(g,s); 34 })();"]; 35 } 36} 37