Home  »     »     »     »     »  Where should the Google Analytics code to be placed on a web page?

Where should the Google Analytics code to be placed on a web page?

Monday, November 11, 2013



Google Analytics (GA) is a great way to track the visits to your website. For this You should have a GA and you can generate the Javascript code for tracking the page views.

There are 2 versions of the GA code. Synchronous and Asynchronous

GA ASYNCHRONOUS CODE SNIPPET

The default code is Asynchronous, it is given below.

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_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>

Location of the Asynchronous code : code snippet should appear at the top of your web page just before the closing </head> tag.


GA SYNCHRONOUS CODE SNIPPET

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}
</script>

Location of the Synchronous code : code snippet should appear at the bottom of your page just before the closing </body> tag.

Please Note: Replace the xxxx-x in the code snippet with your Google Analytics Account Number.

Google Analytics is a service offered by Google that generates detailed statistics about a website's traffic and traffic sources and measures conversions and sales.


References:
http://www.google.com/analytics/
GA forum





How to link to this page?
If you wish to link to this page from your website, simply Copy and paste the above HTML code to your web page. It will appear on your page as:
Where should the Google Analytics code to be placed on a web page?.




Share this!




comments powered by Disqus

This Weeks 7 Popular Posts


Subscribe to Recent Posts by Email
Stay connected to CROZOOM with regular Email notices of new Techie articles and IT Jobs. Updates will be delivered to your Inbox as soon as they are posted online.

Enter Your Email Address:  

Delivered by FeedBurner   RSS Feed

Search this Blog   



Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »