希望使用旧代码从google-analytics.com/ga.js更新到stats.g.doubleclick.net/dc.js

时间:2014-02-19 23:18:30

标签: javascript google-analytics

我想将google-analytics.com/ga.js更改为stats.g.doubleclick.net/dc.js

我当前的代码(旧的,但害怕改变它 - 继承)是

<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-051510-6'); 
pageTracker._setDomainName('mydomain.org'); 
pageTracker._addIgnoredOrganic('mydomain.org'); 
pageTracker._setAllowHash(false);
pageTracker._setAllowLinker(true);
pageTracker._trackPageview();
} catch(err) {}</script>

我尝试将其更改为

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." :   "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "stats.g.doubleclick.net/dc.js'     type='text/javascript'%3E%3C/script%3E"));
</script>

但得到一个错误,说它无法加载,因为它正在查看localhost:dc.js

任何帮助表示赞赏!

2 个答案:

答案 0 :(得分:1)

我认为您应该更新为Classic异步代码(Universal Analytics不支持双击),如下所示:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-051510-6']);
  _gaq.push(['_setDomainName', 'mydomain.org']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_addIgnoredOrganic', 'mydomain.org']); 
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

不推荐使用_setAllowHash

答案 1 :(得分:0)

感谢所有帮助过的人。基本上我只需删除www,因为它是拉动www.stats.g.doubleclick.net/dc.js

所以最终的代码是

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." :   "http://");
document.write(unescape("%3Cscript src='" + gaJsHost + "stats.g.doubleclick.net/dc.js'          type='text/javascript'%3E%3C/script%3E"));
</script>