Google Analytics Custom Tagging – Part 2

0 Share47

Google Analytics Custom Tagging – Part 2

Going Beyond the Code Snippet As I mentioned in my last post, there are plenty of other kinds of tracking that can be done beyond the basics with Google Analytics. In that post I ...

Woman Editing CodeGoing Beyond the Code Snippet

As I mentioned in my last post, there are plenty of other kinds of tracking that can be done beyond the basics with Google Analytics. In that post I covered in detail how to do eCommerce and Campaign tracking. In this post I’ll be going over a couple more areas of tracking that require customized tracking codes: Event Tracking and Custom Variables.

Event Tracking

If you use videos, flash, or other types of interactive, rich media experiences on your site, you will need to use Event Tracking in order to gain the most insight into how well these elements are performing. Event tracking can also be valuable in terms of tracking outbound links on your site.

Setting-Up Event Tracking (Source: GA Event Tracking Guide)

Before you can view event tracking results in your reports, you must set it up on your site following these steps.

  1. Set up tracking on your site. Make sure you have set up tracking for your website. For information on setting this up, see Tracking Sites.
  2. Call the _trackEvent() method in the source code of a page object, widget, or video.
    The specification for the _trackEvent() method is:

    _trackEvent(category, action, opt_label, opt_value, opt_noninteraction)
    • category (required) – The name you supply for the group of objects you want to track.
    • action (required) – A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object.
    • label (optional) – An optional string to provide additional dimensions to the event data.
    • value (optional) 0 An integer that you can use to provide numerical data about the user event.
    • non-interaction (optional) – A boolean that when set to true, indicates that the event hit will not be used in bounce-rate calculation.
  3. View the reports. Once event tracking has been set up and working on your site for a day, go to the Content section of the reports and view Event Tracking.

Understanding Event Tracking

Setting up event tracking is generally fairly simple, however there are a number of elements you need to understand. As seen in the above example, there are several components within each event to be tracked (category, action, label, etc.), and each one maps directly to elements in the Google Analytics reports.

Here are some examples of what this might look like in a real scenario.

Tracking a video:

  • <a href=”#” onClick=”_gaq.push([‘_trackEvent’, ‘Videos’, ‘Play’, ‘Baby\’s First Birthday’]);”>Play</a>

Here you can see the category=Videos, the action=Play, the label=Baby’s First Birthday, and it’s embedded in the anchor tag around a text link. This same code could be embedded into the ActionScript of a Flash file and be used to record the play, pause and stop, something like this:

  • _gaq.push([‘_trackEvent’, ‘Videos’, ‘Play’, ‘Gone With the Wind’]); 
  • _gaq.push([‘_trackEvent’, ‘Videos’, ‘Pause’, ‘Gone With the Wind’]); 
  • _gaq.push([‘_trackEvent’, ‘Videos’, ‘Stop’, ‘Gone With the Wind’]);

Tracking Links to External Sites

Another use for custom event tracking could be to track clicks to external sites, like social media links, on your site. For example if you have a link to share content on a page to Twitter or Facebook, your code could look like this:

  • <a href=”#” onClick=”_gaq.push([‘_trackEvent’, ‘Social Media Links’, ‘Click’, ‘Twitter’]);”>Twitter</a>
  • <a href=”#” onClick=”_gaq.push([‘_trackEvent’, ‘Social Media Links’, ‘Click’, ‘Facebook’]);”>Facebook</a>

Additional Uses for Event Tracking

Besides tracking videos and links to external sites additional uses for event tracking would be:

  • File downloads (by file name and/or type)
  • Specific link/button locations on your site
    • For example  you have a “register now!” button in several places on your site, and you want to know which button gets the most clicks
  • Any other unique event/action you want to track that isn’t being included in the standard reports.

Custom Variables

Custom variables will allow you to refine the level of detail you currently get from your data. They are most commonly created using your own JavaScript utilities to manage them, and this will require a certain level of JavaScript knowledge. I will admit, that this is an area I’m somewhat weak in. However, there are lots of resources online to help with writing the JavaScript. I will include some links below under Additional Resources.

Custom variables can be set up to track a wide variety of things on your site that can’t be tracked in any of the other methods I’ve discussed so far, however they often can support some of the types of custom tracking I’ve discussed.

  • For example, a custom variable can be set up to support eCommerce tracking by tracking how many times items are removed from a shopping cart.
  • Another use case for custom variables would be to track different sections of your site (for example About Us, Contact Us, Products, Services).
    • This is different than tracking traffic to just your “About Us” page – you may have several pages within your About Us section and you may wish to track how much traffic that entire section receives when compared to your other sections.
  • If your site asks for users to sign-up or register and then log-in to access member only content, you may wish to track how many logged in members vs. guests you have visiting your site.

The basis of the custom variable is:

_setCustomVar(index, name, value, opt_scope)

This method accepts four parameters:

  • index – The slot for the custom variable. Required. This is a number whose value can range from 1 – 5, inclusive. A custom variable should be placed in one slot only and not be re-used across different slots.
  • name – The name for the custom variable. Required. This is a string that identifies the custom variable and appears in the top-level Custom Variables report of the Analytics reports.
  • value – The value for the custom variable. Required. This is a string that is paired with a name. You can pair a number of values with a custom variable name. The value appears in the table list of the UI for a selected variable name. Typically, you will have two or more values for a given name. For example, you might define a custom variable name gender and supply male and female as two possible values.
  • opt_scope – The scope for the custom variable. Optional. As described above, the scope defines the level of user engagement with your site. It is a number whose possible values are 1 (visitor-level), 2 (session-level), or 3 (page-level). When left undefined, the custom variable scope defaults to page-level interaction.

To see detailed code examples of how custom variables are set up, please see the Example Use Cases in the Google Analytics Developers Guide.

Additional Resources

Here are some helpful resources to go beyond the examples I gave here:

Gabriele has been doing "Web Stuff" since the mid-1990s, and Web Analytics since 2005. She began with Omniture SiteCatalyst (now known as Adobe Analytics) and is now also well versed in Google Analytics. She has been building a team of professional analysts who have expertise in all the major analytics platforms, including Adobe Analytics, Google Analytics, IBM Coremetrics and WebTrends.