Google Analytics Enhanced Ecommerce - How to track cart quantity update? - google-analytics

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?

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

eCommerce datalayer need to be piggy-backed on other GA hits. So every time someone add or remove item, you must:
First update or rebuild * the eCommerce datalayer.
Trigger an event to pass the new data to GA.
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.

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.

Related

Google Analytics Enhanced Ecommerce removed basket items not shown in dashboard

I have a function to remove an item from my analytics data. I'm calling the below function, when my shopper deletes an item from their cart. I've followed the example in the docs.
function removeFromCart(product) {
ga('ec:addProduct', {
'id': product.id,
'name': product.name,
});
ga('ec:setAction', 'remove');
ga('send', 'event', 'UX', 'click', 'remove from cart');
}
I was expecting the Product Adds To Basket metric to decrement by 1 when this function is called, but it appears to remain the same.
Is this a wrong assumption? Is there a Product Removes From Basket column that I need to reveal in the dashboard?
You can find this information in this report in Google Analytics:

How do I loop through products when tracking orders with Google Analytics Ecommerce?

I have a web shop for which I want to track orders. I have successfully set up Google Analytics and pulled test data when orders are finalized, so I get information about the transaction and about the product ordered.
Naturally, I want to pull data from several products in an order, and here is where my problem arises. Whenever I insert a loop I get a template error:
Too many characters in character literal
The script I am using is this:
<script>
ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
'id': '#GetString("Ecom:Order.ID")',
'affiliation': 'Online Store',
'revenue': '#GetDouble("Ecom:Order.Price.PriceWithVAT")',
'shipping': '#GetDouble("Ecom:Order.ShippingFee.Price")',
'tax': '#GetDouble("Ecom:Order.Price.VAT")'
});
#foreach(LoopItem orderline in GetLoop("OrderLines")) {
ga('ecommerce:addItem', {
'id': '#orderline.GetString("Ecom:Product.ID")',
'name': '#orderline.GetString("Ecom:Order:OrderLine.ProductName")',
'price': '#orderline.GetDouble("Ecom:Order:OrderLine.UnitPrice.Price")',
'quantity': '#orderline.GetString("Ecom:Order:OrderLine.Quantity")'
});
}
ga('ecommerce:send');
</script>
Is there something wrong in the way I use this script? It seems like there is only an error when I try to loop through products.
For anyone encountering this - my problem was that I had added the product ID in the ecommerce:addItem when instead I should have added the Order ID from ecommerce:addTransaction so it can link the products to the transaction. If you want to add the product ID, use 'sku' : [product id].

Tracking with Google Tag Manager Ecommerce to Analytics

I need your help about GTM and UA.
Like this exemple i catch the Event in Google Analytics that's work fine :
// 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
}]
}
}
});
In Analytics i can catch the "Event" but where is products data ?
Thanks in advance for your help.
The products data is in the datalayer. You can set set the GA tag to read the dataLayer (alternatively you can set it to use an E-commerce-Variable containing the product data). This is just not very visible in the documentation, you need to click the little green arrow below the code example to expand the description of how to configure your tag (the example assumes you are using and event to send e-commerce data):
If you use a GA setting variable you might need to click "override settings" in the GA tag first.

How can I send custom dimensions with the product impressions event in Google Analytics?

I am currently trying to send custom dimension values with the product impressions event. Everything else seems to work but I am not able to report on the custom dimension values.
I have set up dimension8 and dimension 9 for star rating and review count. I have passed through these values to the object and it is successfully being sent.
dataLayer.push({
'event': 'productDetailImpressions',
'ecommerce': {
'detail': {
'actionField': {
'list': 'PDP'
},
'products': [{
'name': name,
'id': id,
'price': price,
'brand': brand,
'category': category,
'variant': variant,
'dimension8': reviewCount,
'dimension9': starRating
}]
}
}
});
I have set these custom dimensions up with product scope in GA.
I can view the tag and the information it is sending with a plugin in the browser, the values look correct.
However I am still not able to report on these values inside Google Analytics.
Is there anything I am doing wrong?
Thank you.
The scoping of dimensions required 2 things:
Configure scope in Google Analytics admin interface
See below screenshot:
Send custom dimension with the proper hit
Data is sent to Google Analytics with "hits". Hits are:
page tracking hits
event tracking hits
ecommerce tracking hits social
interaction hits
Now this doesn't mean that you should structure your dataLayer so that the custom dimensions are on the same level ase the object (eg user, product) you're trying to associate them with. Instead, you should follow the standard method for setting dimensions:
In Google Analytics, it is:
// Set the dimension
ga('set', 'cd1', 'Level 1');
// Send custom dimension along with a hit (eg pageview)
ga('send', 'pageview');
Now with Google Tag Manager, GTM doesn't send any hits to Google Analytics, it's just a tool for preparing your data and automating the use of GA. So an example on how to do it:
dataLayer.push({
'event': 'productDetailImpressions',
'dimension8': reviewCount,
'dimension9': starRating,
'ecommerce': {
'detail': {
'actionField': {
'list': 'PDP'
},
'products': [{
'name': name,
'id': id,
'price': price,
'brand': brand,
'category': category,
'variant': variant,
}]
}
}
});
Then create some dataLayer variables to read the custom dimension values:
Finally, assign those dimensions to your GA tags:
note: you could potentially make it work with the dataLayer you have, you would just have to replace your dataLayer variable to point to the right location, however I think it's bad practice because it leads to believe that dimensions have to be nested within the scoped object in order to work (which is not true) and it makes things harder to debug.

Enhanced Ecommerce Product List Attribution

So I have read over the Product List Attribution, and can not really understand why my addToCart, checkout and purchase data is not coming through in the product list performance reports in GA.
Product Attribution
In Enhanced Ecommerce, the Product List Performance report includes
useful Product Attribution data. The report includes a "last action"
attribute which gives product level credit to the last Product List
(i.e. add to cart, checkout, or purchase) that the user interacted
with prior to the conversion event.
Product Attribution data helps you understand which Product Lists are
driving conversions and allows you to optimize your merchandising
efforts and drive sales. For example, you can now understand whether
users are purchasing a product as a result of clicking on a
merchandising block, category page, or on the search results page.
To get started with Product Attribution, make sure to specify the list
attribute on your ecommerce action data. This list field will be used
to then attribute Product Adds To Cart, Product Checkouts, Unique
Purchases, and Product Revenue in the Product List Performance report
accordingly
I'm implementing this in GTM. I'm trying to track each one of my category pages performance however, I would like to track the Product List through the whole checkout process "Product Adds To Cart, Product Checkouts, Unique Purchases, and Product Revenue"
Does this mean I will have to assign the product list value for each product on checkout event & purchase events? if so how do you recommend I do this.
For example if a person views a product on category A, clicks a product and then continues through the addToCart checkout and purchase do I need to record that it was product list A that lead to the addToCart, checkout and purchase at each step???
So far i managed to get the list populated all the way up to Unique Purchases ( this column still gets dumped into "not set" for some reason )
For the add2cart i m using:
ga('ec:addProduct', {
'id': id,
'name': name,
'category': category,
'price': price,
'quantity': qty });
ga('ec:setAction', 'add', { 'list': category });
ga('send', 'event', 'UX', 'click', 'add to cart');
The same goes for the checkout procces ( my checkout is a onestep checkout in magento ) so i only load the page once and used :
for(var i = 0; i < cart.length; i++) {
var product = cart[i];
ga('ec:addProduct', {
'id': product.sku,
'name': product.name,
'category': product.category,
'price': product.price,
'quantity': product.qty
}); }
ga('ec:setAction','checkout', {'step': 1 , 'option': log});
ga('send', 'pageview');
Maybe you have an ideea for the last step :)
Hope this helps
You do have to add the list ID and position on the checkout flow, but not when adding a product to the cart or removing one.
You need the list ID and position for:
product impression or clicks
checkout steps
transactions
When you track the checkout steps, your code should look like this:
for(var i = 0; i < cart.length; i++) {
var product = cart[i];
ga('ec:addProduct', {
'id': product.sku,
'name': product.name,
'category': product.category,
'price': product.price,
'quantity': product.qty,
'list': product.category,
'position': product.positionInCategory
});
}
ga('ec:setAction','checkout', {'step': 1 , 'option': log});
ga('send', 'pageview');
This way, Google will associate the checkout step to the proper list.
Make sure you add the list ID and position also with when tracking the transaction itself, for every product in the transaction.
To store this between pages, I would suggest you cache the information:
on the backend side and store it in a caching database like Redis OR
on the frontend side, with cookies or local storate
directly on Google Analytics, through the Management API: https://developers.google.com/analytics/solutions/data-import-product

Resources