Menü schliessen
Created: March 7th 2012
Last updated: May 1st 2020
Categories: Typo3
Author: Marcus Fleuti

Insert Google Analytics code in Typo3 root template using headerData

Insert Google Analytics code in your pages' header like this:

1. Edit your Typo3 root template

2. Add the following code to it (change your Google Analytics code accordingly)

// add various page metadata
page.headerData.9999 = TEXT
page.headerData.9999.value (
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-???????-?']);
_gaq.push(['_trackPageview']);
(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'https://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
)