Custom Variables in Google Analytics

Custom Variables in Google Analytics

In our last two posts, we learned:  to setup a Google Analytics account; add a tracking code to each page of our website; and setup valuable goals and track custom events and social events.

In this post we will learn about custom variables in Google Analytics, how they differ from custom metrics and dimensions, and the limitations of using them.

What are Custom Variables in Google Analytics?

According to the Google Developer’s portal:

“Custom variables are name-value pair tags that you can insert in your tracking code in order to refine Google Analytics tracking. With custom variables, you can define additional segments to apply to your visitors other than the ones already provided by Analytics.”

In other words, we can further categorize our users, based not only on predefined Google Analytics parameters, but also based on our own parameters. For example, we could segment our visitors based on the answer to a question: Do they prefer dark or milk chocolate? Based on their answer we can compare the two types of respondents inside our Google Analytics platform.

The beauty of creating custom variables is that you can analyze the behavior of a particular type of user.

However, when you use the Universal JS code, custom variables are called custom metrics and dimensions.

So what are the differences between custom metrics and custom dimensions?

Custom Metrics and Dimensions

Metrics are quantitative measurements:  if you can calculate something based on your custom value, then it is a metric. Things like minutes, number of sessions, and number of page views are metrics.

Dimensions are parameters that describe the user, session, or event. For example, the dimension of city holds values like: “Paris” or “London”.

Limitations of Custom Metrics and Dimensions

Perhaps the most important limitation of custom dimensions is that they can’t be deleted. You can disable them, but it is best practice not to reuse them for something else.

20-metrics

There are only 20 indices available for custom dimensions and 20 indices available for custom metrics per property. If you need more than 20 you can sign up for a Google Analytics Premium account that provides up to 200 indices for each property.

Now you know the difference between dimensions and metrics, and their limitations.

 

Implementing Custom Metrics and Dimensions on a Website

First, you’ll need to set up the custom dimension or metric inside your Google Analytics platform:

Log into your Google Analytics platform and click “Admin”.
Select the property you want to add the dimension or metric to.
Click on the “Custom Definitions” button. (see image below)
Custom Definitions Google Analytics
Select either “Custom Dimensions” or “Custom Metrics” depending on what you’d like to define.

Four Steps to Setting Up a Custom Dimension

Click on the “New Custom Dimension” button at the top. (see image below)
New Custom Dimension
Give it a name that summarizes the batch of information you are capturing.
Define a Scope. Read more about scopes in the Google Analytics developer guide.
The scope would be one of the following:


Hit
Session
User
Product
Check the “Active” box to start collecting custom dimension data and seeing it in your reports. Remember that you can return to the checkbox and make the dimension inactive. However, you won’t be able to modify it to capture different information.

Three Steps to Setting Up a Custom Metric

Select a Scope and Formatting Type (Integer, Currency, or Time).
You can also input a minimum and maximum value to capture.
Click “Create”.

The Code

Once you’ve created the custom dimensions and metrics in your property’s admin section, you’ll modify the tracking code. (NOTE:  This part is a bit more complex, so make sure that you understand how to modify your environment before proceeding, or ask for help.)

Note the index that identifies your custom metric. For example, if you’re sending data for a “pageview” hit with the index of “2”, and the data is “London”, the code looks like this:

    ga(‘send’, ‘pageview’, { ‘dimension2’ : ‘London’ }); 


In our custom metric, let’s say that visitors to  our website fill out a contact form. Then they select whether they’re interested in information about middle school or high school. You can modify the tracking code to segment the visits based on their selection by creating a dimension called “School Preference”. Depending on the number of dimensions that you have in place, Google Analytics will assign your new dimension an ID number between 1 and 20. In this case let’s say that the dimension was assigned an ID number of “4”, so the code would look like this:

    ga(‘send’, ‘pageview’, { ‘dimension4’ :  “<?php print $school_preference; ?>” }); 

NOTE:  In this example I use PHP to print the variable named “school_preference” that holds the actual value of the selection in the form.

 

You’re done! Now you can create custom metrics in your properties and understand your users at a higher level of complexity.

If you have any questions or comments about Google Analytics or how to better market your business online, we would love to hear from you. Please contact us today!

Share and follow us on social media:
RSS
Twitter
Visit Us
Follow Me
LinkedIn
Share
INSTAGRAM

Subscribe now for useful information from AndiSites:

* indicates required

You might also enjoy

How Can We Help You?

We listen. We're different. You'll see.