New site: Womens Conference 2010Internet Explorer 6,7 & 8 trends in 2009

Custom Variables in Google Analytics

customVariablesTNHaving seen that Google Analytics was updating their custom segmentation function to custom variables I decided to try to figure out how to configure them. You would think this would be easy. Not so much.  So I consulted the Help section in Google Analytics. While it provided a lot of usage details and gave some code examples, it didn’t give you a good idea of where exactly in the code you would put the code snippet. Say, for example, I was putting the custom variable tag on a hyperlink, it didn’t show where in the link it should go or how it should be configured. Also, it didn’t tell you if you had to modify your existing GA tagging code. All very frustrating. I tried several different configurations but never met with any success.

What I did was test it on this site. I created a post in WordPress and added a link to the post and placed the code in the link the way I thought it should be configured by reviewing the help files. I am using the new asynchronous tracking code so my visits were coming in fairly quickly. Within an hour or two I was seeing my visit show up. But when I clicked on Custom Variables in the navigation it always showed nothing. Frustrated, I Googled ‘custom variables in Google Analytics’ and several other search terms to see if someone else had figured it out and I could reverse engineer their code to fit with mine. Unfortunately, I came to no success there. Still  no results under Custom Variables in my account. So I decided to post a question in the forums. After a couple days a user named nathanziarek replied and helped me out figure out where the code should be and how it should be configured. Instead of trying to explain it all here I’ll just link to the forum thread and you can read the back and forth exchange we had.

In the end it ended up that there were some single and double quote issues going on with the variables and adding the custom variable code snippet to the main GA tracking code.

Below you’ll see two tests that were successful. I was trying to set a custom variable on a visitor when they clicked the age range. It was a basic test to see if I could get results. Ultimately, the goal would be to be able to use this data to see what people in either certain age ranges, gender, salary range, etc were doing when they were on my work’s site. We would set up a form for them to fill out and tag the form fields with the custom variable code. We would set the variable to be a visitor level cookie so that it’s set for the life of the visitor (or until they delete their cookie).

You can set three types of custom variables in GA:

  • Page-level: A single pageview, event, or transaction call.
  • Session-level: The session of the visitor.
  • Visitor-level: The life of the visitor cookie. When set, applies to all visits onward (but not to previous visits or current visit).

I think that last part in parenthesis was what messed me up for the first couple days of testing. I didn’t realize it didn’t apply to the current visit. So I’d change the code, publish the changes, go to the site and click the link. Then I’d wait and look in GA after a few hours. Had I read that sooner I would have made a second visit to the page and clicked the link to generate the visit.

I’m still not sure why you can only have five slots for Custom Variables but I’ll figure it out soon.

I hope this helps anyone trying to work with Custom Variables in Google Analytics and is having a hard time. You can view the source on this page and see how the code is configured.

Here are the test links I was working with:

10-20

12-23 test

Back to Top

Write a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>