好的,让我们开始吧 我确实在所有页面的“ head”模板中都包含了小脚本
<script type="text/javascript">
(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","https://www.google-analytics.com/analytics.js","ga");
ga("create", "' . $this->getTrackId() . '", "auto");
ga("require", "ec");
ga("send", "pageview");
</script>
和其他脚本:
查看产品详细信息
<script type="text/javascript">
ga("ec:addProduct", { // Provide product details in a productFieldObject.
"id":"' . $post_id . '", // Product ID (string).
"name":"' . $title . '", // Product name (string).
"category":"' . $categories . '" // Product category (string).
});
ga("ec:setAction","click", { // click action.
"list":"' . $categories . '" // Product list (string).
});
ga("send", "pageview");
</script>
<script type="text/javascript">
ga("ec:addProduct", {
"id": "' . $post_id . '",
"name": "' . $title . '",
"category": "' . $categories . '"
});
ga("ec:setAction", "detail");
ga("send", "pageview");
</script>
要购买
<script type="text/javascript">
ga("ec:addProduct", {
"id": "'.$product_id_arr.'",
"name": "'.$name.'",
"variant": "'.$variant.'",
"price": "'.$subtotal.'",
"quantity": "'.$qty.'"
});
ga("ec:setAction", "purchase", {
"id": "'.$trans.'"
});
ga("send", "pageview");
</script>
和其他经典的analytics.js函数
每个代码都包含ga(“发送”,“网页浏览”);行,但由于这个原因,浏览量统计数据增加了数倍并且是不正确的。如果没有此行,将停止发送“购买”之类的数据。我该怎么办?
我需要使页面浏览数正确,同时还应该发送其他数据,有哪些选择?
答案 0 :(得分:0)
由于您的头部所有页面都有“发送”网页浏览量,因此剩下的工作就是use "events"。假设产品详细信息和产品购买都是同一页面上发生的事件。
例如,您可以发送事件:
ga('send', 'event', 'product', 'view-detail', 'PRODID000111');
要购买:
ga('send', 'event', 'product', 'purchase', 'PRODID000111');
模式是
ga('send', 'event', {EVENT CATEGORY}, {EVENT ACTION}, {EVENT LABEL});