Archive for the ‘Custom Variables’ Category

How to Track Conversions for Both Internal and External Campaigns

After you learn about campaign tagging for Google Analytics, you may be excited that you can add all that extra information to a simple little link – so excited that you want to put campaign tags on every kind of promotional link that leads to a web page on your site. But there’s one kind of link that should never get campaign tags. You should never put GA campaign tags on internal banners or on-site promotions that lead from one page of your site to another.

Why You Shouldn’t Use GA Campaign Tags for Internal Promotions

Imagine this sample scenario: A visitor clicks an email campaign link from your latest marketing effort and lands on your site. Google Analytics records the traffic source and starts collecting data for the visit. Of course you hope that the visitor will continue to view pages on your site and maybe even convert on an important goal like registering for an upcoming conference or buying your latest e-book. When they do, you’ll be able to attribute that conversion to the campaign and evaluate that campaign’s success.

But what happens if the visitor clicks an internal banner with campaign tags before they convert? Google Analytics records a new traffic source and starts a whole new visit. So now you have at least two problems: You’ve split what was really one visit into two visits, skewing your data. And you can’t tie the original email link directly to the conversion, because the conversion happens in a separate visit.

To track internal promotions without splitting visits and losing credit for conversions, try one of these instead:

  • Add your own campaign parameters (not GA campaign tags) to the links and view the data in your Content/Pages reports
  • Use event tracking when a visitor clicks an internal banner or promotional link and view the data in your Content/Events reports

Alternative #1: Add Your Own Campaign Parameters

The first method involves making up your own tags, ones that GA won’t recognize and will pass right along into your Pages reports with the rest of the URL. Instead of utm_source or utm_medium, for example, you might simply add something like “from=promo” to the target link:

http://www.anything.com/buy-ebook.html?from=promo

Or you could use a more detailed scheme if, for example, you run internal promotions with many types of links in different places. So you might have one parameter similar to campaign name, like “campname=e-book”, and another parameter that describes the links, like “camplink=home-page-banner” or “camplink=side-nav-feature”:

http://www.anything.com/buy-ebook.html?campname=e-book&camplink=home-page-banner

http://www.anything.com/buy-ebook.html?campname=e-book&camplink=side-nav-feature

As long as you stay away from Google Analytics utm parameters, these types of URLs will appear in your Content/Pages reports and you can tell by the number of pageviews exactly how many times a visitor clicked the tagged link to arrive there.

Internal campaigns in the Content Pages report

Alternative #2: Use Event Tracking

The second method involves adding a bit of code to the link on the page. Inside the anchor tag (a href=”…”) include an onclick event like this (a href=”…” onclick=”…”). And in the onclick event, add the event tracking code using an event category and action like “internal promo” and “home-page-banner”:

onclick="_gaq.push(['_trackEvent', 'internal promo', 'home-page-banner', this.href]);"

After the event category and action it’s a good idea to include the optional event label. For the label you can simply write the target (href) of the link, using this.href.

View this data in your Content/Events reports by drilling into Top Events through the “internal promo” category, where you can see the how many times someone clicked each of your different internal promotional links.

Internal campaigns in the Top Events report

Combine with Custom Variables for Goal Data

Okay, so where’s the goal data? You may have noticed that Google Analytics has Goal tabs in Traffic Sources reports, but not in Content reports. The whole point of these alternatives was to keep your original traffic source intact so you could tie it to a conversion. But you probably also want to know how well your internal promotions lead to conversions, too, right? Of course you do.

Well, there’s another set of reports that has Goal tabs, where you can combine conversion data with a set of dimensions that you define, and that’s the Audience set of reports. You can write a custom variable with the parameters or event data you created in either alternative described above. And then you can easily compare goal conversion data in a single table that lists all your internal promotions.

Conversion Data in Custom Variables report

The thing to remember when writing custom variables is that the data needs to piggyback on a _trackPageview or _trackEvent call.

For the event tracking alternative, add _setCustomVar to the onclick event, like this:

onclick="_gaq.push(['_setCustomVar', 1, 'internal promo', 'home-page-banner', 2]);_gaq.push(['_trackEvent', 'internal promo', 'home-page-banner', this.href]);"

For the other alternative where you make up your own campaign parameters, I suggest adding _setCustomVar to the page that’s the target of the link, right before the usual call to _trackPageview. You can use a little Javascript to read the URL and write the custom variable according to the campaign parameters that appear there. For example, if the URL is:

http://www.anything.com/buy-ebook.html?campname=e-book&camplink=side-nav-feature

The resulting custom variable code (placed before the call to _trackPageview) could be something like this:

_gaq.push(['_setCustomVar', 1, 'e-book', 'side-nav-feature', 2]);

In both cases I’ve set a session-level custom variable (indicated by the number 2 above), and I’ve set the custom variable to slot number 1 (out of 5). If you are already using that slot then you’ll need to assign it to another one. Read our post about how to keep track of custom variable slots and scopes for more guidance.

No More Split Visits

Avoid the split-visit problem. Keep visit data together by keeping internal and external promotions separate. Track your external campaigns with GA’s utm parameters and try one of the above alternatives for internal campaign tracking. And tie both external and internal promotions to conversion data to evaluate the success of each.

What methods do you use for tracking internal promotions? And how do you tie them to conversion data? Please share in the comments.

Google Analytics Custom Variables Not Working?

Custom variables... or not?

Everyone can agree: Google Analytics’ custom variables are a great feature. It lets you label your visitors with all sorts of fun stuff. Male or female? Member or non-member? Cat person or dog person? If you can identify your visitors’ answers to these sorts of questions, you can tag them with a custom variable.

But sometimes website owners implement the custom variable code and start gathering these valuable segments of traffic, completely unaware that the numbers aren’t very accurate. What could be causing such a heinous mistake?

Believe it or not, Google warns against the issue right in those instructions there, but they don’t call it out quite enough for my taste. It’s extremely important that you “call the _setCustomVar() function when it can be set prior to a pageview or event GIF request” (emphasis mine). Here are the details:

In certain cases this might not be possible, and you will need to set another _trackPageview() request after setting a custom variable. This is typically only necessary in those situations where the user triggers a session- or visit-level custom var, where it is not possible to bundle that method with a pageview, event, or ecommerce tracking call.

What exactly does this mean? Well, if a visitor fills out a survey on your site, hits submit, and you run _setCustomVar() after the _trackPageview() of the submission success page, that _setCustomVar() call just sits there in deep space, waiting for another _trackPageview() or _trackEvent() function to carry it along to Google’s servers. If that is the visitor’s final pageview in the session, then the call floats away forever, never to be heard from again.

The worst part, though, is if the visitor goes to another page, then the _setCustomVar() will tag along with any subsequent GIF requests. This means that it may appear as if the custom variable is working just fine, according to the reports in Google Analytics, but the numbers are just inaccurate.

So, to ensure that you are tracking your custom variables as precisely as possible, make sure that you always run the _setCustomVar() function before the calls to _trackPageview() or _trackEvent(). If this isn’t possible–you have an include at the top of every page, for instance, and can’t modify it–then be sure to include a second pageview or event after the _setCustomVar() function, like this:

_gaq.push(['_setCustomVar', 1, 'membership', 'gold', 1]);
_gaq.push(['_trackEvent', 'Tow Truck', 'go', '-', 0, true]);

This will ensure that every single time that function runs, it gets counted. Guaranteed!

Update: Tyson Kirksey, of Vertical Nerve, reminded me to set the event to non-interaction mode so that it won’t influence bounce rate, pages/visit, time on page, etc. I’ve also borrowed his clever naming convention for the event. Thanks, Tyson!

Was that visitor signed-in?

With GA you can track custom information about a visitor, a specific visit, or a particular page with Custom Variables.

One of the things people often want to do is to know when the visit is a signed-in visit.

The GA JavaScript is pretty easy for this.  Assuming you’re not using any other Custom Variables, it might look like this (Depending on whether you’re using the traditional or async syntax.):

pageTracker._setCustomVar(1,”Signed-in status”, “Signed-in”, 2);

OR

_gaq.push(["_setCustomVar", 1, "Signed-in status", "Signed-in", 2]);

(Here is the GA documentation for _setCustomVar and information on how to set a Custom Variable.)

The trick is to execute this JavaScript at the right time — right after the visitor does actually sign-in.  And there are probably as many correct ways to do it as there are websites.

One of the easier ways to implement this is to include the JavaScript in an HTML element that only gets included in the webpage when the visitor is signed in.

For example, here are 2 screenshots of the aboutus.org website. The first is the signed-in version.  The second is the signed-out version.

Notice how the block of HTML in the Top-Right Corner changes.  This block would be a good candidate for where to execute the GA code.  Just include the GA JavaScript from the example above in the “signed-in” block and you’re done.

The downside is that although this is simple and fast, it would execute the JavaScript for every page.  This isn’t a problem from the reporting side, but since it is only required to execute once for tracking purposes, executing it every time is needless.  Realistically, it executes pretty quickly and should not slow down the user experience.

Once you’ve set the custom variable for your signed-in visits, you can then look at that segment of visits and see how they stack up. Are they more likely to click on ads? Sign up for your newsletter? Purchase a product? Of course, you can get these insights by going to the Visitors > Custom Variables report in your GA, or by creating a Custom Report to pull in just the information you want to see for that segment.

Custom Variables, Part III: Slots

This is the third post (at long last) in a series about custom variables. We’ve already written about why to use custom variables and how the code works. This last part is about a subtlety of how custom variables operate called “slots”.

Slots and Scope

You’ll remember from Part II that the “slot” or “index” is the first argument in the _setCustomVar function, and we glossed over it at the time because it deserved a whole post of its own.

You can think of the slots like little mailboxes to Google Analytics. You write the name/value pair on a slip of paper and stuff it in the hole, and the Google Analytics mailman pulls it out the other side and notes down the value. There are 5 slots, numbered 1-5, and each slot can only hold one slip of paper at a time.

“So,” you might say, “that means I can have 5 custom variables, right?”

Well, not exactly, because remember each variable has a scope: visitor-, session-, or page-level. Each one of these works slightly differently.

With a page-level variable, the Google Analytics mailman takes the slips of paper out of the box on every page. The boxes are empty again, and available for you to put another slip of paper in on the next page.

With a session-level variable, the Google Analytics mailman takes the slips of paper out of the box at the end of a visit. You are allowed to put a new piece of paper in the slot, but you have to throw the old slip away first.

With a visitor-level variable, the Google Analytics mailman takes the slip out, writes down the value, and puts the slip back in the box (it stays in the __utmv cookie). Again, you can put a new piece of paper in, but you have to throw the old slip away first.

In any slot, the last value recorded wins.

OK, that was a nice story. Just the executive summary, please.

So what’s the upshot here?

  • You can reuse a slot on different pages for a page-level variable.
  • If you reuse a slot for a session- or visitor-level variable, the last value wins. So make sure you really, truly want to overwrite the slot when you’re doing this. Sometimes this makes sense (someone changes status from “member=gold” to a “member=platinum”). Mostly, you want to dedicate a slot to each mutually exclusive session- or visitor-level variable.
  • You should always put variables with the same key in the same slot. You don’t want “member=gold” appearing in 2 different slots, or worse yet, “member=gold” in slot 1 and “member=platinum” in slot 2.
  • The most important lesson is that managing the way the variables is stored is up to you. If you have a complicated situation with lots of variables, make sure you create a chart of slots and scopes to keep track of it all.

Knowing the slots

Being aware of the slots is important, even if you throw this over the fence to your developer and assume they can sort it out. The reason that slots are important is that, to use a custom variable in an Advanced Segment (or in cross-segmentation in reports, or Custom Reports), you need to know what the slot is:

Custom Variable selections for Advanced Segments

Learning more

The Google Code site has some fairly good documentation on custom variables. But the very best thing you can do is watch this webinar in which Phil Mui (the product manager for Google Analytics) walks through exactly how these things work. Straight from Phil to you; it doesn’t get better than that when you want to know something about how GA works.