问题
I have this code to be executed from an html file which sends data to Google Analytics. The code itself is in a file on the localhost and I'm opening it in a browser. So it's not on the webserver.
<html>
<head>
<script>
alert('hello123');
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','http://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxx-1', 'none');
ga('set', 'checkProtocolTask', null);
ga('send', 'pageview');
// ga('require', 'ecommerce');
ga('require', 'ecommerce', 'ecommerce.js');
/*ecommerce*/
ga('ecommerce:addTransaction', {
'id': 'storeId123_test_cartId123_test_1426000599',
'affiliation': '',
'revenue': '352429',
'shipping': '334433',
'tax': '3344'
});
ga('ecommerce:addItem', {
'id': 'storeId123_test_cartId123_test_1426000599',
'name': 'title_123',
'sku': 'sku_123',
'category': 'some_category',
'price': '444',
'quantity': '33'
});
ga('ecommerce:send',{'hitCallback': function() {alert("ecommerce");}});
</script>
</head>
<body>
</body>
</html>
I have the errors:
1) Error loading resource for plugin "ecommerce": Refusing to load url: "http://www.google-analytics.com/plugins/ua/ecommerce.js"
although that url is avaible.
2) Storage not available. Aborting hit -- but I have 'none' in ga('create', 'UA-xxxxxx-1', 'none');
The main error is the first one, I believe the 2nd is related to it.
回答1:
It seems that the combination of cookie domain "none" and the ecommerce-plugin does not work. I haven't delved deeply enough into the tracking code to find out why this is so, I have simply tested it - when I save your code in a file an place it on a web server the ecommerce tracking fails with "none" and works with "auto".
This means if you want to test E-Commerce Tracking Code you cannot do so from the filesystem. I would recommend you set up a local webserver (I like [XAMPP], which1 includes apache, mysql and php and runs on Windows and Mac) and test your code from there.
来源:https://stackoverflow.com/questions/28982806/running-google-analytics-on-localhost-error-loading-the-plugin