Comments on: Leverage Enhanced Ecommerce Data Layer for Marketing Pixels https://mixedanalytics.com/blog/use-enhanced-ecommerce-data-layer-marketing-pixels/ APIs, Sheets, and Analytics Thu, 25 Feb 2021 08:42:01 +0000 hourly 1 https://wordpress.org/?v=6.5.5 By: Ana https://mixedanalytics.com/blog/use-enhanced-ecommerce-data-layer-marketing-pixels/#comment-21320 Thu, 17 Dec 2020 15:58:58 +0000 https://mixedanalytics.com/?p=9738#comment-21320 In reply to Toos.

In JS, the plus operator will concatenate instead of add values if at least one is a string. Since your quantity (and price) have quotation marks around them, they are strings instead of numbers, so that's causing this issue.
Anyway, you can resolve this either by making sure your quantities are passed in as numbers to start, or by adjusting the script to force any number-like strings to numbers. Something like this should work:
function (){
var prods = {{DL – ecommerce.purchase.products}};
var i;
var sum = 0;
if (!prods) { return; }
for (i = 0; i < prods.length; i++) { sum +=parseInt((prods[i].quantity)) } return sum; }

]]>
By: Toos https://mixedanalytics.com/blog/use-enhanced-ecommerce-data-layer-marketing-pixels/#comment-21318 Thu, 17 Dec 2020 15:03:01 +0000 https://mixedanalytics.com/?p=9738#comment-21318 Hi there,

I've tried the first script (total quanity) and have implemented the following Custom JS:

function (){
var prods = {{DL – ecommerce.purchase.products}};
var i;
var sum = 0;
if (!prods) { return; }
for (i = 0; i < prods.length; i++) { sum +=(prods[i].quantity) } return sum; }

However, it doesnt really sum, but it concatenates as a string to '011', while my endresult should be '2' (quantity 1+1)

Data Layer Variable array
[
{
id: '1',
name: 'Test product 1',
price: '4.54',
quantity: '1'
},
{
id: '2',
name: 'Test product 2',
price: '20.25',
quantity: '1'
}
]

How can I change this? Thanks for your help!

]]>
By: Ana https://mixedanalytics.com/blog/use-enhanced-ecommerce-data-layer-marketing-pixels/#comment-20074 Wed, 28 Oct 2020 04:16:56 +0000 https://mixedanalytics.com/?p=9738#comment-20074 In reply to steve.

I think you'd just need to add in a second conditional statement to exclude the product ID. Something like this should work:
function(){
var prods = {{DL - ecommerce.purchase.products}};
var i;
var sum = 0;
if (!prods) { return; }
for (i = 0; i < prods.length; i++) { if (prods[i].id!="1001") {
sum +=(prods[i].quantity)
} }
return sum;
}

]]>
By: steve https://mixedanalytics.com/blog/use-enhanced-ecommerce-data-layer-marketing-pixels/#comment-20073 Wed, 28 Oct 2020 03:36:15 +0000 https://mixedanalytics.com/?p=9738#comment-20073 Hi there! Thanks for this article.

How would I filter our a specific product ID from the ecommerce datalayer and count the quantity for all other products?

e.g. if product id = 1001 exclude from count of product quantity?

Thanks!

]]>
By: Ana https://mixedanalytics.com/blog/use-enhanced-ecommerce-data-layer-marketing-pixels/#comment-15943 Wed, 22 Apr 2020 05:14:58 +0000 https://mixedanalytics.com/?p=9738#comment-15943 In reply to John.

Hi John! I checked out the new data layer format and the “price” and “quantity” fields haven’t changed from the GTM format. So I’m not yet sure what the issue is, since it looks like it should work. Just to confirm, you changed the DL variable from ecommerce.purchase.products to ecommerce.items, right? And, do the other scripts from the post work? If so, can you please check if your data layer is using a non-standard format or missing the price/quantity fields in the items array?a

]]>
By: John https://mixedanalytics.com/blog/use-enhanced-ecommerce-data-layer-marketing-pixels/#comment-15932 Tue, 21 Apr 2020 19:10:38 +0000 https://mixedanalytics.com/?p=9738#comment-15932 Thanks for this - awesome reference!

I'm struggling with the "total price" script. When using the updated Google ecommerce framework (https://developers.google.com/tag-manager/ecommerce-appweb) which uses the term "items" in place of "products", the DLV keep showing as "undefined" when using this script:

function (){
var prods = {{ecommerce.items}};
var i;
var sum = 0;
if (!prods) { return; }
for (i = 0; i < prods.length; i++) {
sum +=parseFloat(prods[i].price*prods[i].quantity)
}
return sum;
}

Any advice?

]]>
By: Ana https://mixedanalytics.com/blog/use-enhanced-ecommerce-data-layer-marketing-pixels/#comment-12289 Fri, 13 Dec 2019 12:09:17 +0000 https://mixedanalytics.com/?p=9738#comment-12289 In reply to lolo.

I think the replace method probably does what you want. For example, this would remove all the quotation marks:

function(){
 return JSON.stringify({{JS – Product Attributes}}).replace(/"/g,"");
}

This is just a JavaScript question, so you can check out some JS tutorials online and then change your output exactly the way you want.

]]>
By: lolo https://mixedanalytics.com/blog/use-enhanced-ecommerce-data-layer-marketing-pixels/#comment-12287 Fri, 13 Dec 2019 11:32:08 +0000 https://mixedanalytics.com/?p=9738#comment-12287 In reply to lolo.

sorry, not delete these [ ] symbols 🙂

]]>
By: lolo https://mixedanalytics.com/blog/use-enhanced-ecommerce-data-layer-marketing-pixels/#comment-12286 Fri, 13 Dec 2019 11:31:05 +0000 https://mixedanalytics.com/?p=9738#comment-12286 In reply to lolo.

How can i delete the next simbols in Attributtes names e.g "categoria"-"producto"- "precio" - "cantidad":
" , { , and [
and how can i separate products with "|" symbol in the collected string with your function:
Subset Atributos: [{"categoria":"Sweaters","producto":"Hoodie con bolsillo canguro","precio":75,"cantidad":1,"talla":"xl"},{"categoria":"Cap","producto":"Gorra de pana orgánica y PIÑATEX","precio":53,"cantidad":1}]

to get something like this:

Subset Atributos: [categoria:"Sweaters", producto:"Hoodie con bolsillo canguro", precio:75, cantidad:1, talla:"xl" | categoria:"Cap", producto:"Gorra de pana orgánica y PIÑATEX", precio:53, cantidad:1]

]]>
By: lolo https://mixedanalytics.com/blog/use-enhanced-ecommerce-data-layer-marketing-pixels/#comment-12284 Fri, 13 Dec 2019 10:58:00 +0000 https://mixedanalytics.com/?p=9738#comment-12284 Hi, GREAT SUPPORT!! Now i understand. Then, you means that to collect in GA the data i want in a subset, i have to create a CJS var, and paste the next inside:
function(){
return JSON.stringify({{JS – Product Attributes}});
}
isn´t it?
The next question is if you have any course than show how work with GMT-EEC-Ads Pixels (Facebook&Google Ads). I´m very interested in your way of teach. This post help me a lot!! And your support much more!! 🙂

]]>