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”.

Google Analytics Events

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 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

As usual, create your own copy (File -> Make a copy) before you get started.

  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:
    • Suggested – This event is NOT implemented in the source code.
    • Implemented – This event is implemented in the source code.
    • Working – This event was successfully tested and is being recorded in Google Analytics.

Google Analytics Event Tracking Generator

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.

Global Object in Google Analytics Tracking Code

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.

 

Open the Sheet

I'm an SEO Strategist who enjoys technical aspects of SEO and web analytics because you can't optimize anything if you don't measure it.
  • Patrycja Michałek

    Hi,
    I actually gave up coding some time ago. I found a tool to set it up without any code. You just need to click what you want to track and name it (traditionally with category, label etc.) It is chrome extension: https://pixpecker.io/
    I like it because it saves time and at the end you can see everything in your Tag Manger and create the report easily.
    I hope I helped someone. 🙂
    Take care!

    • http://rozhon.com/ Robin Rozhon

      Hi Patrycja,

      Thanks for sharing the Pixpecker. I have no personal experience with the extension you’re referring to and it may be useful for simple events. However, I assume that the extension has limitations such as form submissions, scroll tracking, etc.

      Is Pixpecker able to track contact forms? If so, is an event triggered as soon as a “Send” button is clicked or after the form validation?

      Also, it’s essential to have a solid understanding of code (or Tag Manager) for implementing enhanced e-commerce because I don’t expect Pixpecker being able to handle is either.

      Cheers,
      Robin

      • Patrycja Michałek

        Dear Robin,

        Thanks for the reply and questions. I’ve checked it and you are right with your assumption according to form submission and scroll tracking. PixPecker doesn’t have those features. It tracks the clicks on the button, but it doesn’t provided the option to make sure that all required fields are filled out when the form is sent.

        With E-commerce most of the sites have build in event tracking solution. However, with PixPecker it all depends on the program behind and what exactly you want to do.

        At the same time it helps you to set the tracking which is visible and coordinated with Google Tag Manager. For my needs it does the job, but I am not a profi in analytics.

        I hope I helped with my answers.

        Take care!

        Patrycja

        • http://rozhon.com/ Robin Rozhon

          Thanks for the info, Patrycja!