Google Analytics Event Tracking
Google Analytics is a very powerful reporting tool, which most people are aware of, but rarely use! It can provide exceptionally detailed insights into your web business and help you shape your online strategy to really maximise your presence.
Here we look one of the many great features of Analytics, namely Event Tracking. As anyone who has ever used Event Tracking in Google Analytics will tell you, once you start using it you will find it invaluable!
Very often, when a site has just been launched, there is a collective sigh of relief. Job done, project completed. However, once you set sail on the good ship ‘website’, it helps hugely to have a compass to steer you away from white horses, rocky shores and towards bountiful islands where you can increase, not merely web traffic, but relevant web traffic.
But how can you possibly get strong insights to allow you to strategise for your website. Well, we usually find that most clients have heard of Google Analytics, but have never used it!
Google Analytics is the amazing free tool that lets you know exactly what’s going on with your website traffic. From where your visitors are coming from to what they’re doing on your site to where they’re leaving? It can even tell you how many times a certain button on your site has been clicked and position this information amongst other dimensions. For example, you can break these button clicks down to demographic level, device level, and even plot them across a time dimension to see what days, or times of day, you are getting the strongest interaction. This is all possible when you combine Event Tracking with Google Analytics.
So, Google Analytics can tell you where your customers or leads are coming from, but it doesn’t come setup out-of-the-box to do that for you. If you wish to track events – such as button clicks, as previously mentioned – you need to make some tweaks. And let’s be honest, if you’re not using Google Analytics to tell you where the leads for your business are actually coming from, you’re not maximising the potential of this amazing tool.
Setting up Google Analytics is extremely straightforward on modern websites. Essentially you just need to:
- Create a Google Account
- Sign into Google Analytics hub
- Create a property
- Install the tracking code into your website for every page you wish to track
- Wait approximately 24 hours for your data to start coming through
- Tailor your reports according to your particular requirements
For specific instructions regarding each step, check out this very useful resource put together by the boffins at Google themselves!
I stress modern websites above, simply because this usually implies some form of PHP and CMS. In these cases your site developer can add the code once and have it dynamically called by each page.
In a CMS such as WordPress your developer will almost certainly create an input box in one of the site’s admin screens for you to add your Google Analytics tracking snippet, just like adding any item of content. The heavy lifting will be taken care of for you. If you are using a commercial theme, this input area will come with the theme out-of-the-box.
Joomla also has similar methods for adding your Google Analytics code. Joomla has the benefit of deriving every page from a single index.php template file. So adding your tracking snippet to the footer area of this index template file will have the effect of loading it on every page for you.

Okay, we’ll assume you’re all setup with Google Analytics now. It’s a bit dazzling, isn’t it? All that data; all those options. Okay, we’ll do a separate article on managing these reports in the very near future. For now, the objective is to show how a tweak to your analytics code can make tracking events on your website a snip! Don’t worry, all will be explained.
For the purposes of Google Analytics, an event is any action by a user on your website and for which you are ‘listening’ in your analytics reports. This could be a newsletter signup, adding a product to the shopping cart, or submitting an enquiry via your site’s contact form. It is this last example we will work with here.
One thing you certainly don’t want to do is to rely solely on the number of visits to your contact page as a measure of actual enquiries. They might be the same thing, but in reality page visits will be higher than actual enquiries since the user could bounce from the page without ever submitting your contact form.
Often people get around this by creating a redirect to a confirmation page and then track visits to this confirmation page as an indicator of actual enquiries. This is definitely an improvement and for many people it will suffice. However, you must be certain that the confirmation page itself cannot be accessed without first submitting the form. There are many ways to do this, but passing your confirmation page through a dedicated function to identify how the user got there is method that could be considered.
function confirmation_page() {
if($this->referer() != ‘your_contact_page_url’) {
$this->redirect(‘some_other_page_url’);
}
}
The snippet of code above demonstrates the principle here. If the user has not landed on your confirmation page via your contact form, then you simply redirect them to another page. This guarantees that only users who have successfully submitted your contact form will land on the confirmation page. You can then be confident in tracking these page visits in Google Analytics as ‘enquiries’.
We can go one step further though and really crank up the reporting efficiency by adding event tracking for the contact form submission. To do this we need to add a small piece of additional code to the relevant page(s) on your site.
I’m not going to explain every parameter here of the event tracking method that Google Analytics listens to, but I will give you a specific example, from which you can derive the principle. If you’re feeling particularly geeky, you can get intimate with the event tracking code by visiting Google’s own Developer Guide for Events.
All we need to establish before we add our single line of additional jQuery code to get our event tracking working is the ID of the contact form button, the category (this is how it will appear in Google Analytics reports), the name of the event type and the label we wish to give this event (which can be used for categorising events). Google’s event tracking method refers to these as ‘category’, ‘action’ and ‘label’.
The ID of my button is ‘contacter’ (original, right?). The category is ‘enquiry, event type is a ‘click’ and the label I’m giving it is ‘contact’. The Google Analytics Event Tracking method is expressed as follows:
ga(‘send’, ‘event’, ‘category’, ‘action’, ‘label’);
Adding our specific values we express the method as follows:
ga(‘send’, ‘event’, ‘enquiry’, ‘click’, ‘send_button’);
Now we add this snippet of code to a jQuery event that corresponds to a click on the contact form’s submit button. Remember, the ID of my button is ‘contacter’, hence:
$(“button#contacter”).on(‘click’,function() { ga(‘send’, ‘event’, ‘enquiry’, ‘click’, ‘send_button’); });
It can take up to twenty-four hours for your Google Analytics to pick up on this code change and begin populating your reports with results from your newly tracked event. When this time passes you will find all your event data under ‘Behaviour —> Events’.
If, like me, you don’t want to wait to see that your code is working, you can check it under ‘Real Time —> Events’. It will look something like this:

The eagle-eyed among you will have spotted that this event gets tracked every time the user clicks the submit button on the contact form. What if their submitted details fail validation, the captcha is not completed correctly or for some reason the form doesn’t submit correctly? Does it still count as an enquiry?
In my case all three possibilities are covered in flow control code for my contact form. If captcha fails I capture that in my code. Likewise, if the user fails validation (for example, they don’t input a valid email address), I also capture that in my code. And, if for some bizarre reason the gremlins contrive to prevent the form from submitting correctly, I get a submission failure result.
Because I am using an AJAX form, if any of these three issue arise, my button click will never reach my Google Analytics Event Tracking code and so the form will never appear as having been sent within my analytics reports.
Finally, we need to be careful that each click on our form does not generate a ‘bounce’ result in our Google Analytics reports. Otherwise we will artificially inflate our bounce statistics for the contact page, which will create some head-scratching when we analyse our monthly reports.
Fortunately, Google has provided a solution to this for us. We simply add another parameter to the code snippet. This parameter is referred to as ‘Noninteractive’. It’s expressed in JSON format (don’t worry if you don’t know about JSON, just see the snippet below) and when set to ‘1’ it tells Google Analytics not to count the submission as a bounce.
$(“button#contacter”).on(‘click’,function() { ga(‘send’, ‘event’, ‘enquiry’, ‘click’, ‘send_button’,{‘nonInteraction’: 1}); });
And that’s it! You now have ‘contact’! You can now safely measure your enquiries, cross-tabulate the data with other dimensions and create insightful aggregates or forensic granulars all from within Google Analytics and your new Event Tracking code.
In our next article on the area of Google Analytics we’ll show you how to set up Conversion Goals for your new event and put some cool KPIs in place for giving your data real purpose for your business. If you’re having difficulty with your Google Analytics setup we are happy to assist. Just click the ‘Contact Us’ button below. We’re not tracking it, honestly!
Leave a Comment