Google Analytics Enhanced Ecommerce - How to track cart quantity update?
Asked Answered
F

3

18

Google doesn't say a word on how to deal with the user changing the quantity of a line in their cart using the Enhanced Ecommerce plugin.

When a user adds something to his cart, returns to the same cart in a later session and adds more of the same product it might occur that he gets a lower unit price (for example when price breaks are used by the e-commerce site).

So, for example, he first adds 1 unit for $3, comes back and raises the number to 10 and thereby only has to pay $2 for each unit.

Now the price previously sent to GA needs to be invalidated in some way.

There are multiple solutions for this, but each of them have some serious drawbacks:

1) Calculate the difference and add / remove that.

2) Remove the line and then add with current quantity.

Method 1 has the advantage of passing the (most) correct user interaction. Since add/remove doesn't seem to have a nonInteraction parameter, using method 2 would mean wrong numbers of adds/removes.

Method 2 has the advantage of being able to change the price if a price change has happened after the product has been added the first time. For example: after adding more units the customer now has a lower unit price. Using method 1 would mean that either the amounts in GA are incorrect, or you would have to calculate price differences and fictionally give the latest added units a lower price.

Which of the two methods is preferable?

Faithfaithful answered 9/1, 2017 at 10:51 Comment(3)
Did you have a solution for this, I am having the same questionPerdurable
@Perdurable If I remember correctly in the end we went with method 2 (removing the line and adding a new one), but that's about as much as I can recall. I haven't worked with Enhanced Ecommerce in the last years, so could very well be that they do have a better way to handle this in the meanwhile,Faithfaithful
Thanks, as far as we understood, we indeed have to use method 2.Perdurable
M
2

In a pure analytics.js implementation you do use

ga('ec:setAction', 'remove');

along with the product attributes describing the product being removed

see https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart

// describes the product being removed
ga('ec:addProduct', {
    'id': product.id,
    'name': product.name,
    'category': product.category,
    'brand': product.brand,
    'variant': product.variant,
    'price': product.price,
    'quantity': product.qty
  });
ga('ec:setAction', 'remove'); // notice 'remove' here
ga('send', 'event', 'UX', 'click', 'removed from cart'); // sends the action

If you are using GTM and GA native tags in GTM, see https://developers.google.com/tag-manager/enhanced-ecommerce#add and the remove section

// Measure the removal of a product from a shopping cart.
dataLayer.push({
  'event': 'removeFromCart',
  'ecommerce': {
    'remove': {                               // 'remove' actionFieldObject measures.
      'products': [{                          //  removing a product to a shopping cart.
          'name': 'Triblend Android T-Shirt',
          'id': '12345',
          'price': '15.25',
          'brand': 'Google',
          'category': 'Apparel',
          'variant': 'Gray',
          'quantity': 1
      }]
    }
  }
});
Meade answered 18/4, 2020 at 19:46 Comment(0)
D
0

eCommerce datalayer need to be piggy-backed on other GA hits. So every time someone add or remove item, you must:

  1. First update or rebuild * the eCommerce datalayer.
  2. Trigger an event to pass the new data to GA.
  3. Reset the dataLayer value to make sure you don't duplicate the data.

* Datalayer are persistent, so make sure you reset the values (dataLayer.push({'ecommerce': undefined});) after you send the data so you won't have duplicate data.

Dingdong answered 25/5, 2018 at 16:36 Comment(3)
This only works within a single pageview. A user can add something to his cart in one pageview and return in a different pageview or even different session to the same cart and change quantities, causing a different unit price and thereby invalidating the correctness of the data that was already sent to GA.Faithfaithful
Exact, this datalayer persitence is at the page load level. So, if the page is reloaed, the datalayer will be clear. But yet, it's a best practice to clear the ecommerce values after you send a hit. For example if you set values to collect product view data with the pageView tag, if you don't reset the ecommerce values after, other hits (I.e.: event to measure scroll) will also resend the same data and will inflate your product view count.Jolinejoliotcurie
I don't think that it is the default behavior of GA to send the same data more than once, that is more likely caused by a bad implementation. Any way this is unrelated to my question. I updated it btw to be more precise.Faithfaithful
U
0

Increasing the quantity shouldn't differ than adding a product to cart. The price change case is the challenge here as you mentioned. If those transactions are not more than %5 of all transactions you may go ahead with the recent quantity and value. If you/they'd like to have the highest possibly accuracy; calculate the difference, save it to local storage, apply it as a qty-change-discount-coupon on success page.

Unseal answered 27/12, 2019 at 20:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.