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 articles

7 Reasons We Choose WordPress CMS Framework

If you Google “Why should I use WordPress?” you’ll...

How to setup the new Instagram API

The Instagram API has recently been updated with the...

4 Landing Page Conversion Tips

How are your Landing Pages performing? Are you converting your...

Top 9 Reasons to Personalize Content in Your Marketing Campaigns

Excerpts and summary of article posted by Corey Eridon More than...

iHomeFinder Optima Express WordPress MLS IDX Plugin Shortcodes

Listing Gallery Shortcode Reference The following shortcode examples can be...

Case Studies

Real Estate Listings

A clothing brand wanted to launch a new e-commerce website that would allow customers to browse and purchase their products online. We developed a...

Personal Trainer Shop

A clothing brand wanted to launch a new e-commerce website that would allow customers to browse and purchase their products online. We developed a...

Compass Music Platform

A clothing brand wanted to launch a new e-commerce website that would allow customers to browse and purchase their products online. We developed a...