Google Analytics事件+电子商务跟踪=>事件丢失

时间:2022-03-29 14:45:58

I have a site where I am successfully tracking some events, and successfully collecting eCommerce tracking data.

我有一个网站,我成功跟踪一些事件,并成功收集电子商务跟踪数据。

However, when I try to log an event together with an eCommerce transaction, the event is lost.

但是,当我尝试将事件与电子商务交易一起记录时,事件将丢失。

The code is:

代码是:

<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','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-XX', {'userId': 'XXX'});
ga('send', 'pageview');
</script>

... lots of html ... 

<script type="text/javascript">
ga('send', 'event', 'goal', 'purchase', "sub_plan_sku", 10.0, {'nonInteraction': 1});

ga('require', 'ecommerce', 'ecommerce.js');
ga('ecommerce:addTransaction', {'id':'hello_test', 'affiliation': 'example.com', 'revenue': '10.00'});
ga('ecommerce:addItem', {'id':'hello_test', 'name': 'sub_plan_name', 'sku': 'sub_plan_sku', 'category': 'signup', 'price': '10.00', 'quantity': '1'});
ga('ecommerce:send');
</script>

So when I track events by themselves they work, but when I track it like above they don't get registered.

因此,当我自己跟踪事件时,它们可以工作,但是当我像上面那样跟踪它们时,它们就不会被注册。

All event-tracking javascript is generated by the same Scala Class, so the precise formatting should be consistent across the two scenarios.

所有事件跟踪javascript都是由相同的Scala类生成的,因此精确格式化应该在两个场景中保持一致。

There are no error messages in the browser console.

浏览器控制台中没有错误消息。

The eCommerce data gets registered correctly.

电子商务数据已正确注册。

???

2 个解决方案

#1


You need to send the ecommerce event with an existing event. See the note under Load the Ecommerce Plugin.

您需要使用现有事件发送电子商务事件。请参阅加载电子商务插件下的说明。

So in your situation, just move your event after the ecommerce event.

因此,在您的情况下,只需在电子商务活动后移动您的活动即可。

<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','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-XX', {'userId': 'XXX'});
ga('send', 'pageview');
</script>

... lots of html ... 

<script type="text/javascript">

ga('require', 'ecommerce', 'ecommerce.js');
ga('ecommerce:addTransaction', {'id':'hello_test', 'affiliation': 'example.com', 'revenue': '10.00'});
ga('ecommerce:addItem', {'id':'hello_test', 'name': 'sub_plan_name', 'sku': 'sub_plan_sku', 'category': 'signup', 'price': '10.00', 'quantity': '1'});
ga('ecommerce:send');

ga('send', 'event', 'goal', 'purchase', "sub_plan_sku", 10.0, {'nonInteraction': 1});
</script>

#2


Looks like there are some bugs in your event tracking method.

看起来您的事件跟踪方法存在一些错误。

  1. Try to use this event tracking code without "nonInteraction"
  2. 尝试使用此事件跟踪代码而不使用“nonInteraction”

  3. Try to use only single quotes at all method
  4. 尝试在所有方法中仅使用单引号

  5. Try to change values like "10.0" to integer - "10".

    尝试将“10.0”之类的值更改为整数 - “10”。

    ga('send', 'event', 'goal', 'purchase', 'sub_plan_sku', 10);

    ga('发送','事件','目标','购买','sub_plan_sku',10);

#1


You need to send the ecommerce event with an existing event. See the note under Load the Ecommerce Plugin.

您需要使用现有事件发送电子商务事件。请参阅加载电子商务插件下的说明。

So in your situation, just move your event after the ecommerce event.

因此,在您的情况下,只需在电子商务活动后移动您的活动即可。

<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','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-XX', {'userId': 'XXX'});
ga('send', 'pageview');
</script>

... lots of html ... 

<script type="text/javascript">

ga('require', 'ecommerce', 'ecommerce.js');
ga('ecommerce:addTransaction', {'id':'hello_test', 'affiliation': 'example.com', 'revenue': '10.00'});
ga('ecommerce:addItem', {'id':'hello_test', 'name': 'sub_plan_name', 'sku': 'sub_plan_sku', 'category': 'signup', 'price': '10.00', 'quantity': '1'});
ga('ecommerce:send');

ga('send', 'event', 'goal', 'purchase', "sub_plan_sku", 10.0, {'nonInteraction': 1});
</script>

#2


Looks like there are some bugs in your event tracking method.

看起来您的事件跟踪方法存在一些错误。

  1. Try to use this event tracking code without "nonInteraction"
  2. 尝试使用此事件跟踪代码而不使用“nonInteraction”

  3. Try to use only single quotes at all method
  4. 尝试在所有方法中仅使用单引号

  5. Try to change values like "10.0" to integer - "10".

    尝试将“10.0”之类的值更改为整数 - “10”。

    ga('send', 'event', 'goal', 'purchase', 'sub_plan_sku', 10);

    ga('发送','事件','目标','购买','sub_plan_sku',10);