NameSilo

Which Google Analytics code to use

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch
Impact
5,566
I found the following two code snippets from Google's site. Can someone explain their difference and when to use them. (In my Google Analytics account, only the second method is mentioned.)


Method 1:
Source: Adding the tracking code (traditional) - Analytics Help

<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>

Method 2:
Source: Set up the tracking code (asynchronous) - Analytics Help



<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>
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
0
Close
Thanks todosa. I read the explanation but still couldn't understand very well.

I guess my question is: when is the traditional method preferred to the asynchronous method? When would you use the former?
 
0
Close
The answer to your question is that traditional method is made for quick and easy counting.

Asynchronous is for detailed and andvansed counting.

Оf course - this is my opinion
 
0
Close
OK, so if I use the traditional method, I'll get less information in GA reports. Thanks
 
0
Close
You'll get let, but you will just get the info that is more likely to be useful to you anyway. No need to get overwhelmed with too much info.
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back