Reputation: 76
Is it possible to implement the following tracking pixel through Google Tag Manager:
...by using the following variable array?:
[
{
id: '4009314961126',
name: 'Schuurschijf k120',
price: '4.7900',
quantity: 1,
category: 'Gereedschap & Werkplaats/Machine toebehoren/Schuurmachines/Delta-
&Multibladen',
brand: ''
},
{
id: '4008496270705',
name: 'Varta knoopcel CR1216 lithium',
price: '5.5000',
quantity: 1,
category: 'Elektra/Energie/Knoopcellen',
brand: ''
}
]
Update #1 With the help of @Max I was able to create the JavaScript I needed:
var pixel_url = "http://gethatch.com/iceleads_rest/merch/91487/direct";
for (i = 0; i < products.length; i++) {
var product = products[i];
pixel_url += ";ean="+product.id+";cur=EUR;pr="+product.price+";qty="+product.quantity+";vendor_name="+product.brand+";prod_name="+product.name;
}
var pixel = document.createElement("img");
pixel.src = pixel_url;
pixel.height = 0;
pixel.width = 0;
document.body.appendChild(pixel);
Working example: https://jsfiddle.net/ronaldbijker/a3qLc607/51/
Upvotes: 0
Views: 515
Reputation: 13334
Something like this should work:
{{ecommerce_products}}
which reads ecommerce.products from dataLayer.pixel_url =
as per your needsTag code:
var products = {{ecommerce_products}};
for (i = 0; i < products.length; i++) {
var product = products[i];
var pixel_url = "http://gethatch.com/...prod_name="+product.name+"qty="+product.quantity+...
var pixel = document.createElement("img");
pixel.src = pixel_url;
document.body.appendChild(pixel);
}
Upvotes: 2