diff --git a/_test/action_plugin_googletagmanagerTest.php b/_test/action_plugin_googletagmanagerTest.php index 5f1ebb8..d983e2d 100644 --- a/_test/action_plugin_googletagmanagerTest.php +++ b/_test/action_plugin_googletagmanagerTest.php @@ -26,7 +26,7 @@ public function test_google_tag_manager() idx_addPage($pageId); $request = new TestRequest(); - $response = $request->get(array('id' => $pageId, '/doku.php')); + $response = $request->get(['id' => $pageId, '/doku.php']); /** * Tags to searched @@ -67,7 +67,7 @@ public function test_google_tag_manager_awcode() idx_addPage($pageId); $request = new TestRequest(); - $response = $request->get(array('id' => $pageId, '/doku.php')); + $response = $request->get(['id' => $pageId, '/doku.php']); $domElements = $response->queryHTML("script"); diff --git a/action.php b/action.php index 1eec45f..0e19978 100644 --- a/action.php +++ b/action.php @@ -1,28 +1,16 @@ 'Alexander Lehmann', - 'email' => 'alexlehm@gmail.com', - 'date' => '2026-01-03', - 'name' => 'Google Tag Manager Plugin', - 'desc' => 'Plugin to embed Google Tag Manager in your wiki.', - 'url' => 'https://wiki.lehmann.cx/projects:dokuwiki_gtm', - ); - } - - /** - * Register its handlers with the DokuWiki's event controller - */ - public function register(Doku_Event_Handler $controller) + public function register(EventHandler $controller) { $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'addHeaders'); } @@ -35,32 +23,24 @@ public function addHeaders(&$event, $param) $is_AW_tag = substr($GTMID, 0, 3) == 'AW-'; if ($is_AW_tag) { - $event->data['script'][] = array ( - 'src' => "https://www.googletagmanager.com/gtag/js?id=" . $GTMID, - ); - $event->data['script'][] = array ( - 'type' => 'text/javascript', + $event->data['script'][] = ['src' => "https://www.googletagmanager.com/gtag/js?id=" . $GTMID]; + $event->data['script'][] = ['type' => 'text/javascript', '_data' => "window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);}" . - " gtag('js', new Date()); gtag('config', '" . - $GTMID . - "');", - ); + " gtag('js', new Date()); gtag('config', '" . + $GTMID . + "');"]; } else { - $event->data['noscript'][] = array ( - '_data' => '', - ); - $event->data['script'][] = array ( - 'type' => 'text/javascript', + $event->data['noscript'][] = ['_data' => '']; + $event->data['script'][] = ['type' => 'text/javascript', '_data' => "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','" . - $GTMID . - "');", - ); + $GTMID . + "');"]; } } } diff --git a/conf/metadata.php b/conf/metadata.php index 5738b65..ec2feff 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -1,3 +1,3 @@