Articles in The 'custom variables' Tag


March 1 2012

As Easy As 1, 2, 3: Custom Variables – Part III: Visitor Level

by Jarret Streiner

In Part I of this series we spoke about session level variables. In Part II we discussed page level variables. Now we are going to talk about Visitor Level variables. This variety of variable is the highest of the three levels; the tag assigned is permanent and remains disassociated during following visits until the visitor deletes the cookie or overwrites it’s value.

Visitor-level custom variables are used to differentiate the type of visitors who access your site across multiple sessions, such as a member, account holder, visitor or guest. You can make use of this variable to evaluate which users are paying members, what type of membership they have (if you have multiple levels), and visitors who are only guests. This custom variable would be set as a one-time function, given that the value would be carried across the life of the visitor cookie.

Visitor Level Variables follow these coding guidelines:
_setCustomVar(index, name, value, opt_scope)

The coding set up would look like this:
_gaq.push([‘_setCustomVar’,
1, // This custom var is set to slot #1. Required parameter.
‘Member Rate’, // The name of the custom variable. Required parameter.
’12 Months’, // The value of the custom variable. Required parameter.
// (possible values might be Free, 3 Months, 6 Months, and 12 Months)
1 // Sets the scope to visitor-level. Optional parameter.
]);

The finished coding would look like this:

<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-XXXXXX-1’]);
_gaq.push([‘_setCustomVar’,1,’Member Rate’,’12 Months’, 1]);
_gaq.push([‘_trackPageview’]);
(function() { var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’; var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s); })();

</script>

Now that you have set your variables and are tracking them, it is time to see the results. You can find your reports in Visitors > Demographic > Custom Variables report.

The report will display your variables as a “KEY”. There are 5 keys available with 5 values attached to each key.

During our three part series on As Easy as 1, 2, 3: Custom Variables, we have learned how to define additional segments to apply to visitors, about coding parameters, where and how to use each variable and how the different levels; Session (Used to distinguish different visitor experiences across sessions), Page (Used to define a collection of page-level activities by your users) and Visitor (Used to distinguish categories of visitors across multiple sessions) are unique.

We had a look at the reports and the type of information you can choose to add to your data flow. With custom variables, you can label additional segments to apply to your visitors in addition to what is already provided by Google Analytics.

February 23 2012

As Easy As 1, 2, 3: Custom Variables – Part II: Page Level

by Jarret Streiner

In Part I of this series we spoke about session level variables. There are two additional types of Custom Variables available for you to use Visitor Level and Page Level. In this post we are going to look at Page Level variables.

A Page Level variable is the activity of the user; which can be a pageview or an event, such as a pdf download or a video view.

One way of using page level variables is to track which areas or categories of your site that visitors are going to. We will use the example of a clothing company that has divided up their products into three areas: Long-Sleeve Shirts, T-Shirts and Dress Shirts.

The clothing company is thinking of having a sale, but they want to determine which areas or categories of their site, not just which pages, are driving the most traffic. If you look at the example, under clothing, there are three types of shirts listed; these three areas will be the “sections” of the site that will use the page level custom variable.

When labeling variable parameters, the naming convention is your choice. I chose “sections” for the name variable in these examples.You could use any naming convention, but a good rule of thumb is to keep them short and concise.

Your script will use the basic method for creating a custom variable as follows:
_setCustomVar(index, name, value, opt_scope)

The index, name and value parameters are required while the opt_scope parameter is optional, but it 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). If left undefined, the custom variable scope defaults to page-level interaction.

Using the code example below, the clothing company would use the session parameter to set which areas or categories of their site they would like to track. They would then place the coding on each page that displays Long-Sleeve Shirts, T-Shirts or Dress Shirts.
Example of the Custom Variable coding structure:
_gaq.push([‘_setCustomVar’,
1, // This custom var is set to slot #1. Required parameter.
‘Section’, // The top-level name for your online content categories. Required parameter.
‘T-Shirts’, // Sets the value of “Section” to “T-Shirts” for this particular aricle. Required parameter.
3 // Sets the scope to page-level. Optional parameter.
]);

When you install the code it should look like this:

<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-XXXXXX-1’]);
_gaq.push([‘_setCustomVar’,1,’Section’,’T-Shirts’, 3]);
_gaq.push([‘_trackPageview’]);
(function() { var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’; var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s); })();
</script>

After the code is implemented you will be able to find the custom variable reports under Audience>>Demographics>>Custom Variables.

For any single page, you can set up to 5 simultaneous custom variables, in which you can collect more useful data.

<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-XXXXXX-1’]);
_gaq.push([‘_setCustomVar’,1,’Section’,’T-Shirts’, 3]);
_gaq.push([‘_setCustomVar’,2,’Gender’,’Mens’, 3]);
_gaq.push([‘_setCustomVar’,3,’Size’,’Large’, 3]);
_gaq.push([‘_trackPageview’]);
(function() { var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’; var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s); })();
</script>

If you look at the code example above, the Custom Variables that will be pulled are:
Section – T-Shirts
Gender – Men
Size – Large

In our last post in this series, coming soon, we will be discussing Visitor-Level Custom Variables.

February 16 2012

As Easy as 1,2,3: Custom Variables – Part I: Session Level

by Jarret Streiner

What is a custom variable and when do I use it? Custom variables are tags that you insert into your tracking code that allows you to be able to filter your Google Analytics tracking down to certain segments of your site. You will be able to define those sections and segment your visitors to get a better understanding of how they use your site. Running custom variables will allow you to gather data that Google Analytics does not provide in their standard set of reports.

We are going to look at custom variables in three parts. This post, Part I is on Session-Level variables or the period of time during which the visitor is active on the site. To track the actions of the visitor during their session, the actions are stored in a cookie which is deleted when the session cookie expires.

The most common use for this custom variable is for logged in members versus anonymous visitors.

As you are able to set up an assortment of custom variables to track user activity for your site, you’ll usually create your own JavaScript utilities to manage them. Your script will use the basic method for creating a custom variable as follows:

_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.

Example of the Custom Variable coding structure:

_gaq.push([‘_setCustomVar’,
1, // This custom var is set to slot #1. Required parameter.
‘User Type’, // The name of the custom variable. Required parameter.
‘Member’, // Sets the value of “User Type” to “Member” or “Visitor” depending on status. Required parameter.
2 // Sets the scope to session-level. Optional parameter.
]);

When you install the code it should look like this:

<script type=”text/javascript”>// <![CDATA[
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-XXXXXX-1’]);
_gaq.push([‘_setCustomVar’,1,’VisitorType’,’Member’, 1]);
_gaq.push([‘_trackPageview’]);
(function() { var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’; var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s); })();
// ]]>
</script>

The total combined length of any custom variable name and value may not exceed 64 bytes, which is not the same as characters. A space is coded as %20 which is 3 bytes, not 1.

Once your code is implemented you can find the custom variable reports under Audience>>Demographics>>Custom Variables.

Noteworthy

  • Do not use duplicate key names across slots.
  • You have up to 5 simultaneous custom variables for use in a single request (e.g. pageview or event call).
  • Call the _setCustomVar() function when it can be set prior to a pageview or event GIF request.
  • Use a slot matrix to track large numbers of custom variables.
  • Consider using Event Tracking for certain applications, rather than custom variables.
  • Don’t use session-level variables to track behavior you can track with page-level variables.

In our next post we will be discussing Page-Level Custom Variables.

© 2023 MoreVisibility. All rights reserved.