Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _test/action_plugin_googletagmanagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");

Expand Down
54 changes: 17 additions & 37 deletions action.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
<?php

class action_plugin_googletagmanager extends DokuWiki_Action_Plugin
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;

class action_plugin_googletagmanager extends ActionPlugin
{
public const GTMID = 'GTMID';

/**
* return some info
* Register its handlers with the DokuWiki's event controller
*/
public function getInfo()
{
return array(
'author' => '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');
}
Expand All @@ -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' => '<iframe src="https://www.googletagmanager.com/ns.html?id=' .
$GTMID .
'" height="0" width="0" style="display:none;visibility:hidden"></iframe>',
);
$event->data['script'][] = array (
'type' => 'text/javascript',
$event->data['noscript'][] = ['_data' => '<iframe src="https://www.googletagmanager.com/ns.html?id=' .
$GTMID .
'" height="0" width="0" style="display:none;visibility:hidden"></iframe>'];
$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 .
"');"];
}
}
}
2 changes: 1 addition & 1 deletion conf/metadata.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

$meta['GTMID'] = array('string');
$meta['GTMID'] = ['string'];
Loading