Tracking Events in Google Analytics

Understanding the crowd

I’ve seen some very overly complicated Google Analytics configuration in my career. I think the most complicated and labor intensive setups is when people use Google Tag Manager. It’s a “hands off” way to setup tracking in that you can have someone do it for you without access to your web site’s code base. So that’s cool…But the cool factor wears off right there.

When you setup Google Analytics using the Tag Manager you have a lot of complex rules setup and these configurations get versioned. They need to be. Why? Because the maintenance burden is extreme and the configuration is delicate.

Worse yet, if the developers aren’t communicating with the analytics team then they are likely to make a change on the site that completely throws off analytics until changes can be made to the configuration in Tag Manager.

So I highly recommend not using Tag Manager for those reasons. What you really need to do is use JavaScript on the page. This way your developers can take that code into account when they make code changes so things continue to work and track as expected. I know this is less than ideal for some folks who aren’t able to write JavaScript, but hire a contractor to do it if need be – it’s worth it.

Custom Events

In my opinion custom events are one of the most important features of Google Analytics. Most of the questions I find people with about their users and web site traffic comes down to behavior. What actions did visitors take on the site? Did they share the content from sharing buttons? Did they actually read my content? These and many other questions can be tracked through custom events.

There are a few analytic services out there that will provide some of these answers, but they are costly in my opinion. You have a free tool right here with Google Analytics that can do the same exact things, but only if configured. There’s two parts to setting this up.

The JavaScript on Your Site

First, you’ll need to actually track the events using JavaScript on your web pages. Google has great documentation on this here. Essentially you’ll be calling ga('send', 'event', 'category', 'action', 'label', 123) where that last argument (123) is an optional count value. Typically this is left empty when you’re talking about things such as a “read” or a “share” because on each event that triggers this call, you’re only talking about one event.

The other values, category, action, and label are where you need to focus. There’s no hard and fast rules here as these values can be practically anything. Typically people tend to use the category for the object in question; the “page” or “button” for example. While the action is a little more obvious and often is used for; “click”, “read”, “share”, or “navigate” for example. Finally, this leaves the optional label which is often used for additional detail.

For example, you could track a Facebook share event like this:

  • category: page
  • action: share
  • label: facebook

Note: Google Analytics has a separate call specifically tailored for social media sharing, though events could also work and I’m going to continue using sharing (maybe it’s via e-mail and not social networks) for these examples. Read more about Google Analytics Social Interactions.

The JavaScript would be attached to a listener on a Facebook share button on the page. Since this pops up in a new window, the event gets sent to Google without worrying about the user navigating away before it has had a chance to process. Of course there’s no way to confirm the user actually followed through with the share, but we know the user had the intent and actually clicked the button.

So what if the user is leaving the page? Well, here’s where you’ll need to be a little bit more clever with the JavaScript. It is possible to interrupt the browser and log the event, then re-trigger that event to allow the user to continue along. This will happen quickly enough that the user shouldn’t notice any real delays in their navigation.

So we can track outbound links as well. This is something a bit more advanced that is harder (if even possible) with Tag Manager. There’s a feature that some browsers have that will continue to log that event after the browser has changed pages, but it’s not fully supported across browsers.

So again, your best course of action is custom JavaScript.

The Setup in Google Analytics

The second part here is configuring your Google Analytics reporting. This is pretty straight forward and is certainly less complex than working with Tag Manager.

You’ll notice boxes in most reporting screens that say “+ Add Segment” and these are likely your most important feature here. Not only can you see reports for many different segments of traffic such as geo-location, browser type, and more…But you can also create segments based on your custom events.

Google Analytics Create Segment

You’ll need to create a new segment and go to “Conditions” under the “Advanced” section on the left. Click on the first drop down on the new condition, start searching for “event” and you’ll see options for category, label, and action.

It should be pretty straight forward from here. Let’s say you choose “event action” in this case. The next drop down will say “contains” by default which is fine for our needs. You’ll go to the input field to the right of that and find you have a handy autocomplete input. You should be able to find your action with ease.

Then continue on to add more filters as needed. You may want to add a second one now for the “event label” with a value of “facebook” in this case. Now you’ve created a segment for Facebook share events.

You can name these segments anything you like so it’s easy to find and use later.

Using Segments

Now that you have configured both the web site to send events and the reporting segments based on those, you’re ready to actually make use of this data.

In Google Analytics, you can apply a segment to most any report. So if you wanted to see which pages were most shared, that’s be pretty easy at this point.

Go to “Behavior > Site Content > All Pages” and add a segment you setup earlier. They’ll be under the “Custom” section. Going along with our example, choose your Facebook share segement. Next, remove the “All Sessions” segment that’s there by default.

Now you’re just looking at pages with Facebook share actions and you can easily sort by “Pageviews” column. The language here is a little confusing, but this is actually a count of events. More accurately, it is a number of pageviews from unique sessions where your custom event occurred.

Google Analytics Segment Example

So if you’re tracking actual users by giving Google Analytics custom user IDs, then you could instead adjust your segment filters to take into account actual users instead of sessions. This might provide you with a little more accuracy since sessions expire after a certain (configurable) amount of time. Though I’m going to go out on a limb here and say that most visitors won’t be sharing multiple times through those share buttons so it’s likley OK to leave it as is and not worry.

Cool! You now have nearly every facet of Google Analytics filterable by your actions. You can really see which content is stands out on your site now. Not just by page view, but by the actual actions take on the page. This is true engagement. So what else can we do?

Remarketing

One of the biggest advantages Google Analytics offers you with segments is the ability to remarket to them. If you click under any report on the little gray down arrow on any segment you’ve applied, you’ll see a “Build Audience” menu item.

This allows you to target Google ads to these segments of users. Extremely powerful.

Why? Well, if you know a user is taking certain actions you can better target them with leading ads that help bring them back to your site or product. It might make the difference between closing a deal and letting a user forget about you.

The other important thing to realize here is that your ads will now be more effective and your ROI will be higher because you aren’t just advertising blindly to the world. You could really be targeting people on the fence so to speak.

Final Thoughts

I covered a good deal of information and there’s actually so much more, but this should get you started. I think custom events are one of the single most important things to setup in Google Analytics to be honest. I’d even put it ahead of setting up goals and complex funnels because you can’t really setup good funnels without good segments defined by specific events. They’d be too wide otherwise.

I know for many people setting up the JavaScript on the web site is going to be a challenge. I hope to release a little script that can easily be included on your web sites that would help with a few basic segments and make it all easier. Keep an eye out for that. I think there’s a lot of automation that can be put to work here and even some machine learning and natural language processing.

For example, why can’t I build a script that, when placed on your site, knows which pages are actually blog posts? Then once it knows the page is a blog post, it could easily put into place an event that would track an actual “read” by condition of how far a user has scrolled down on the page and how much time they spent on the page.

Why couldn’t I put simple rules into place that checked for the Facebook and Twitter share URLs and then wathced those links for click events to then track the share events? I certainly could.

Again, I’ll be working more on this and will write about it in the future. As always, if you have any questions or anything to add, please comment below.

Tags// , ,
comments powered by Disqus