You must be using Google Analytics script for this to work - so the integrations page should look like this
And finally, paste the below piece of code in the footer code of your site settings.
<script type="text/javascript">
//GA Event Tracker Script. Licensed under MIT. Free for any use by all. Written by Paul Seal from codeshare.co.uk
// Get the category, action and label from the element and send it to GA. The action is optional, because mostly it will be a click event.
var trackClickEvent = function () {
var eventCategory = this.getAttribute("data-event-category");
var eventAction = this.getAttribute("data-event-action");
var eventLabel = this.getAttribute("data-event-label");
var eventValue = this.getAttribute("data-event-value");
ga('send', 'event', eventCategory, (eventAction != undefined && eventAction != '' ? eventAction : 'click'), eventLabel, eventValue);
};
// Find all of the elements on the page which have the class 'ga-event'
var elementsToTrack = document.getElementsByClassName("ga-event");
// Add an event listener to each of the elements you found
var elementsToTrackLength = elementsToTrack.length;
for (var i = 0; i < elementsToTrackLength; i++) {
elementsToTrack[i].addEventListener('click', trackClickEvent, false);
}
</script>
You can track as many buttons as you like. The results will appear in your Google Analytics dashboard under Behaviour > Events and also under Real Time > Events
Hi @Diarmuid_Sexton ! first of all thank you for sharing. I did it step by step but it’s not showing in my GA events. Could you help me? It’s very important for me to track the home page buttons but I am kind of new here…
Do I have to change anything inside your script?
this is my website: https://www.liv-fit.shop/
ok, sorry - I can’t help you anymore right now - i’ve to look at this for a site of my own in a while - i’ll send you the link so you can compare once ready.
@Diarmuid_Sexton You rock, thanks for this! I followed your directions, but it’s weird, the Event Tracking Tracker chrome extension shows the events tracking, but even after waiting for hours, the events still aren’t coming through to GA. I made sure and gtag.js wasn’t toggled on. Thoughts?
Hi all! I’ve tried this but am not seeming to get any results. I’m trying to track the download button clicks, currently only have it setup in the top two buttons in the hero. Any thoughts??
I’m having trouble seeing the events in GA also. It looks like they’re being sent to GA - I can see the requests in Chrome DevTools. But GA doesn’t show them up in the dashboard.
Anyone work that out? I would like to attach a screenshot but the forum won’t allow me as I’m a new user
@Meirion That’s right, you won’t see them in your dashboard unless you customise it. By the way, the Real-time section will only show events that happened within the last 30 minutes. If you want to view events older than that you can go to Behaviour → Events.