A common question that I’m asked by clients is…
Where do I put the Google Analytics JavaScript tracking code snippet in my web page?
Here’s my answer:
Your Google Analytics JavaScript code snippet should go at the bottom of the html document, directly above the ending </body> tag. If possible, it’s always good to have your JavaScript code at the bottom, after all other visible html has been loaded. It doesn’t matter if you’re using PHP or ASP.NET or ColdFusion or Ruby on Rails, the GA code is JavaScript. It just drops in like so…
<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-30555133-1’]);
_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>
</body>
</html>