How can i send a dynamic price that should change to the datalayer? can't i simply send a variable like below example?
Var price; //this price will dynamically change based on the product value
dataLayer.push({
'event': 'gtm-event',
'value': price
});
Not sure about google-datalayer, but primitives in Javascript are passed by value, and objects by reference. So, consider
If you now change
priceto 4,data_with_price.pricewill still be 3 because the value had been passed.But if you do
object_with_price.price = 4, thendata_with_object.value.pricewill also be 4.If you change
object_with_price = { price: 5 },data_with_objectwill remain unchanged.