17
votes

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?

3
Did you have a solution for this, I am having the same questionEmmie
@Emmie 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,inwerpsel
Thanks, as far as we understood, we indeed have to use method 2.Emmie

3 Answers

2
votes

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
      }]
    }
  }
});
0
votes

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.

0
votes

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.