As we saw last week the custom variables feature in Google Analytics is revolving around the _setCustomVar() method. Typically you will call _setCustomVar() before a _trackPageview() or a _trackEvent() so that the information get delivered with the GIF request sent by _trackPageview() or _trackEvent().
Here is an example:
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
<script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
pageTracker._setCustomVar(1, "pagetype", "productpages" , 3 );
pageTracker._setCustomVar(2, "productcategory", "officefurniture" , 3 );
pageTracker._trackPageview();
} catch(err) {}<script>
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
<script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
pageTracker._setCustomVar(1, "pagetype", "productpages" , 3 );
pageTracker._setCustomVar(2, "productcategory", "officefurniture" , 3 );
pageTracker._trackPageview();
} catch(err) {}<script>
This is the typical script you will put at the end of the page before the tag. As we can see we defined two variables “pagetype” and “productcategory” and gave them the values “productpage” and “officefurniture” (all at the page-level scope since last argument of setCustomVar is 3).
How can I track results?
The Custom variables data can be integrated in 3 different report types:
- The Custom Variables report (in the Visitors section in the main menu)
- The “Advanced Segments”
- The “Custom Reports”
The Custom Variables report
While it normally takes only few hours for all reports to be updated, the custom variable report takes a bit longer. To my experience this is roughly around 48 hours. The first time you will run the report you will see a “not set” message in the first column. Do not panic, just be patient. Eventually you will be able to see the data.
As you can see in the pictures, if you click on the variable name you will drill down to the different values.
The advanced segments report
The advanced segment report is an incredibly powerful feature. If you have never used it I recommend checking the Google conversion university and have a look to the corresponding “Advanced Segmentation” presentation.
When you create the custom segment you will find new dimensions in the “visitor” section. Basically two sets:
- Custom variable key
- Custom variable value
Each one numbered from 1 to 5, and corresponding to the variable slot.
The Custom Reports
Exactly like in the advanced segment reports you will find two new dimension types:
- Custom variable key
- Custom variable value
Each one numbered from 1 to 5, and corresponding to the variable slot. See an example in the previous picture
Next part
Next week we will see the in details the different reports and the differences between the variable scopes in practical measurements.







2 comments: