2010-05-10 56 views
0

我想知道如果我可以將我的電子商務分析標籤添加到xml格式文件中?XML文件中的Google Analytics腳本

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
<script type="text/javascript"> 

    var _gaq = _gaq || []; 
    _gaq.push(['_setAccount', 'UA-XXXXX-X']); 
    _gaq.push(['_trackPageview']); 
    _gaq.push(['_addTrans', 
    '1234',   // order ID - required 
    'Acme Clothing', // affiliation or store name 
    '11.99',   // total - required 
    '1.29',   // tax 
    '5',    // shipping 
    'San Jose',  // city 
    'California',  // state or province 
    'USA'    // country 
    ]); 

    // add item might be called for every item in the shopping cart 
    // where your ecommerce engine loops through each item in the cart and 
    // prints out _addItem for each 
    _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']); //submits transaction to the Analytics servers 

    (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'; 
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga); 
    })(); 

</script> 

回答

1

,以確保這類內容不會引起衝突的最簡單的方法是將其包裝在一個<![CDATA[]]>標籤。

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
<script type="text/javascript"> 
<![CDATA[ 
    //javascript 
]]> 
</script> 
0

您確定您的建議實際工作Oded?我嘗試過類似的東西,而Javascript永遠不會被執行。

不知道我是否做錯了什麼,或者你的想法是否未經測試。

相關問題