[TYPO3-english] Google Analytics - insert javascript with page.headerData

Dennis Hoffland d.o.hoffland at tele2.nl
Fri Nov 10 14:09:35 CET 2017


Hello,

I have put the following code into the TS Setup of my root page:

# *****
# Google Analytics
# *****

temp.GoogleAnalytics = TEXT
temp.GoogleAnalytics.value (
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxx-x"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
ga('set', 'anonymizeIp', true); // Toelichting AP: Hiermee zet u de IP-maskering aan
  gtag('config', 'UA-xxxxxxx-x');
</script>
)

page.headerData.50 = TEMPLATE
page.headerData.50.template < temp.GoogleAnalytics


The HTML output only contains:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxx-x"></script>

The second section of the javascript is simply missing ...


If I try instead:

# *****
# Google Analytics
# *****

page.headerData.50 = TEXT
page.headerData.50.value ( 
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxx-x"></script>
)
page.headerData.60 = TEXT
page.headerData.60.value ( 
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
ga('set', 'anonymizeIp', true); // Toelichting AP: Hiermee zet u de IP-maskering aan
  gtag('config', 'UA-xxxxxxx-x');
</script>
)

It produces the same result:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxx-x"></script>

Is there something wrong with the syntax that prevents the second javascript section from being rendered?

Kind regards,

Dennis


More information about the TYPO3-english mailing list