3 Types of Google Analytics Code. Which one should we use? 🤔

Hi,

You might know well, Google Analytics code was like this

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxxx-2']);
  _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>

Then…

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
	(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
	m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-xxxxxxxxx-1', 'auto');
  ga('send', 'pageview');
</script>

Now, it changed like this

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxx-12"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-xxxxxxx-12');
</script>

Which one you are using?

1 Like

i am just using monster insights to enter analytics code. how they handle don’t know?

1 Like

There are 3 types?? :sweat_smile: I just pasted the code which they provided.

2 Likes

The Global site tag (Gtag.js) seems more promising to me and it’s efficient as well. So people wouldn’t need to manually handle Google Tag Manager. The unified code does the job altogether. At least that’s what I know. Please correct me if I am wrong anywhere.

1 Like

I’m using the Monster Insight’s Javascript method that allows me to see outbound links in real time, and more!

1 Like

I’m using 2nd with little modification.

1 Like

So, earlier it was also possible that if we use Google Tag Manage, we were able to include analytics scripts into it. I don’t see here anything in new version of Google Analytics code. Moreover, it increased one extra HTTP request.

I am using this one :smile:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
	(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
	m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-xxxxxxxxx-1', 'auto');
  ga('send', 'pageview');
</script>

@championrings Solution: Try this version or you can use CAOS plugin.

I’m using Google Analytic locally. Do you recommend it?

Hello @GulshanKumar Ji,

I am using GA from 2 years plugin name ExactMetrix previously it was fine but now it went to pro and many features are paid fine it has 1 Million active users but, leave what it is.
Can you suggest me some best GA Plugin for WordPress, Recommend from your side.

Thank You In Advance.

@TheIndianRiTz You can also try this (I’m using)

@TheIndianRiTz or else you can also try this one https://wordpress.org/plugins/ga-google-analytics/
Well these 3 are the more better than ExactMetrix.

1 Like