How to use Custom Variables in Google Analytics?

Each industry tracks its own analytic variables to measure key performance indicators. For e-commerce site it would be like “How many customers used the Holiday Discount Coupons”, for blogs it would be “The number of returning visitors after they have read a popular blog post”. Depending on your industry, you can create and track custom variables in Google Analytics. 

Why I need custom variables when I can use user segment?

User segments as the name suggests can only track variables at a visitor level. Also, you cannot track multiple values for the same variable. For example, if you want to track a variable LessThan40 (all visitors below the age of 40). Now you can’t store separate value for this variables based on Gender. Say all female visitors less than 40 or all male visitors less than 40. Of course, you can track it as separate variables but then it would be cumbersome to manage and track all variables, based on slight variations.

How can custom variables solve the problem?

To solve tracking multi-valued variables and to get details at visitor, session or page level, you need to use Custom Variables

Can you explain the difference between visitor, session and page level custom variables?

Visitor Level Custom Variables: can track clients that have visited your site. It can include the browser type, the device used to access the page(Computer/tablet device/mobile phone), the demographic information about the visitor, source of visit and other visitor level details that you see in Google Analytics(under Audience section of the new Google Analytics).

Session Level Custom Variables:  can track all events for which the client was active in your site. This variable is useful to track the user path in the conversion funnel. Has the user added your product in the shopping cart and left? Did they reach your contact page in that session? You can track micro-conversions with this variable.

Page Level Custom Variables: can track interactions like visit /a click/video view/Ajax event/flash event or any page specific interactions.

What code should I add to track custom variables?

All you have to do is to add one line of JavaScript code to make custom variables work

_setCustomVar(index, name, value, opt_scope)

index (required): refers to the slots where the custom variables can be placed. As of 2012, Google analytics allows only 5 slots so the index can have values ranging from 1-5. A variable in one slot cannot be reused in another slot.

name (required): refers to the name of the custom variable. The variable can only be a string and it is visible in the top level custom variable report in Google analytics panel. 

value (required): refers to the value of the variable, which is associated with the variable name. Remember the variable name-value is a key-value pair. Any number of values can be paired with the custom variable. This is where the issue that we have discussed in user-segment can be solved. You can include both male and female as values for the key –‘gender’.

OPT_SCOPE (optional): refers to the scope of the custom variable. There are three levels: 1 (visitor-level), 2 (session-level), 3 (page-level). The default scope is page-level.

What is the asynchronous JavaScript code to implement Custom Variables?

<script type="text/javascript"><![CDATA[

var _gaq = _gaq || [];

_gaq.push(['_setAccount', 'UA-AccountNumber']);





(function() {

var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);




How are Custom Variables tracked by Google and how can you make sure that the data tracked is accurate?

When a custom variable is set, the data is sent to Google Analytics server via a .GIF image request. This means that for page visits, after the last page visit, if a custom variable is set, that value will not be recorded by Google Analytics.

In order to avoid such scenarios, always set the custom variables before the _trackPageview() function like:



What are the limitations of custom variables?

The number of slots is limited to 5, which means that for a custom variable type if all the slots are filled, the data in the slot will be overridden with the latest variable value.

How can I see the custom Variable values in Google Analytics?

In Old Google Analytics: Click Visitors->Custom Variables

Custom Variables in Old Google Analytics

In New Google Analytics: Click Audience-> Demographics-> Custom Variables

Custom Variables New Google Analytics

If you want help in setting up Custom Variables for your website, contact us or you can call us at: India (Ph): +91 9497189032, UK (Ph): +44 (0)20-3371-9976 or US (Ph): +1 650-491-0004

ByteFive provides comprehensive Internet Marketing Services and Training in Search Engine Optimization, Search Engine Marketing (PPC Campaign Creation, Management and Optimization), Developing processes and best practices for Internet Marketing, Managing and Analyzing Web Analytics,  Landing page Optimization, E-Mail Newsletter Management, Competitor Research, Content Creation and Content Marketing.