remove cart item datalayer
-
I trying to capture remove item from cart. The product ID is in a js variable but its not assigning it to datalayer. it shows the name of the variable rather then value.
how i should pass the variable to datalayer or is it possible to change the js variable to a php variable. the code below is on wordpress function.php file
sample code
if (document.querySelectorAll('a.remove')) { document.querySelectorAll('a.remove').forEach((el) => { el.addEventListener('click', (e) => { var Producid= el.getAttribute('data-product_id'); //console.log(Producid); window.dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object. window.dataLayer.push({ 'event': 'removeFromCart', 'ecommerce': { 'remove': { 'products': [{ 'name': 'Remove Triblend Android T-Shirt', 'id': Producid, // this variable Producid not print value it just showing name of the variable 'price': '15.25', 'brand': 'Google', 'category': 'Apparel', 'variant': 'Gray', 'quantity': 1 }] } } });
or how do i access product details that is removed from cart
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘remove cart item datalayer’ is closed to new replies.