I have no problems creating GTM variables from 'simple' dataLayer, example:
"transactionEntity": "ORDER",
"transactionId": "193552702",
But can't understand how to take values from array. Basically i need to take ID value from these dataLayer table:
"transactionProducts": [
{
"id": "5",
"sku": "black-handbag",
"price": 170,
"priceexcludingtax": "0.00",
"tax": "0.00",
"taxrate": 0,
"type": "bundle",
"category": "",
"quantity": 1
},
{
"id": "3",
"sku": "red-handbag",
"price": 120,
"priceexcludingtax": "0.00",
"tax": "0.00",
"taxrate": 0,
"type": "bundle",
"category": "",
"quantity": 1
}
],
And to pass them to FB pixel using this format:
content_ids: ['5', '3'],
If you have datalayer like that:
<script>
dataLayer.push({
'ecommerce': {
"transactionProducts": [
{
"id": "5",
"sku": "black-handbag",
"price": 170,
"priceexcludingtax": "0.00",
"tax": "0.00",
"taxrate": 0,
"type": "bundle",
"category": "",
"quantity": 1
},
{
"id": "3",
"sku": "red-handbag",
"price": 120,
"priceexcludingtax": "0.00",
"tax": "0.00",
"taxrate": 0,
"type": "bundle",
"category": "",
"quantity": 1
}
]
}
});
</script>
And you want to create variable which will return array of IDs ['5', '3']
Then you need to create two variables:
1) Name: transactionProducts
Type: Data Layer Variable
Data Layer Variable Name: ecommerce.transactionProducts
2) Name: transactionProductsIds
Type: Custom JavaScript
Custom JavaScript: function () { return {{transactionProducts}}.map(function(a) {return a.id;}); }
And then you can use your second variable transactionProductsIds
to receive IDs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With