如何使用 "ga" 命令通过 Analytics.js 将购买请求发送到 google 分析?
how to send purchase request to google analytics via Analytics.js with "ga" command?
好的,开始吧
我确实在所有页面的 "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>
和其他脚本:
for view product detail
<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>
for purchase
<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>
and other classic analytics.js functions
每个代码都包含ga("send","pageview");行,但正因为如此,页面浏览量统计数据增加了数倍并且是不正确的。如果没有这一行,"purchase" 等数据将停止发送。我该怎么办?
我需要让浏览量正确,同时还要发送其他数据,有哪些选择?
由于头部所有页面的综合浏览量为 "send",您可以对其余页面进行 use "events"。这是假设产品详细信息和产品购买都是在同一页面上发生的所有事件。
例如,您可以发送事件而不是发送产品详细信息的综合浏览量:
ga('send', 'event', 'product', 'view-detail', 'PRODID000111');
购买:
ga('send', 'event', 'product', 'purchase', 'PRODID000111');
模式是
ga('send', 'event', {EVENT CATEGORY}, {EVENT ACTION}, {EVENT LABEL});
好的,开始吧 我确实在所有页面的 "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>
和其他脚本:
for view product detail
<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>
for purchase
<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>
and other classic analytics.js functions
每个代码都包含ga("send","pageview");行,但正因为如此,页面浏览量统计数据增加了数倍并且是不正确的。如果没有这一行,"purchase" 等数据将停止发送。我该怎么办?
我需要让浏览量正确,同时还要发送其他数据,有哪些选择?
由于头部所有页面的综合浏览量为 "send",您可以对其余页面进行 use "events"。这是假设产品详细信息和产品购买都是在同一页面上发生的所有事件。
例如,您可以发送事件而不是发送产品详细信息的综合浏览量:
ga('send', 'event', 'product', 'view-detail', 'PRODID000111');
购买:
ga('send', 'event', 'product', 'purchase', 'PRODID000111');
模式是
ga('send', 'event', {EVENT CATEGORY}, {EVENT ACTION}, {EVENT LABEL});