Where do I put Google Analytics tracking code?

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>

Related

3 Factors That Made Blockchain Become Valuable Last Year

BlockChain is a cryptocurrency and worldwide payment system. It...

Proof of Insurance to Be Added on the BlockChain Network

BlockChain is a cryptocurrency and worldwide payment system. It...

This Year Will Bring Breakthrough Blockchain Developments

BlockChain is a cryptocurrency and worldwide payment system. It...

BlockChain Will Launch New Mining Operation With 5 nm Chips

BlockChain is a cryptocurrency and worldwide payment system. It...

New Mining Centers Increase North American Market Position

BlockChain is a cryptocurrency and worldwide payment system. It...