I created a data layer in gtm and wrote a script to import the information reflected in this part into my own data store, but something seems wrong.
I have a trigger called addToCard, and with this event, my script fires as it pulls the data.
but my data block looks empty as seen in the image
Please help, I can explain more details you want. at least give me advice..
`
<script>
var SvstData={};
var a = window['dataLayer']
var x =[]
var b
a.forEach(item=>{
if(item.event=="addToCart"){
b=item
}
})
if(a){
b.ecommerce.add.products.forEach((item) = function() {
x.push({
pId: item.id,
pQty: item.quantity,
pPrice: item.price,
pName: item.name,
url: '0',
pimg: '0',
image_url: '0',
category_name: item.category,
category_id: '0',
brand: item.brand,
brand_id: '0',
product_code: '0',
title: item.name,
currency: '0',
price_sell: item.price,
price_order_general: item.price
})
})
SvstData.product = x
SvstData.count = x.length
SvstData.email= a[2].userinfo.email;
SvstData.oAmt= a[4].ecommerce.checkout.products[0].price;
SvstData.oID= a[4].ecommerce.checkout.products[0].id;
}
SvstData.status= "cart";
</script>
`
I want to pass information from gtm data layer to my own data block
Via Active questions tagged javascript - Stack Overflow https://ift.tt/H8QdEn7
Comments
Post a Comment