Google Analytics Script inside XML File
I would like to know If I can add my ecommerce analytics tags inside an xml formated file?
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X'])开发者_JAVA技巧;
_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>
The easiest way to ensure this kind of content will not cause conflicts is to wrap it in a <![CDATA[]]>
tag.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<script type="text/javascript">
<![CDATA[
//javascript
]]>
</script>
Are you sure your suggestion actually works Oded? I've tried something similar and the Javascript never gets executed.
Not sure if I'm doing something wrong or whether your idea was untested.
精彩评论