2011-10-20 43 views
0

我正在將Google Analytics從傳統遷移到異步追蹤。我現在將我的通用腳本作爲結束標記之前的文檔細節。GA異步跟蹤:追蹤方法是否可以從頭標分離

就像這個...

<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> 

在頁面之後,「近」的結束標記 - 我編程推「_addTrans」,「_addItme」和「_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> 

這是允許的嗎?由於它們不是API文檔中的細節,我的電子商務跟蹤是否仍然有效?

謝謝

回答

0

它的工作原理。它不需要在同一個標​​籤中。你應該注意到對_setAccount的調用仍然是第一次運行。而在你的例子中,你發佈了2次綜合瀏覽量。第一個使用默認的document.location.href,另一個使用自定義/虛擬pageview。這可能不是你想要的,你應該每個頁面都有一個pageview。