- This topic has 1 reply, 2 voices, and was last updated 7 years, 5 months ago by .
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- The forum ‘How do I …’ is closed to new topics and replies.
Events Made Easy › Forums › How do I … › Implement JavaScript Code for E-Commerce-Tracking w/ Google Analytics
Tagged: E-Commerce tracking, GA, google analytics, Google Tag Manager, GTM
Hi there,
I just came across an issue where I want to implement a JavaScript Code with “dataLayer pushes” for Google Tag Manager snippet after successfully booking an event to track the transaction with Google Analytics.
So there are some courses available on my site and after one of these has been booked via the event’s detail page and the confirmation is being displayed I’d like to add the following code snippet as well:
<script>
var timeStamp = Math.floor(Date.now() / 1000);
window.dataLayer = window.dataLayer || []
dataLayer.push({
‘transactionId’: timeStamp,
‘transactionAffiliation’: ‘Website’,
‘transactionTotal’: ‘#_TOTALPRICE’,
‘transactionTax’: 0,
‘transactionShipping’: 0,
‘transactionProducts’: [{
‘sku’: ‘#_EVENTID’,
‘name’: ‘#_EVENTNAME’,
‘category’: ‘#_EVENTCATEGORIES’,
‘price’: #_EVENTPRICE,
‘quantity’: #_RESPSPACES
}]
});
</script>
Can anybody please help me with this?
Thanks,
Holger
You can add custom javascript in the EME setting “Extra html header”.
If you want your code to only be executed on specific things (like singe event and rsvp), figure out a html-element id that is present only there (for the single event: add a hidden span-html tag to your event format for example, idem for the confirmation page) and check on the presence of that html-tag.
In jquery this looks something like this:
jQuery(document).ready(function () {
if (jQuery('#myElementID').length) {
// do my stuff
}
});