Extension:GoogleTagManager

The GoogleTagManager extension integrates a Google Tag Manager container, e.g. containing a Google Universal Analytics tracking code, into each mediawiki page.

This extension is based on the extension Google Analytics Integration.

Configuration parameters

 * $wgGoogleTagManagerContainerID: Set this to the container ID, shown in your Google Tag Manager account, e.g. GTM-XXXXXX

Known issues
The container code is integrated before the closing body tag. The official documentation in contrast proposed integration right after the opening body tag. General tracking however works fine.

File GoogleTagManager.pgp
 __FILE__,	'name'           => 'Google Tag Manager Integration',	'version'        => '0',	'author'         => 'Felix Kaiser',	'descriptionmsg' => 'googletagmanager-desc',	'url'            => 'https://www.mediawiki.org/wiki/Extension:Google_Analytics_Integration', );

$wgExtensionMessagesFiles['GoogleTagManager'] = dirname(__FILE__). '/GoogleTagManager.i18n.php';

$wgHooks['SkinAfterBottomScripts'][] = 'efGoogleTagManagerHookText';

$wgGoogleTagManagerContainerID = "";

// These options are deprecated. // You should add the "noanalytics" right to the group // Ex: $wgGroupPermissions["sysop"]["noanalytics"] = true; $wgGoogleTagManagerIgnoreSysops = true; $wgGoogleTagManagerIgnoreBots = true;

function efGoogleTagManagerHookText( $skin, &$text='' ) { $text .= efAddGoogleTagManager; return true; }

function efAddGoogleTagManager { global $wgGoogleTagManagerContainerID, $wgGoogleTagManagerIgnoreSysops, $wgGoogleTagManagerIgnoreBots, $wgUser; if ( $wgUser->isAllowed( 'noanalytics' ) ||		 $wgGoogleTagManagerIgnoreBots && $wgUser->isAllowed( 'bot' ) ||		 $wgGoogleTagManagerIgnoreSysops && $wgUser->isAllowed( 'protect' ) ) { return "\n"; }	if ( $wgGoogleTagManagerContainerID === '' ) { return "\n"; }	return << (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= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','{$wgGoogleTagManagerContainerID}');

HTML; }

File GoogleTagManager.i18n.php
 'Inserts a Google Tag Manager container into MediaWiki pages for tracking', );

/** Message documentation (Message documentation) * @author Felix Kaiser */ $messages['qqq'] = array(	'googletagmanager-desc' => 'The name of the extension\'s entry in Special:SpecialPages', );