I'm new to GTM and I'm having trouble trying to submit 2 enhanced ecommerce events in the dataLayer. Only the last event seems to be getting sent when I check on Google Analytics.
I've come across http://www.simoahava.com/analytics/ecommerce-tips-google-tag-manager/ which, just before the summary, seems to sum up what I've said regarding it only submitting the last one.
dataLayer.push({
'event': 'addToCart',
'ecommerce': {
'currencyCode': 'GBP',
'add': {
'products': dataLayerProducts
}
}
});
dataLayer.push({
'event': 'checkout',
'ecommerce': {
'checkout': {
'actionField': {'step': 1},
'products': dataLayerProducts
}
}
});
Only the checkout will be registered with Analytics. I've tried things like the following:
dataLayer = [{
'event': 'checkout',
'event': 'addToCart',
'ecommerce': {
'add': {
'products': dataLayerProducts
},
'checkout': {
'actionField': {'step': 1},
'products': dataLayerProducts
}
}
}];
and
dataLayer = [{
'event': 'addToCart',
'ecommerce': {
'add': {
'products': dataLayerProducts
},
}
}, {
'event': 'checkout',
'ecommerce': {
'checkout': {
'actionField': {'step': 1},
'products': dataLayerProducts
}
}
}];
But I've had no luck doing it like that either. If it just isn't possible, any helpful workarounds would be much appreciated.
UPDATE WITH NEW CODE:
Still only sending the last event (checkout). Code appears immediately after the opening <body> tag.
<script>
dataLayer = [];
dataLayerProducts = [];
dataLayerProducts.push({
'name': 'Product Name',
'id': 'SKU',
'price': '29.95',
'brand': 'Brand',
'category': 'Some/Category',
'quantity': 1
});
dataLayer.push({
'event': 'addToCart',
'ecommerce': {
'add': {
'products': dataLayerProducts
},
}
});
dataLayer.push({
'event': 'checkout',
'ecommerce': {
'checkout': {
'actionField': {'step': 1},
'products': dataLayerProducts
}
}
});
</script>
<!-- Google Tag Manager -->
// Code
<!-- End Google Tag Manager -->