Skip to content

Instantly share code, notes, and snippets.

@georgringer
Last active September 18, 2019 07:37
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgringer/0f4f3d0fc7bf6b11668c2a1ac4984a7f to your computer and use it in GitHub Desktop.
Save georgringer/0f4f3d0fc7bf6b11668c2a1ac4984a7f to your computer and use it in GitHub Desktop.
Google Tag Manager with CMS 9. The Site module is extended to allow site admins to edit the GTM code
page {
headerData.50 = TEXT
headerData.50 {
if.isTrue.data = site:googleTagManager
stdWrap.replacement {
10 {
search = ###CODE###
replace.data = site:googleTagManager
}
}
value (
<!-- Google Tag Manager -->
<script>(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','###CODE###');</script>
<!-- End Google Tag Manager -->
)
}
3 = TEXT
3 {
if.isTrue.data = site:googleTagManager
stdWrap.replacement {
10 {
search = ###CODE###
replace.data = site:googleTagManager
}
}
value (
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=###CODE###"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
)
}
}
<?php
# placed in EXT:site/Configuration/SiteConfiguration/Overrides/sites.php
defined('TYPO3_MODE') || die('Access denied.');
call_user_func(
function ($table) {
$GLOBALS['SiteConfiguration'][$table]['columns']['googleTagManager'] = [
'label' => 'Google Tag Manager',
'config' => [
'type' => 'input',
'placeholder' => 'GTM-123456',
],
];
$GLOBALS['SiteConfiguration'][$table]['types']['0']['showitem'] .= ',--div--;Custom,googleTagManager';
},
'site'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment