Usually a developer would create custom events for us with data we need to send in our enhanced eCommerce data.
We’re going to take matters into our own hands now, and introduce a dataLayer.push ourselves that we know Google Analytics will read.
At the bottom on this page, you’ll see a test product created. When we click on the button, it will send in a Custom time event into our dataLayer with additional data.
We’re going to introduce this additional data ourselves, seeing as our developer is on holiday and we need a hack to have the site work.
To get this to work, we need the dataLayer information to be present before our Google Analytics tag fires.
To do this, we’ll make our Google Analytics tag fire when it sees a custom event “addToCart” in our dataLayer (as that will only happen when we click on the button).
Task:
- 2 Tags to set up
- 1 dataLayer push tag with enhanced eCommerce code shown below (fire this on Page View)
- 1 Google Analytics event to fire only when it sees the custom event “addtoCart”
dataLayer.push({
'event': 'addToCart',
'ecommerce': {
'currencyCode': 'EUR',
'add': {
'products': [{
'name': 'Triblend Android T-Shirt',
'id': '12345',
'price': '15.25',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Gray',
'quantity': 1
}]
}
}
});
Our Special button: