为什么为我的站点生成的跟踪代码与文档中的不同?

Why is tracking code generated for my site different than what is in the documentation?

查看 https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide 的 GA 开发人员页面,它说跟踪代码是:

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);
  })();

但是当我为我的网站开设帐户时,GA 会给我跟踪代码:

(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-XXXXX-1', 'auto');
  ga('send', 'pageview');

为什么这些完全不同?

谢谢

第一个代码片段用于 old/traditional Google Analytics 跟踪脚本。

第二个使用较新的通用 Google 分析跟踪脚本。

它们不同的原因可能是因为 Google 正在尝试推送较新的跟踪脚本,但尚未更新所有文档。

The analytics.js JavaScript library is built on Universal Analytics technology. If you’re using a tracking code snippet on your website that references analytics.js, you’re using Universal Analytics.

If you’re using any other library, like ga.js, you’re using a Classic Analytics tracking technology, and should upgrade your tracking code (if you also have a Universal Analytics property).

Reference