Advertisement
Other

Quick Tip: The Power of Google Analytics Custom Variables

by

Familiarity with your users and their needs is the most important aspect of any successful site or web campaign. Google Analytics is the perfect tool to gather this sort of information. But there's much more you can find out about your users when you begin using custom variables to make better decisions.


What are Custom Variables?

Using custom variables carries huge potential, as it allows you to acquire information about the behavior of your visitors.

You can treat custom variables as your own extension of metrics and dimensions. These provide you with the ability to gather non-standard and detailed data, which are not available via the Google Analytics panel.

Using custom variables carries huge potential, as it allows you to acquire information about the behavior of your visitors, which, in total, can significantly contribute to an increase of the ROI (return on investment) of the website or e-shop.

For example, using custom variables makes it possible to differentiate the activities of the logged in users versus those who never signed in. This provides an opportunity to observe the behavior of the website designed for a particular target group. For instance, we can learn which page of our website is the one that males - aged between 20 and 30 - visit most frequently. And this is just a tiny piece of the information that can be stored with the help of custom variables.


So How do Custom Variables Work?

The functionality of custom variables is wonderful in its simplicity. In fact, it's based on the simple fact that, while performing a pre-defined activity, the user is labeled and the information about this label is subsequently stored in a cookie. Then, on the basis of this particular label, we can create a new section in the statistics of the Google Analytics panel.

Custom variables can be used in one of three ways:

  • page-level – this is the lowest level used to monitor particular ways in which the visitor interacts with the web page (e.g. AJAX, watching a video etc.)
  • session-level – a label attached to this level is added to the actions of the visitor throughout the session, and is deleted when the session cookie expires.
  • visitor-level – this is the highest level; the label is permanent and remains detached during subsequent visits until the visitor deletes the cookie or overwrites the value.

How Do I Configure Custom Variables?

Custom variables are quite easy to configure; you only need to add one line of code before the _trackPageview call.

_gaq.push(['._setCustomVar,INDEX, NAME, VALUE, OPT_SCOPE']);
  • INDEX (required) – determines a slot for a custom variable in Google Analytics. There are 5 slots available, numbered 1 to 5. You should remember that, if the variables are to function correctly, a single variable must be placed in a single slot.
  • NAME (required) – is the name of the variable that is going to appear in the report of the Google Analytics panel – Custom Variables
  • VALUE (optional) – is the actual value of the variable which is paired with NAME. Any number of such value pairs is possible, for instance if NAME=country, VALUE can, one by one, equal the values of US, GB, PL etc.
  • OPT_SCOPE (optional) – is a level within which a custom variable functions. As I described above, there are three levels: 1 (visitor-level), 2 (session-level), 3 (page-level). When this parameter is not provided, it is replaced with the default page-level.
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount','UA-xxxxxxxx-x']);
        _gaq.push(['._setCustomVar,INDEX, NAME, VALUE, OPT_SCOPE']);
       _gaq.push(['_trackPageview']);

Some Practice

Now, let's review how custom variables function in practice. Let's suppose that we want to keep track of the visitors of our website's - distinguishing between those who did and did not log in. In order to do so, before the _trackPageview call, we insert code describing the user.

_gaq.push(['._setCustomVar, 
			1, 			    // first slot
			'user-type',    // custom variable name
			'visitor', 	    // custom variable value
			2			    // custom variable scope - session-level
			]);


Once the visitor logs into your website, we change this code, accordingly:

_gaq.push(['._setCustomVar, 
			1, 			    // first slot
			'user-type',    // custom variable name
			'regular-user', // custom variable value
			2			    // custom variable scope - session-level
			]);

But What Follows?

It's time to present the results of the described script. After the script had been executing for a week, an advanced segment in Google Analytics panel was created. Its aim is to divide the data in the panel into: total, report for logged-in users, and report for users who didn’t log in for particular metrics.

The segment itself is created through Advanced Segments => Create a new advanced segment. Then you should set the dimensions according to the screenshot below:

The variable which we defined using JavaScript was in the first slot, so we have to select Key 1 and Value 1. Then, we set the key which we are interested in (user-type), and the value for the defined key (visitor) together using concatenation. Next, we name and test the advanced segment. The number of visits during a particular period of time for particular segments will be calculated within the test.

We define the second segment which takes into account the logged-in users in the same way. We can create it by analogy with the pattern presented above - with the difference in that the custom variable is set as regular-user.

After establishing the two segments, we can activate them. The result is presented below. Such a set of data is a great basis for an in-depth analysis of the activities on a webpage.


It's Worth Remembering...

  • Don't duplicate the names of custom variables between the slots.
  • Set custom variables before the pageview call.
  • You cannot use more than five custom variables in a single request.
  • Consider event tracking instead of custom variables for some demands, as then no additional (false) pageviews are generated in the panel.
  • You can determine whether custom variables work by observing requests within Firebug, or with the help of the Chrome extension, Google Analytics Tracking Code Debugger.

This is Only the Beginning

Using custom variables translates into more justified and accurate site decisions.

The example presented in this article only illustrate the process of using a single custom variable, and determining the best way to manage a website, according to the type of visitor. Of course, this is only the beginning. Custom variables can become incredibly powerful when we combine several of them at the same time. As a quick example, with the applicable data from a website's registration process, we can then track, not only the sex of the visitor (session-level), but also his or her age bracket (session-level). Further, we could divide the visitors into groups who have made purchases in our fictional eShop, or even track those who took a specific action, such as clicking on a Facebook button.

These techniques translate into more justified and accurate site decisions.

Related Posts
  • Code
    JavaScript & AJAX
    JavaScript ObjectsCover
    In JavaScript, objects are king: Almost everything is an object or acts like an object. Understand objects and you will understand JavaScript. So let's examine the creation of objects in JavaScript.Read More…
  • Business
    Marketing
    A Smart Guide to Landing Page OptimizationLanding page optimization
    Landing pages are a great way to convert your website traffic into users, email subscribers, or customer leads. In this smart guide to landing page optimization, learn how to apply proven strategies that will help you convert a higher percentage of your site visitors.Read More…
  • Code
    Creative Coding
    Using WordPress for Web Application Development: Features: SessionsApplication foundation 400
    In this series, we're taking a look at how it's possible to build web applications using WordPress. Thus far, we've talked about how WordPress is a foundation (rather than a framework), its architecture, how we need to conceptually think of it when approaching it especially coming from other languages, and then we began talking about the components that make up a basic web application.Read More…
  • Business
    App Training
    Squarespace Activity and Google Analytics ComparedPreviews squarespace activity and google analytics compared
    Over the course of this series, we've set up a complete online presence using products such as Squarespace and Google Apps to provide rock-solid web and email services with almost no configuration and zero maintenance required. In this part of our series, we'll show you how to gather analytical information about your Squarespace site's visitors, as well as comparing it to Google Analytics.Read More…
  • Business
    Marketing
    Minimally Viable Google Analytics Conversion TrackingPreview minimally viable google analytics setup graphic
    Have you heard of Google Analytics? 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? If you have, then you know that Google Analytics can give you a lot of amazing insights into your business. 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. It requires a little tweaking. 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, what are you using it for?Read More…
  • Business
    App Training
    How to Install Google Analytics on WordpressPreview install google analytics on wordpress
    Have you heard about all the powerful insights Google Analytics can churn out for your business? (Here are just 3 Google Analytics insights you can learn about your business.) If you haven’t heard about Google Analytics, it’s an amazing, free tool you can use to track everything related to your website visitor data - from how many, to where they’re coming from, to what they’re doing on your website (and what’s making them leave!). If you have heard of Google Analytics and its powerful insights, you know that installing it on your site is a must do item. If you're a Wordpress user, I have a secret for you: installing Google Analytics on your Wordpress site involves very little code. We can install Google Analytics easily. Sound good? Let’s get to it.Read More…