4

I have following code

<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','//www.google-analytics.com/analytics.js','ga');

          ga('create', 'UA-XXXXXXXXXXXX-1', 'auto');
          ga('send', 'pageview');

        </script>

and

<script type="text/javascript">
/* <![CDATA[ */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXXXXXX-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);
})();

(function(b){(function(a){"__CF"in b&&"DJS"in b.__CF?b.__CF.DJS.push(a):"addEventListener"in b?b.addEventListener("load",a,!1):b.attachEvent("onload",a)})(function(){"FB"in b&&"Event"in FB&&"subscribe"in FB.Event&&(FB.Event.subscribe("edge.create",function(a){_gaq.push(["_trackSocial","facebook","like",a])}),FB.Event.subscribe("edge.remove",function(a){_gaq.push(["_trackSocial","facebook","unlike",a])}),FB.Event.subscribe("message.send",function(a){_gaq.push(["_trackSocial","facebook","send",a])}));"twttr"in b&&"events"in twttr&&"bind"in twttr.events&&twttr.events.bind("tweet",function(a){if(a){var b;if(a.target&&a.target.nodeName=="IFRAME")a:{if(a=a.target.src){a=a.split("#")[0].match(/[^?=&]+=([^&]*)?/g);b=0;for(var c;c=a[b];++b)if(c.indexOf("url")===0){b=unescape(c.split("=")[1]);break a}}b=void 0}_gaq.push(["_trackSocial","twitter","tweet",b])}})})})(window);
/* ]]> */
</script>

Can anybody tell me what the difference is between the two?

David Mulder
  • 26,123
  • 9
  • 51
  • 114
Hitu Bansal
  • 2,917
  • 10
  • 52
  • 87

2 Answers2

3

Simplest answer: ga() is Universal analytics (analytics.js), _gaq.push is classic analytics (ga.js).

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
-2

Basically ...

ga('send', 'pageview');

... is: "Page tracking allows you to measure the number of views you had of a particular page on your web site." This sends Page, Location, and Title information or tracking page hits.

_gaq.push(['_trackPageview']);

... is basically the command to send a series of data points. Basically, an object is built with a variety of data and this command pushes the collected data. Can send much more than just page view tracking data.

UPDATE

  • _gaq: Classic analytics
  • ga: Universal analytics
rfornal
  • 5,072
  • 5
  • 30
  • 42