Upcoming LunaMetrics Seminars
Washington DC, Sep 22-26 Boston, Oct 6-10 Chicago, Oct 20-24 Seattle, Nov 3-7

20 Ways to Use Google Analytics Custom Variables

Google Analytics Custom VariablesThis is not a “How to Install Custom Variables” post.

I’m not going to bore you with a long rambling introduction to Google Analytics Custom Variables. We’ve talked about Google Analytics Custom Variables a few times on this blog, as we should… They’re an amazingly powerful way to get more out of your site data. Jonathan Weber’s early series from 2010 is still mostly valid though it uses the older traditional tracking code. If you need a primer, they’re a good place to start:

Google Analytics Custom Variables, Part 1: Why?

Custom Variables, Part 2: The Code

Custom Variables, Part 3: Slots

Also don’t forget what Michael Harrison laid out at the end of last year. Custom variables need to be in your code BEFORE a pageview or event is tracked, or they won’t work at all. Also the code he uses on this page is the current asynchronous tracking code format for custom variables:

Google Analytics Custom Variables Not Working?

And hey since I’m linking things, the best resource is usually from the source. Here’s the Google guide for Custom Variables.

 

https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables

Hopefully you can discern the basics from those articles, and others across the web about how exactly to use custom variables, how to segment your reports, etc. This post though is about specific ways to use them. it’s funny how often I’ll talk to a client who seems to understand that they’re very powerful, but can’t figure out ways to use them on their site.

So here are twenty different ways you can use custom variables. Five for each of the four main website types. Content sites, Ecommerce Sites, Lead Generation Sites, and Self Service sites.

Ways to use Custom Variables With A Content Generation Site AKA a Blog

Content sites rely on getting people to consume content, the more the better. So it’s important to be able to really parse out what content works, and what doesn’t.

Track Your Authors
If you have multiple authors, place a custom variable for that page and assign the author to it. This way you can segment visits that include that author, just look at that author’s performance, etc.

_gaq.push(['_setCustomVar',1,'Author','Sayf Sharif',3]);

Track The Categories
Same as the authors, track your categories, so you can see which ones do better than others, and where you should focus your efforts.

_gaq.push(['_setCustomVar',2,'Category','Google Analytics',3]);

Track Your Tags
You might uses tags on your site to boil down different non-category topics. This way you can see what tags and sub areas are interesting to people across various categories. Keep in mind though that if you set a custom variable at the page level, you can only have one, so you’ll have to pick one tag, not multiple.

_gaq.push(['_setCustomVar',3,'Tag','Custom Variables',3]);

Track Who Comments
Commenters are more likely to return to your site, and are more engaged. Track a default value of no on the visitor until they comment, they record they’re a commentor, and you can watch the behavior of these two types of users across the site.

_gaq.push(['_setCustomVar',4,'Commented','Yes',1]);
_gaq.push(['_setCustomVar',4,'Commented','No',1]);

track social sharer
You can track a specific type of social sharer, or you can just say “this is a person who has shared”. So whenever they click a link to share on twitter or Facebook, in addition to tracking that as an Event add in a custom variable either onto the user or a session. Now you know that THIS VISITOR has shared, and might do so again. That way you can see how many total users share, and see if it’s more than just the same 100 people sharing your content day in and day out.

_gaq.push(['_setCustomVar',5,'Social Sharer','Yes',1]);
_gaq.push(['_setCustomVar',5,'Social Sharer','No',1]);

Ways to use Custom Variables with an Ecommerce site

Ecommerce sites are different, you’re more interested in product performance, so we want to track different things with our custom variables.

Track The Visitor ID
Google Analytics doesn’t let you put in personally identifiable information, but it’s generally held that random visitor id’s that you can then compare with your own database outside of GA, are ok. so this way you can track the same visitor even when they’re not logged into your site.

_gaq.push(['_setCustomVar',1,'UserID','1234567890',1]);

Track Your Customer Loyalty
Tracking customer loyalty is a big thing. Start with a custom variable with 0 purchases and every time they make a purchase, increment the count. That way you can track different levels of purchase, and segment users as new users, returning customers, regular customers, etc. Just look at users who have more than 3 purchases vs users with only 2 purchases, etc.

_gaq.push(['_setCustomVar',2,'Purchases','6',1])

Track a Product View (with SKU)
Track which products your visitors view during their visit. some might not get purchased, but lead to other conversions, and other insights.

_gaq.push(['_setCustomVar',3,'View Product','SKU12345',2]);

Track the Number of Items in a Shopping Cart
Track the total number of cart items the visitor has. increment the count. This can help see how many abandoned carts there are, with specific information.

_gaq.push(['_setCustomVar',4,'Cart Items','4',2]);

Track a Customers Ongoing Value
Like the customer loyalty, but track their overall value. every purchase increment the ongoing value, so you can see which of your customers are your whales and how they react differently. Do customers who have made over $100 in purchases behave differently on the site than those that have spent less?

_gaq.push(['_setCustomVar',5,'Ongoing Value','3400',1]);

Ways to use Custom Variables with a lead generation site

Lead generation sites are all about getting people to contact you, so we don’t necessarily care about the same things a blog or a ecommerce site does.

Track Whether They’re a Lead or Not
Pretty basic, but if someone fills out an appropriate contact form, then track them as a lead. That way you can see the ones who come back, watch their behavior, etc. How do leads differ in their behavior on your site than non-leads? Is there a trick that gets people to convert?

_gaq.push(['_setCustomVar',1,'Lead','Yes',1]);

Track Newsletter Subscriber
Maybe they’re not a lead but subscribed to your email, see how often they come back, how the newsletter works, etc.

_gaq.push(['_setCustomVar',2,'Newsletter subscriber','Yes',1]);

Track RSS Subscriber
Same thing but with your RSS feed. Is it any good? Does it convert people to leads?

_gaq.push(['_setCustomVar',3,'RSS subscriber','Yes',1]);

Track Demographic Information
You could track a whole slew of demographic information, particularly if you have a form that collects this sort of data when they fill it out. How do 16 year old Male leads react differently to your content than 18 year old female leads?

_gaq.push(['_setCustomVar',4,'Gender','Male',1]);

track promo offers
This really could go anywhere, but if you’re using different header images on a home page for instance to drive internal promotions to sign up pages, the you can see if someone actually saw that image, and then track their conversion rates appropriately. Or it could just be a marketing message you want to ensure they’ve seen, and how it affects your lead generation.

_gaq.push(['_setCustomVar',5,'September Promotional Image','Yes',2]);

Ways to use Custom Variables with a Self Service site

Self service sites, are sites that are more about helping people, getting information into their hands. Like a help desk, with support articles. You’d want to use your variables different here also.

Track Member Type
Maybe you have different support levels, or a paid service level vs a free one. Record the visitor’s member type, maybe yes or no, maybe gold silver platinum, etc. Or maybe you just want to record logged in vs not-logged in.

_gaq.push(['_setCustomVar',1,'Member Type','Gold',1]);

Track session help articles serviced
During the session, track places you see as a successful delivery of a help article. Increment the count. How many did they view? Is more a good thing or a bad thing? How do people react differently depending on how many articles/downloads they’ve made?

_gaq.push(['_setCustomVar',2,'Session Articles','6',2]);

Track This Total Over Time
And at the same time track a permanent overall one, not just for the session, but over time. How many times has this visitor come and viewed support articles over the past year? Do the people who view lots of articles behave differently? Do you get higher reviews from those that come often but view few articles, rather than someone who comes rarely and views many?

_gaq.push(['_setCustomVar',3,'Total Articles','6',1]);

Emailed Customer service
Sometimes emailing or contacting customer service is a good thing on these sites, and sometimes it’s a failure. Besides just tracking it as a negative goal, track it as a custom variable so you can see the differences between users who did contact customer service, and those who didn’t.

_gaq.push(['_setCustomVar',4,'Customer service','contacted',2]);

Complaint
And maybe when they contacted they actually complained, and you have a drop down on the contact form for complaints. record the complaint, so you can then segment complainers from non-complainers and get some insights on what site behaviors they had to lead to complaining that might help you improve your site. Or even make it a visitor scope custom variable and compare complainers vs non-complainers over time.

_gaq.push(['_setCustomVar',5,'Complaint','yes',2]);

There you go. Twenty different ways you can use the 5 free custom variable slots you get in Google Analytics (or maybe you have GA Premium, and you can use all 20 at the same time!). Get these in your websites today, and start gaining better insights into your visitor behavior.

Sayf Sharif

About Sayf Sharif

Sayf Sharif is a Web Analyst, and expert in Usability and UX, who has worked with businesses large and small to maximize their online presence since the beginning of the Web, winning numerous awards along the way. Sayf has studied human tool use from the stone age (he went to graduate school for Archaeology) to the information age (he started programing on his father’s TRS-80), and is always interested in what goals people wish to accomplish using their tools, and how successful that experience was.

http://www.lunametrics.com/blog/2012/08/28/20-ways-use-custom-variables/

73 Responses to “20 Ways to Use Google Analytics Custom Variables”

Hi,

Good list & I need to publish my own list of ways I am using CVs with clients as well – have a few to add to this. But I have a question, is it really now considered ok to capture visitor IDs within Google Analytics – I thought that still broke their ToS?

Thanks

Peter

Sayf Sharif Sayf Sharif says:

To my knowledge Google Analytics has never definitively answered the question however, it’s my opinion, and the opinion of those much closer to GA than I am such as Justin Cutroni, that capturing a Visitor ID as long as it’s some sort of database key, is perfectly fine, and really no different from storing your transaction ID.

Here’s Justin saying as much within this post: http://cutroni.com/blog/2011/05/05/merging-google-analytics-with-your-data-warehouse/

The terms of service itself states: “You will not (and will not allow any third party to) use the Service to track, collect or upload any data that personally identifies an individual (such as a name, email address or billing information), or other data which can be reasonably linked to such information by Google. You will have and abide by an appropriate Privacy Policy and will comply with all applicable laws and regulations relating to the collection of information from Visitors. You must post a Privacy Policy and that Privacy Policy must provide notice of Your use of cookies that are used to collect traffic data, and You must not circumvent any privacy features (e.g., an opt-out) that are part of the Service.”

Personally identifiable information isn’t a visitor ID. It’s a name, a social security number, a credit card number, etc. If the ID is just something that links to your own database it’s not “data which can be reasonably linked to such information by Google”.

It’s a fairly common practice now, and as long as your visitor ID isn’t their social security number or their name or something, as long as it’s a random string of numbers that you have also stored within your own system, most experts read that as acceptable.

I managed to miss that post from Justin annoyingly. I was not aware this had become common practice and wished I knew that.

My belief was that transaction IDs were in a grey area where they had to be captured for ecommerce tracking, could technically be used to combine with other data but Google looked the other way as were there by default. But that deliberately using GA to capture any other type of ID which could be combined with other data sources was still a big no-no which could get your GA account shut down. And annoyingly have told various of my clients that over the past few months.

With this post from Joomla (http://www.analyticsforjoomla.com/google-analytics/166-the-assonishing-new-features-of-google-analytics), it does sound as though a form of visitor ID is permissible, it is the only way they could track across devices. But I really wish they would come out and state where the line is and what is allowed, partially if I am advising my clients one thing and everyone else is doing something else.

Appreciate the response & update.

Following a twitter discussion, it appears the answer is still of course “it depends”. But agree, it now looks to be fine to capture visitor ID in GA, a light grey area.

It also seems like the ToS changed which makes this more light grey than very dark grey. Taking a copy from one of the comments on that post of Justin’s, they used to be

“You will not (and will not allow any third party to) use the Service to track or collect personally identifiable information of Internet users, nor will You (or will You allow any third party to) associate any data gathered from Your website(s) (or such third parties’ website(s)) with any personally identifying information from any source as part of Your use (or such third parties’ use) of the Service.”

The key difference for me is “by Google” instead of “Your use”.

Sayf Sharif Sayf Sharif says:

Right, I think that’s the part that people miss. “By Google”.

Otherwise you could just perform a transaction on the site, and capture a transaction ID for a fake purchase, and then associate that into your own records. What’s the difference? None. Google can’t look at a transaction ID and know who you are or find out about you that way. Google doesn’t want even the hint of PERSONAL information about people in their system. I’ve seen people recommending hashing a phone number and putting it into GA, and I think that’s problematic, even if it’s hashed. But a pure ‘random’ id that isn’t anything other than an ID, simply doesn’t go against GA’s terms of service.

Also the fact that @googleanalytics linked to this post I take as an endorsement of the “go ahead and capture a random visitor ID in a custom variable” concept. :P

Sayf Sharif Sayf Sharif says:

Just re-read that twitter conversation. Wish I had seen it earlier and jumped in. After talking with Robbin here about it more, I really think it’s barely a gray area. In the 50 Shades of Gray regarding storing PII in GA, this is Hex #eeeeee imho. I like to stir controversy though….

Uffe says:

If you want to get demographic data, such as gender and age into your Google Analytics custom variables, you can connect your GA account with your UserReport account. This enables you to build advanced segments containing men/women or young/old etc. All your GA data may now be segmented by demographics, read more: http://www.google.com/analytics/apps/about?app_id=1174001

Marlana Dick says:

The two best ways to increase traffic to your site is:

Agree that it seems pretty much clear cut that it is fine now – wish I had known the ToS had been updated sooner. Currently working on solutions for tracking a visitor ID (member ID if logged in) & a session ID (timestamp) and defining the right data exports via the API to build a really useful member database.

Sayf Sharif Sayf Sharif says:

Funny, I was just looking at a good way to capture a unique generated ID to pop into a custom variable. I worry that a timestamp isn’t enough, if you have a well visited site. I was thinking about doing something like grabbing the timestamp, user agent, and some sort of combination of ports, addresses, etc, and then doing an md5 hash on those followed by converting the number to base 36. Then it’d be a shorter sequence but fairly unique identifier that won’t have the overlap a pure time stamp will have.

The timestamp approach to identify a session will work if used with a visitor ID – the two identify a session uniquely. It does mean using two custom variables out of your five but is the tradeoff if building a data warehouse off this data.

There is one scenario, for custom variables you might what to append to the article. Is Directories! It’s not a blog–It’s not ecommerce. What would you recommend?

Searchengineman

Sayf Sharif Sayf Sharif says:

Directories. I’d probably recommend a deeper use of the category concept. Like take the Yahoo Directory for example at dir.yahoo.com.

If you drill down into “Computers and Internet” and then “Data Formats” the URL changes, so you can see all these areas within a Content Drilldown report. However you could use the 5 custom variables to do 5 levels of drill down. So the data formats page would have a first page level variable of “computers and internet” and a second page level variable of “data formats”. Drilling down further to Graphics you could do a third page level variable of “Graphics” a fourth for the drill down to “GIF”, and so on…

The problem is that there are only 5 custom variables for most people (unless you want to buy Premium from us) and there will often be stuff deeper than that.

At the very least a top level custom variable for the top level category then that hits every page below.

Otherwise I’m not sure. What are the goals of directories other than just getting people to click links out? Those you could better track with outbound event tracking. Perhaps a custom variable paired with that event for a subsection category?

Cameron says:

Interesting post. I have a question regarding tracking purchase history because what you have written is very different to the other posts I have read.

Is it possible to set a visitor level custom variable to track the number of purchases?

So that when I look at my custom variable in my reports I can see the number of people who have made 1,2 and 3 purchases in the reported period.

What I would really like to do is be able to create an custom segment for people who have made 4 or more purchases. Is this possible?

Would love to get your thoughts.

Sayf Sharif Sayf Sharif says:

You could set a visitor level custom variable to track the number of purchases, however it would increment with every purchase, so you couldn’t use it to see the number of specific purchases within a reported period. If you looked in the reported period it would just show the current total of the variable if it were visitor level.

You could set a session level variable for a transaction showing that the transaction occurred during that session, but that could also get overwritten, so you’d need some actual code on the page checking values, etc, to determine what you’re doing.

There’s no real easy way to do what your’e saying, within a dynamic time frame, in GA without additional coding.

When I saw this web site having amazing featured YouTube videos, I decided to watch out these all videos.

Sayf Sharif Sayf Sharif says:

I know that’s a spam comment from heitzdigital.com but it’s such a great auto generated one, I have to leave it there….

Nicola says:

If you own a news website and you want to measure most popular categories and most popular tags your users visits, you think it should be better insert custom vars at page level scope in which web page? In the article page tracking category name ? This is right if you have 1 content in 1 category but for tags it couldn’t be correct if you have 1 content and more than one tag for each content. What do you think?

Charles B says:

Hi Sayf, is there anything in the GA guidelines, or to your knowledge, to say whether it’s ok to push a numerical visitor-level ID into a custom variable? e.g. their customer ID when they log in, or some other unique ID when they hit the site? Any thoughts very welcome.

Sayf Sharif Sayf Sharif says:

Nicola, It’s hard with tags as you’re limited in spots. It’d stick with tracking the category the page is located within ON the page itself at a page level scope. If you want to collect tags and you have a large number of them, you’d probably want to concatenate all the tags into a single long string like “soup:vegetable broth:carrots:celery” and place that into a page scope custom variable as well. You could then do a filer and say “show me all the visits to pages with tags of carrots by doing a regular expression filter on the variable.

Sayf Sharif Sayf Sharif says:

Charles,
As long as that id is not identifyable with Google it’s ok. They have explicitly stated that it’s about GOOGLE being able to know who it is. So if you have a visitor id field from your own system, that nobody else could use to identify that person outside of your own system, then its ok to put that in GA. So no social security numbers, credit card numbers, names, telephone numbers, emails, etc. But if it’s some random primary key from a database you’re good to go, and in fact it’s going to be encouraged in the new Universal Analytics: http://www.lunametrics.com/blog/2012/11/08/universal-analytics-affect-website/

Nicola says:

Hi Sayf I’ll follow your hint, thanks!

Eric says:

Hi! Thanks for the useful article.
I’m trying to take advantage of custom variables across two different ‘properties.’ We have a social network site as well as our main web site. I’d like to track some variable from the social network (gender and age) then use them to track usage on our main site. I am able to set the CV from the social network, and I can see them in my main site’s reports, but it seems it’s only showing pageviews, etc. that happen on my social site. Is this like a config/setting with how I set my CVs, or does it just not work that way? Thanks for any insight!

Sayf Sharif Sayf Sharif says:

Eric,

Not sure. Are you doing cross domain tracking on the two sites correctly? Is the custom variable being set as a visitor level CV, rather than session or page scope?

Hello,

I just set a welcome splash screen for my website on which I ask the visitor to provide me some information on whether he/she is a client of ours or not and then to provide me with the type of “role” he/she plays in his company. I set two independent visitor custom variables and they are working out great. However I would like to see the Navigation Map for each one of the possible options. i.e: I would like to see the navigation map of Non-Customers that are Engineers . How can I achieve this ?

Thanks

Adrian says:

Hi Sayf,

Great post. I’ve just decided that the time is ripe to learn about and take advantage of custom variables, and your post is very helpful in showing a number of possible uses for them. The site I’m working on is a travel one, with travel products located in hundreds of cities around the world. So I was thinking of setting up custom variables to track what destinations people are searching for. I guess I would use one slot for one way/round trip, another slot for country, a third for departure city and a fourth for arrival city, all at the session level. Would that be proper usage of custom variables? Also, in the case of countries, for example, the list of values (countries) would be over 100. Are there any limits for the number of values?

Sayf Sharif Sayf Sharif says:

Wilfred,

You can create an advanced segment that only shows you visitors that had specific custom variable values, and that would let you look at the analytics JUST for that segment, and then you could look at the Visitor Flow or the Navigation Summary just for that custom variable.

Sayf Sharif Sayf Sharif says:

Adrian,

First, if people are using a site search mechanism, you might want to use that aspect of Google Analytics rather than Custom Variables. If you want to use Custom Variables though you could certainly do that, if you think you could get some insight out of it. It would let you look at JUST users searching to go to certain places, or from certain places, etc. Are users flying FROM new york city more likely to be interested in X, etc. That could give you insight on geotargeting some of your products.

As far as limits on values there aren’t. You could just have them be string values and put in the names of countries. You can really have any value you want, though I think there is an actual string length limitation, which may be 128 characters.

abhinay says:

Hi,
Nice article. I’ve a question- if some user activity sets a custom variable on my site and to send this info. to the GA server i trigger a pageview, doesn’t this inflate my overall pageviews of site or if I do that by triggering events then there ‘ll be additional category on the server.Ain’t there any cleaner way to achieve this.

Sayf Sharif Sayf Sharif says:

Abhinay,

Good question. A custom variable won’t get sent to the server without either a pageview or an event being fired. Therefore I recommend that if possible you set the custom variables prior to the initial pageview being sent. Unless the custom variable is via a specific user action on the page (say a mouseover of a page element) it usually can be placed on the page inside the GATC before the initial pageview.

Otherwise I recommend pairing the custom variable with a trackEvent to set the custom variable rather than a virtual pageview. both would work, but by using an Event you won’t inflate your overall site pageviews.

Hi Sayf,

This is a great list – am currently getting to grips with CVs and found this to jog my brain into thinking about what I can use them for.

Thanks!

Anand says:

I have a product navigation pages, Category > subcategory > product, I have placed custom vars on all these 3 pages and they report count correctly with custom var 1, var 2 and var 3, However if i want to drill down in GA report click of category show subcategories browsed and click on subcat show products browsed. what changes i need to make ?

PedroCZ says:

Great article!

I just have one quick question about tracking registered/not-registered users.

If I use custom variables with visitor scope, is it OK if I set the CustomVar on EVERY page and then call the trackPageview fucntion?

Thanks,
Pedro

Sayf Sharif Sayf Sharif says:

You may want to consider using events instead of custom variables Anand.

When you use page lvel custom variables like that, you can view how site performance does when people view certain pages, etc, but if you isolate those reports, you’ll see all visits in that session.

For instance if you have a category of “boots” as one section of your website, and you set a custom variable there as a page level for category = boots. Then when you look at visits with just that custom variable, by creating an advanced segement say, you’re going to see all page views, that is to say you’re going to see the home page still come up, you might see other categories “shoes” etc. You’ll also see the subcategory visits, but it won’t be restricted. the sub category area will have visits to other pages in other categories not just that one.

What you might want to do is to consider using events, and fire an event on each page. That event can be done similarly by say tracking a category of Boots, and then a subcategory of “winter boots”. Then when you look at just sessions where those cateogry events have happened, you’ll be easier to see the events in subcategories.

Or you could have an event fire on all which concatenates. Use the event label and action for your subcategories, etc, that way you can see all hits to the main page for boots, as an action, or a subcateogory etc.

Sayf Sharif Sayf Sharif says:

“If I use custom variables with visitor scope, is it OK if I set the CustomVar on EVERY page and then call the trackPageview function?”

Yeah it shouldn’t hurt anything, you’ll just constantly be overwriting that custom variable with a new value, which I’m assuming is the old one. Of course if the value changes, it changes at the visitor scope level, so that could be an issue with registered non-registered users.

You really don’t need to be doing that, but it won’t hurt it.

PedroCZ says:

Sayf, thanks a lot for your quick response.

One more quick question: is there a difference between sending CustomVars to GA via trackPageview and trackEvent?

What if I call set CustomVars (with scopes both Session and Page), then call a trackPageview function to make sure they get sent to GA, and then use couple trackEvents? Would they be sent twice?

Thanks a lot!

Sayf Sharif Sayf Sharif says:

There’s no difference. The Custom Variable needs one or the other to ride along with, but it doesn’t care which.

The Custom Variable will get sent with that first hit to GA that gets sent. The following Events won’t carry the Custom Variable again.

PedroCZ says:

Thanks Sayf, really appreciate your help. I was wondering how you know all this, especially if Google doesn’t really mention much specifics in the documentation :-)

Adam Murphy says:

Sayf,

Regarding tracking the Visitor ID:

your example code:
_gaq.push(['_setCustomVar',1,'UserID','1234567890',1]);

What do you think about setting the scope to 2 (Session) instead of 1 (Visitor) as shown your example code (above)? If you have multiple unique visitors accessing your site from the same computer/browser the custom variable values will continuously overwrite each other if scope is set to 1.

Sayf Sharif Sayf Sharif says:

That’s totally valid, and might be the way to go depending on your website. Just as a visitor in GA is a browser and not a person, a visitor on the browser could be more than one person. It’s not inconceivable for 2 or more people in a household to use the same computer and access the same site (amazon, facebook, etc).

This will hopefully be eased by Universal Analytics as you’ll be able to have an id for the browser/visitor and a separate session based id for the user which will carry over. That’ll let you see very clearly that a computer is used by more than one ‘login/user’ etc.

But for now, you could certainly set it as a session. The only issue there is that you might not always see what that user is doing because you’ll only see the sessions where they’ve logged in and identified themselves. If they were to visit your site 2 or 3 times between purchases you wouldn’t see for instance on an ecommerce site what they’re browsing between those points.

Until Universal Analytics, if you have the custom variables to spare, and you feel this is an issue, then maybe you could have two custom variables, one that is browser based, and one that is login based? Really there is no perfect system at present, which is one reason that it’s going to be dealt with in UA.

Adam Murphy says:

Safy,

Thanks for your feedback. Until Universal Analytics arrives, it does seem to be a tricky problem as the scoping choice determines where any holes/inconsistencies in your data may crop up. For our product, we primarily care about interactions behind the paywall so we can always set, or re-set, the custom vars after a successful login. Cutroni advises this exact same strategy but his reason is to keep pushing the scope level 1 cookie expiration date further out into the future.

Ultimately, I think we’ll go with scope level 1 as our users rarely share the exact same machine with another user or prospect. As you said, with scope level 1 we’ll be able to detect any visits even if a person has not logged in.

Thanks for the sage advice.

Adam

William says:

Great list mate, just spent the last 2 hours implementing a custom variable system based on membership :) looking forward to the results.

Ellen says:

Hi Sayf,

Would custom variables be used when you need to track whether or not specific text is displayed on a page? For example, if you wanted to track how many times a specific product was displayed on a product search results page?

These products have unique sku numbers and also have varying locations (or stores) that are not always unique.

We are trying to track how many times a specific product sku is seen by a web visitor, not clicked.

Thanks!

Ellen says:

Also to add, the unique product skus are in the hundreds, and the locations are at least 20.

We would need to track product skus by location.

Robert says:

Sayf,

I am someone new approaching GA – to track internal non-web utilities so we can better understand who is using them, what “screens” they are accessing etc. We will use a built in “web-viewer” capability to test this out.

Since my application is non-web, and used by only our employees, I’m having some trouble with the concept of “session-tracking” because web cookies may not work [at least thats the disclaimer in the sample I'm working from].

If I recorded something like a hex GUID which contained information like session start time & NIC Address do you believe I would get in trouble with the “personally identifiable information” clause and where would I put this information (custom variable or part of the URL “path” etc) to best use it in GA to analyze specific sessions or users?

I’m making the following assumptions:
1. Session Timestamp Start would stay the same throughout duration of “visit” – it would not expire until they closed the application
2. user NIC Address Hex provides reasonable user identification for my purpose without allowing access to PII
3. browser-based cookie is broken for my purposes

Thanks from a newbie to GA.

Arun says:

How to pass dynamic value to the custom variable

Sayf Sharif Sayf Sharif says:

Ellen that is an interesting question. depending on your traffic levels I would do it in a variety of ways. my first instinct is to instead use events to track the products on the page so that while page view would record the page visit event would fire if products showed up on the page. Of course problem with this is if you have hundreds of products in hundreds of pages but only will you be firing hundreds of events per page but thousands per visit and the numbers would add up so that’s probably not optimal.

The same problem of a different sort would occur with custom variables if you had hundreds of products on the page how would you set custom variables for all them to appear.

I would be more inclined to track the delivery of these products to the page on the server side within your own system. Your database would most likely be able to show when these products are being delivered to the page contract that inside your own database somewhere. Then the ability to extract that data could be combined with specific page views in Google Analytics someone a spreadsheet outside of GA such as Excel.

Sayf Sharif Sayf Sharif says:

Robert, using a NIC user address is an interesting question. This is not information that I believe Google would have any access to, and therefore not be considered personally identifiable information. Remember the concept of personally identifiable information is that is identifiable by Google.

Sayf Sharif Sayf Sharif says:

Arun, it depends on whether that dynamic information is server-side or browser client-side. If it is server site you simply generate the client-side code with a dynamic variable in place of that code so that the value is replaced by a dynamic value generated by the server.

If however that dynamic information is client-side you can do the same thing, simply have a function where you fire the custom variable with a dynamic value sometime after the page loads. If you can have that custom variable resolved prior to the initial page tracking then you need do nothing else. If for some reason this custom verbal is being set after the page has already sent its tracking to Google analytics, then you should fire an event in the code after the custom variable line as well. The event will ensure that the customer will get sent to Google analytics anytime on the page as long as the event fires after the custom variable code.

Sayf Sharif Sayf Sharif says:

If Its binary on a page, as in “they visited page X or they didn’t” you don’t need to do anything else. Just set the custom variable on that page say “visited” with a value of the page name.

Then you can segment those visitors with advanced segments. Just exclude visitors who have the value of that page name on that custom variable and you’ll see visitors who didnt see the page. include that value on a segment and it will only show those who have visited that page. Have both segments active at the same time and you’ll easily be able to compare the two.

Gregory says:

Thank You very much for answer and help :) I was just wondering that segment with users who visited the X page will have data from multiple sessions stored in a cookie and others not, because they won’t have visitor scope customVar set.

Sayf Sharif Sayf Sharif says:

Yes that would include possibly later sessions for the visitor when they didn’t visit that page. If that’s an issue you could always set it to be session scope. Or you could do a visitor level custom variable as above AND fire an event on that page (noninteraction. Something like ‘visited’).

Then you could segment for the people who saw the page based on the custom variable, but also segment based on the event so you could see people who visited the page separated into sessions when they saw the page and sessions when they didn’t.

As usual, very nice article that I’ve read few months ago.
I’ve thought about you reading this new article probably written by a “shy” fan ;)
http://www.searchenginepeople.com/blog/title-10-things-to-track-using-google-analytics-custom-variables.html

In Lunametrics, I trust!

Sayf Sharif Sayf Sharif says:

Damian,

You could capture that by some script in your page before your GATC fires the pageview, but after it instantiates the gaq object.

/****************/

function gup(name) {
name = name.replace(/[\[]/, “\\\[").replace(/[\]]/, “\\\]”);
var regexS = “[\\?&]” + name + “=([^&#]*)”;
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return “”;
else
return results[1];
}

var customvarval1 = gup(‘CUSTOMVAR1′));

_gaq.push(['_setCustomVar',1,'NAMEOFTHEVARIABLE',customvarval1,3]);

/*************/

That should work, or something like it. Pull the values out of your window.location.href and then assign them to custom variables before the pageview fires.

Sebastian says:

Hello,

I would like to know if someone knows how to track a list of values in the same variable.

For example:
_gaq.push(['_setCustomVar',1,'name',['val1','val2',...'valn'],3]);

Sorry for my english

thanks!

Sayf Sharif Sayf Sharif says:

Sebasian you can concatenate the values into a single variable. So for instance you could have demographic information all within one variable like…

_gaq.push(['_setCustomVar',1,'Demographics','sex:male|age:36',1]);

Then you would use regular expressions against those values inside GA to parse them.

Sebastian says:

Thanks Sayf Sharif for the advice. Now I’m having trouble logging many variables, in googele analytics i can see only the last defined. For example, in my html code i have:

_gaq.push(['_setCustomVar', 1, 'key1', 'val1', 3]);

_gaq.push(['_setCustomVar', 1, 'key2', 'Val2', 3]);

and in google analytcis i see only data from key2

any advice?
thanks!

Sayf Sharif Sayf Sharif says:

Sebastian,

Keep in mind that for any visitor they can have only one value stored in any particular variable. DIfferent visitors can have different name=value pairs so you could use one key slot for different things… however one visitor has only one custom variable in each slot. so if you set two values both in slot 1, then you will only ever see the last value for that slot set for that visitor.

Maria says:

Hi Sayf, this is a very interesting article and really helpful Q&A in the comments section!

I have a question too. I have a form and when a user submits it I save the info in the database and generate an ID.

I would like to save in GA each and every one of those IDs even if they belong to the same user but I didn’t manage to do it yet. I thought using a page level var would do the trick but for example, the day before yesterday I had 1700 new IDs and registered in GA just 19.

How can I do this? Thank you!

Prasad says:

Hi Sayf, Thanks for this interesting article. I have a question too. I want to display the individual pagevists at the bottom of that particular articlepage. how can i do that with google analytics code. The sample article link is: http://www….com/section-name/this-is-the-title/1104.html. Thank you..

Sayf Sharif Sayf Sharif says:

Maria, In theory what you are saying should work. Assuming you have a form page and a thank you page, then on the resulting thank you page you set as a page scope custom variable with the ID you generated followed by a pageview for the thank you page, it should record all of them. However you may need to use a custom report to see accurate counts of your page scope custom variables. Check out this blog post by Dorcas: http://www.lunametrics.com/blog/2012/09/25/page-level-custom-variables-reports/

Sayf Sharif Sayf Sharif says:

Prasad, I don’t follow. You want to display the pageview at the bottom of the page? In what manner? You mean the total hits that page has gotten in GA like a hit counter?

Maria says:

Thanks Sayf! now I can see all the data!

Prasad says:

yes sayf.. I want to show total hits that page has gotten in GA like a hit counter..

Sayf Sharif Sayf Sharif says:

Prasad the best way to do that would be to use the Google Analytics API to connect with your data and display the pageviews for that page. A single call to the api would be able to deliver you the pageviews for that page, within the time frame you specify.

suriam says:

I have a question. Now that the GA script is changed again, if I use the new script how should the custom variable look like?
New script does not have _gaq.push anymore. It has something like ga(‘send’…)
In this case we use just ga or ga send and then all stays the same?
Could you please write an example?

Thank you.

Sayf Sharif Sayf Sharif says:

suriam,

Well if you are moving up to Universal Analytics I recommend instead of using Custom Variables, to jump right into Custom Dimensions instead. You can check out this link for specifics:

https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets

But generally you will send it with the pageview hit like this:

ga(‘send’, ‘pageview’, {
‘dimension15′: ‘My Custom Dimension’
});

Here’s how to specifically set them up in the interface:

https://support.google.com/analytics/answer/2709829?hl=en&ref_topic=2709827

There are a number of benefits of custom dimensions over custom variables, and if you are using Universal Analytics you should make that leap rather than using Custom Variables.

Anna N. says:

I have a visitor level Custom Variable capturing a numeric User ID for members and non-members alike. The ones who are non-members get assigned a certain number, and the non-members have an existing one. How can I correlate the two User ID s once the non-member becomes a member?

Sayf Sharif Sayf Sharif says:

Anna, you could do different things. You could use a second custom variable for the member ID’s, so youd’ have both. Or you could concatenate the ids to have something like 12345:67890 and then you could search for the : and/or use regular expressions to get the non-member vs member number.

Anna N. says:

Thanks Sayf. The setup at the moment for Custom Variable 1 is User ID 1234 (member ID) or User ID 5678 (non member ID). Custom Variable 2 is User Type – Member or Non-Member, so I can see who is user or member and what their number is. Are you suggesting to do Custom Variable 1 – Member – 1234 and Custom Variable 2 – Non-Member – 5678. If I do that, how will I know when one person switches from Custom Variable 2 – Non-Member to Custom Variable 1 – Member and see what they have done before they became a Member. Thanks.

Sayf Sharif Sayf Sharif says:

i’d probably concatenate if that’s the case. Then your userid variable 1 would be NONMEMBERID:0 until they became a member when it would become NONMEMBERID:MEMBERID

Then you could look at the specifc person via NONMEMBERID and then see what they did before and after by looking at the second part.

otherwise IF you had them in two variables you could segment based on those custom variables. Create one segment where the non-member id is 5678 but the member id has no value, and another segment has the same non-member id but has the member id as a value. Maybe set the member id as 0 for non-members, then it functions the same essentially as your current custom variable 2 of user type. 0 = non member, and any number over 0 = member. So you could still segment just members and non-members, but also create segments for specific users before and after they became members?