Google analytics GA异步跟踪:跟踪方法可以从HEAD标签中分离出来吗

Google analytics GA异步跟踪:跟踪方法可以从HEAD标签中分离出来吗,google-analytics,google-analytics-api,Google Analytics,Google Analytics Api,我正在将我的谷歌分析从传统的跟踪迁移到异步跟踪。现在,我将我的常规脚本作为文档详细信息放置在结束标记之前 像这样 <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXXXXXXX-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createEle

我正在将我的谷歌分析从传统的跟踪迁移到异步跟踪。现在,我将我的常规脚本作为文档详细信息放置在结束标记之前

像这样

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

var _gaq=_gaq | |[];
_gaq.push(['''u setAccount','UA-XXXXXXXXX-1']);
_gaq.push([''u trackPageview']);
(功能(){
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);
})();
在后面的页面中,“靠近”结束体标记——我以编程方式推送methods数组中的“\u addTrans”、“\u addtme”和“\u trackTrans”方法。像这样

    <script type="text/javascript">
        try {
                _gaq.push(['_trackPageview', '/checkout/order_confirmation.aspx']);
                _gaq.push(['_addTrans',
                  '1234',           // order ID - required
                  'Mountain View',  // affiliation or store name
                  '11.99',          // total - required
                  '1.29',           // tax
                  '5',              // shipping
                  'San Jose',       // city
                  'California',     // state or province
                  'USA'             // country
                ]);
                _gaq.push(['_addItem',
                  '1234',           // order ID - required
                  'DD44',           // SKU/code
                  'T-Shirt',        // product name
                  'Green Medium',   // category or variation
                  '11.99',          // unit price - required
                  '1'               // quantity - required
                ]);
                _gaq.push(['_trackTrans']);

        } catch (err) { }
    </script>

试一试{
_gaq.push([''u trackPageview','/checkout/order\u confirmation.aspx']);
_gaq.push(['''u addTrans',
“1234”,//订单ID-必需
“Mountain View”,//附属机构或商店名称
“11.99”,//总计-必填项
‘1.29’,//税
'5',//装运
'圣何塞',//城市
'加利福尼亚',//州或省
“美国”//国家/地区
]);
_gaq.push(附加项),
“1234”,//订单ID-必需
“DD44”,//SKU/代码
'T恤',//产品名称
“绿色介质”,//类别或变体
'11.99',//单价-必需
'1'//数量-必需
]);
_gaq.push([''u trackTrans']);
}捕获(错误){}
这是允许的吗?由于它们没有在API文档中详细列出,我的电子商务跟踪还能工作吗


谢谢

它很管用。它不需要在同一个标签中。您应该注意到,对_setAccount的调用仍然必须是第一次运行。在你的例子中,你有两个页面浏览量。第一个使用默认的document.location.href,另一个使用自定义/虚拟页面视图。这可能不是你想要的,你应该有一个单一的页面浏览每页