Reputation: 704
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.
There are no error messages in the browser console.
The eCommerce data gets registered correctly.
???
Upvotes: 0
Views: 408
Reputation: 9603
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>
Upvotes: 2
Reputation: 1019
Looks like there are some bugs in your event tracking method.
Try to change values like "10.0" to integer - "10".
ga('send', 'event', 'goal', 'purchase', 'sub_plan_sku', 10);
Upvotes: -1