top of page
Writer's pictureRobin Rozhon

Google Analytics Event Tracking Generator

Google Analytics event tracking is a powerful feature that allows you to track visitors’ interactions with your website that would not be tracked normally.


It’s important to mention that Google Analytics is only as good as the setup. If you only insert the JavaScript code into the source code and think your job is done, you miss a lot of information you may get from your website.


I consider event tracking as one of the first things to take care of, while implementing the tracking. Of course, there are more advanced implementations that are useless for small sites, but there are definitely some basic events that should be implemented on every website.


What to track with events?

  • Contact form submissions

  • Clicks on buttons (onclick events)

  • Depth of scrolling

  • Newsletter subscription

  • Videos

  • Clicks on outbound links

  • and much more…


How to set up event tracking in Google Analytics?

  • Category (required) – Name of the group of events you want to track.

  • Action (required) – Type of event (interaction).

  • Label (optional) – For additional information.

  • Value (optional) – It’s an integer, so you can only use numerical values.

  • Non-interaction (optional) – By default, each event is considered interactive (affects the bounce rate). The values are “true” or “false”.



Events Category in Google Analytics

Universal vs. Classic

Personally, I use Tag Manager, which makes Google Analytics implementation much easier, but for the purposes of this article, I’ll be only talking about implementation via a JavaScript snippet.


Nowadays, you can encounter two versions of tracking codes:


  • Classic Google Analytics

  • Universal Analytics


The snippets below represent the minimum configurations required for tracking pageviews. It’s essential to know which tracking code is used because the event syntax is different for each version.


Classic Google Analytics

Classic Google Analytics tracking code is ga.js. It’s an older version of tracking code, and if you still use this version, I’d recommend upgrading to Universal Analytics.


<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-XXXXX-X’]);
_gaq.push([‘_trackPageview’]);
(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

Event Tracking

_gaq.push([‘_trackEvent’, ‘category’, ‘action’, ‘label’, ‘value’, ‘false’]);

For a more detailed description of the code, visit the official Google Event Tracker Guide.


Universal Analytics

Universal Analytics tracking code is named analytics.js, and this tracking code was brought out of beta on April 2nd, 2014. It’s been over two years, so there is no reason to use Classic tracking code.


<script>
(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,’script’,’https://www.google-analytics.com/analytics.js’,’ga’);
ga(‘create’, ‘UA-XXXXX-X’, ‘auto’);
ga(‘send’, ‘pageview’);
</script>

Event Tracking

ga(‘send’, ‘event’, ‘category’, ‘label’, ‘value’, {nonInteraction: false});

More information can be found in the Event Tracking guide for Universal Analytics.


Why use a Google spreadsheet?

It helps you stay organized. Will you remember all event categories and actions you implemented in the last 3 months? I won’t, and for that reason, I keep records of everything I do. If you plan to extend your site, there is nothing easier than opening the spreadsheet with all events on the site and getting familiar with the tracking in a couple of minutes. Then, you’re ready to adjust the tracking and stick with the event naming strategy.


How to use the Event generator

  1. Choose the version of the tracking (Classic Google Analytics vs. Universal Analytics) in B2.

  2. Set up the global object in D2.

  3. Any changes in the first two steps will modify the tracking code (column G) automatically.

  4. Create your events by specifying event category, event action event label, and event value.

  5. Insert events to the source code (e.g., onclick event).

  6. Track the status:

    1. Suggested – This event is NOT implemented in the source code.

    2. Implemented – This event is implemented in the source code.

    3. Working – This event was successfully tested and is being recorded in Google Analytics.





Global Object

Don’t change the global object, unless you know what you’re doing. In most cases, the global object should be “ga” (no quotes). If your site is powered by WordPress and you use Google Analytics by Yoast plugin, then your global object will be “__gaTracker”.


If you are not sure which global object is used, take a look at the source code.



Google Analytics Global Object

How to debug event tracking?

Make sure everything works properly every time you implement a new piece of tracking. Debugging is a topic that should be covered in a blog post on its own, so I’ll mention a couple of great Chrome extensions that make it easier:



I’m just scratching the surface here, but both tools are extremely handy when your event tracking is not working.


Conclusion

There is no point spending time with event tracking if nobody is going to use the data. Also, a lot of marketers want to track everything on the website, but then they get paralyzed by the amount of data. Before you start to implement anything, take some time to create a plan. Determine which metrics are important and why. Then, it will be obvious which actions to track. Last, make sure you decided how and who will report the data.




Comments


bottom of page