1<?php 2if(!defined('DOKU_INC')) die(); 3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 4require_once(DOKU_PLUGIN.'action.php'); 5 6class action_plugin_piwiktagmanager extends DokuWiki_Action_Plugin { 7 8 const PWTMID = 'PWTMID'; 9 const PWTMHOST = 'PWTMHOST'; 10 11 /** 12 * return some info 13 */ 14 function getInfo(){ 15 return array( 16 'author' => 'Alexander Lehmann', 17 'email' => 'alexlehm@gmail.com', 18 'date' => '2024-04-01', 19 'name' => 'Piwik Tag Manager Plugin', 20 'desc' => 'Plugin to embed Piwik Tag Manager in your wiki.', 21 'url' => 'https://www.lehmann.cx/wiki/projects:dokuwiki_piwik', 22 ); 23 } 24 25 /** 26 * Register its handlers with the DokuWiki's event controller 27 */ 28 function register(Doku_Event_Handler $controller) { 29 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, '_addHeaders'); 30 } 31 32 function _addHeaders (&$event, $param) { 33 34 if(!$this->getConf(self::PWTMID)) return; 35 36 $event->data['noscript'][] = array ( 37 '_data' => '', 38 ); 39 $event->data['script'][] = array ( 40 'type' => 'text/javascript', 41 '_data' => " 42 var _mtm = window._mtm = window._mtm || []; 43 _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'}); 44 (function() { 45 var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; 46 g.async=true; g.src='https://".$this->getConf(self::PWTMHOST)."/piwik/js/container_".$this->getConf(self::PWTMID).".js'; s.parentNode.insertBefore(g,s); 47 })();", 48 ); 49 } 50} 51?> 52