GA异步跟踪:TrackingMethods能否从HEADTag中分离出来
我正在将 Google Analytics 从传统跟踪迁移到异步跟踪。现在,我的常规脚本作为文档详细信息位于结束标记之前。
像这样......
<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>
稍后在页面中,“靠近”结束 BODY 标记 - 我以编程方式将“_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 文档中并未详细说明,我的电子商务跟踪是否仍然有效?
谢谢
I'm migrating my Google Analytics from Traditional to Asynchronous tracking. I now have my general scripts located as the documentation details just before the closing tag.
Like this ...
<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>
Later in the page, "near" the closing BODY tag -- I programmatically push the "_addTrans", "_addItme", and "_trackTrans" methods in the methods array. Like this ...
<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>
Is this permissible? Since they are not together as detail in the API docs, will my Ecommerce tracking still work?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有用。它不需要位于同一个标签中。您应该注意到,对 _setAccount 的调用仍然必须是第一个运行的。在您的示例中,您正在触发 2 个综合浏览量。第一个使用默认的 document.location.href,另一个使用自定义/虚拟页面视图。这可能不完全是您想要的,您应该每页有一个综合浏览量。
It works. It doesn't need to be in the same tag. You should notice that the call to _setAccount still has to be the first one run. And in your example you're firing 2 pageviews. The first one uses the default document.location.href and the other uses a custom/virtual pageview. That may not be exactly what you want, you should have a single pageview per page.