Insert Google Analytics JavaScript direct within TypoScript

TIP: For an easy integration of Google-Analyticy in each of your TYPO3 Fluid-Template, I recommend using the Fluid-Template-Manager (short FTM).

In order to integrate CSS or JavaScript into your TYPOScript, as an example the usage of a Google Analytics JavaScript-Snippet, use the following code:

page {
  headerData {
    1 = TEXT
    1.value (
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-Y']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
}) ();

</script>
    )
  }
}
  1. No comments yet.