Faster, Better, Stronger. The GA Async Tracking Code

You may have heard that Google will begin to use site speed when calculating web rankings. This generated a lot of buzz, but according to Matt Cutts,

fewer than 1% of search queries are affected by the site speed signal in our implementation and the signal for site speed only applies for visitors searching in English on Google.com at this point.”

This may be the beginning of Google’s use of site speed. It’s probably a good idea to think about speed when designing your site.

How GA can Slow Your Site

One thing that can potentially slow your site down is the Google Analytics tracking code. Specifically, the ga.js library and how the browser loads the file.

When a browser renders a page it literally starts starts to display the HTML from the top of the page and moves to the botton. When it hits a JavaScript file, like ga.js, it requests the file from the remote server.

Then it waits.

And waits.

And waits.

Once the file has been pulled into the browser it continues to process the HTML.

You can see the issue here, the browser could wait a long time for the JavaScript file depending on the visitors proximity to the server, the visitor’s bandwidth, and a bunch of other factors most of which you can’t control. Waiting for a page to render is a bad user experience. I know I don’t like to wait!

There’s a great example of how a remote file can make the browser slow down on the High Performance website blog.

Google tries to mitigate load-time issues by geo-loadbalancing ga.js, so the visitor’s browser will automatically contact the closest data center to load the ga.js faster.

It’s also best to place the ga.js at the bottom of your pages just in case there is an issue with the communication between the data center and the visitor’s browser. By placing the ga.js at the bottom of the page all of the content has already rendered, so the visitor won’t experience a blank or partially loaded pags.

While placing the GATC at the bottom of the page can mitigate some issues it can cause others.

First, it is possible for visitors to navigate away from the site before data is sent to Google Analytics. This leads to missing data.

Second, if you need to do any advanced tracking, like ecommerce or events, you may need to move the ga.js to the top of the page thus negating the benefit from putting it at the bottom of the page. This can also complicate your implementaiton because some pages may have the code at the top of the page and some might have the code at the bottom of the page which is a maintenance nightmare.

Using the new async code can help mitigate both of these problems.

How the Async Code Helps

First, The asyncronous version of the tracking code utilizes HTML 5 and the modern browser’s ability to load files asyncronously. This means that the browser can load files like ga.js while it continues to render the page for the visitor.

Second, the async code let’s us send data to Google Analytics before the ga.js has loaded in the browser. Technically we’re not sending the data to Google, but we are executing the commands that generate the data. The broser just holds the commands until the ga.js has completely loaded. Then the commands are executed (in the order in which they were added) and the data is sent to Google.

In the old days (like last year) we had to wait for ga.js to load before we could call any GA code. Not any more.

So the Async code is a good thing.

The big question is, should you use the async tracking code?

Well, if you’re concerned that Google Analytics is slowing down your site, and that it may be impacting your search rankings, then yes, use the async code. There are a number of free tools that you can use to test how long it takes ga.js to load on your site. (YSlow, Page Speed, etc.) Use them to determine if GA is slowing down your site.

If you decide to use the async version of the code there are a few things you should know.

Using the async code is slightly different than using the standard tracking code. Let’s look:

< script>
//
// This section creates the queue
//
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);

//
// This section calls the ga.js
//
(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 async code can appear anywhere in a page. But it’s best to place it at the immediately after the opening BODY tag. This let’s you add commands to the queue as soon as the page starts to render.

Some of the GA documentaion states that you can place the code in the HEAD tag. But this can cause some JavaScript issues with IE6. If you have a lot of visitors that use IE6 don’t put the code in the HEAD tag.

If you’re still leary about putting the code at the top of the page you can split the tracking code into two sections. You can place the first part of the code at the top of the page and the second part, the calls the ga.js, at the bottom of the page.

While this let’s you add commands to the queue immediately it is still possible to miss some GA data becayse the ga.js will be the last thing the browser requests. But the choice is up to you.

How the Code Works

Digging into the code a bit more, the first thing you’ll notice is the call for the ga.js is the second part of the code. This is the opposite of the standard tracking code. The async tracking code begins by creating the queue to store commands. Then the tracking code calls Google’s servers for the ga.js file.

The great thing about the queue of commands is you can add things to the queue whenever you want, even if the ga.js has not finished loading. This is what makes it possible to add GA commands at the top of a page.

The second section of code is the request to Google’s servers for the ga.js. It’s the exact same ga.js that’s used in the standard tracking code, it’s just pulled into the browser in a different way. Notice the ga.async=true part of the code? That’s the part that tells the browser it should load the code asyncronously. The browser not execute any commands in the queue until after the ga.js has loaded.

If you’ve got a basic site then all you need to do is add the async code to your pages and you’re good to go. You don’t need to worry about adding items to the que, etc.

But if you’re doing any advanced tracking, like virtual pageviews, events or ecommerce you need to know how to add items to the queue.

How to Add Items to the Queue

Adding items to the queue can be done a number of different ways. The easiest way is to “push” things onto the queue. This is done with the push command, as shown below.

_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);

If you wanted to add an event to the click of a link you would push the command on to the queue like this:

< a href="onClick='_gaq.push('cat','act','label');'">go red sox< /a>

Or, to create a virtual pageview you could push the command onto the queue like this:

< a href="onClick='_gaq.push('_trackPageview','/virtual/go-red-sox');'">go red sox< /a>

You can also add mulitple commands to the queue at a time. But this is where things start to get technical, and I’m not going to go there :)

How you implement the code depends on your site, the commands you want to add and how much JS you know. To learn more about how to add commands check out the GA Code site.

Switching to the Async Code

The complexity of migrating to the async tracking code depends on your site. If you’re not using any of the advanced GA features then migration can be as simple as swapping the tags.

But, if you are using advanced features, you’ll need to update all of the GA code on your site. Remeber, all the standard Google Analytics functionality in the ga.js exists in the async code. You just need to replicate your existing code in the async format. You can find an overview of the async code (written in nerd) as well as code examples, on the Google Code site.

Obviously the migration effort depends on the complexity of your implementation. But if you take your time and document your existing GA code and test your implementaiton thoroughly everything should go smoothly.

Have you tried the new async code? Got an experience you want to share? Leave a comment!

Share this post:
  • Twitter
  • StumbleUpon
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
  • FriendFeed
  • Sphinn
  • Google Bookmarks
  • Reddit
  • email
  • Technorati
  • Yahoo! Buzz

Tracking Internal Campaigns with Google Analytics

Internal campaigns are marketing efforts that are run on your site and promote your products and services. Here’s an example from the Boton Red Sox site. They’re using ads on the homepage to promote ticket sales.

Companies should track how people react to these campaigns and which ones are most successful. But what’s the best way to do this with Google Analytics?

Some people use the standard campaign tracking to track internal campaigns. THIS IS INCORRECT AND SHOULD NEVER BE DONE. Using the standard campaign tracking for internal campaigns will cause problems with your source data. So don’t do it!

There are a few correct ways to track internal campaigns. You could use Event Tracking, Custom Variables or Virtual Pageviews. But I like to use GA’s internal campaign tracking tool.

What? You’ve never seen or used the GA’s internal campaign tracker? It’s in the profile settings and it’s called Site Search tracking! Did I fool you ;)

Site Search can easily be configured to track internal campaigns. Let’s walk through the steps to set it up and then the data and analysis.

Step 1: Create a New Profile

Because we’re using Site Search for an unintended purpose it’s best to configure these settings on a new profile. It’s not possible to use Site Search for both tracking internal campaigns and internal site search within the same profile. You need to have a separate profile to track internal campaigns.

Step 2: Tag your Internal Campaigns

Once you’ve created your new profile it’s time to tag your internal campaigns. Internal campaigns need to be tagged in a similar manner to external campaigns: you need to add query string parameterrs to your internal ad.

However, unlike external campaigns you do not use the standard link tagging parameters (utm_campaign, utm_medium, etc.). You get to make up your own parameters!

You can use one or two parameters for internal campaign tracking and you can name then anything you want. The reason you can use one or two parameters is that GA’s site search configuration uses two parameters, one for the search phrase and one for the search category.

Whatever you choose, make sure the parameters are not used for anything else.

TIP: Check your Top Content report for a complete list of your site’s query string parameters. Verify that the parameters you create are NOT in this list.

For the sake of this post I’ll use the parameter icn (shor for internal campaign name). This parameter will holds the name of the internal campaign. I’m going to use the following format for the value of the campaign name parameter

icn=[internal-campaign-name]

I mentioned that you can use two paramters. You don’t need to use two, but GA’s site search can be confiugured to track the internal site search phrase and a site search category. We’ll use the category paramter to track the internal campaign name.

I’m going to name the second paraeter ici (short for internal campaign info). Again make sure the parameter you’re using does not already exist. This second parameter let’s me collect details about the ad the visitor clicked on and the location of the ad.

Here’s a basic format:

ici=[ad-creative]_[location-on-the-page]

You can see that I’m stuffing a lot of information into the parameter. You can put whatever you want and GA will gladly suck it in. By adding more information we’ll get a granluar view of how the internal campaigns perform and which locations and variations lead to tbe most conversions.

If you don’t have different types of internal ads, or just don’t care about this level of detail, then you can ignore the add internal campaign info parameter. It blank, it’s up to you!

Now you need to define the values for all the ads. Thic can get messy if you’re running a lot of internal campaign. But you can do it, just be organized! Use a spreadsheet to keep track of all the values you use.

Once you’ve got al your parameters it’s time to tag your links. The exact process depends on your site. You may need to change static links, like this:

< a href=”/internal-page.php?icn=2010-spring-sale&ici=stubs_home-roller >

Or if you have complicate flash ads you may need to get inside the Flash code. It depends on your site.

The bottom line is when somone clicks on an internal ad you want to see your internal campaign parameter on the next page. If you don’t see the parameter in the URL then you did something wrong.

You can use the sample spread sheet below to track the different parameters you use for your internal campaigns. The spread sheet also has a formula in column D to automatically add the parameters to your URLs.

NOTE: There is an iFrame in this post. If you can not see it, you can view the original post here or view the Google Spreadsheet here.

Once youe’ve got the parameters added to your links it’s itme to configure the Site Search settings.

Step 3: Configure Site Search Settings

Remeber, we’re configuring these settings on a new profile so we don’t break the site search in our main reporting profile.

Site search has three settings. First, turn site search on.

Next, tell GA the name of the paramter that holds the site search phrase (in this case it’s out internal campaign name) by adding the parameter to the ‘Query Parameter’ filed.

Next, choose Strip Query String Parameters. This setting will remove the parameter from the URL after GA processes the data. This is a good idea because it reduces duplicate pages in your top content reports.

TIP: You probably want to exclude your internal campaign name parameter, and internal campaign information parameter, from your other profiles. It can really mess up your pageview data.

If you’re using an internal campaign information parameter configure the Site Search Category settings the same way. Just make sure you use your internal campaign info parameter in the ‘Category Parameter’ setting.

Here’s how the settings look using the parameters from my example:

That’s it! Let’s look at the data.

The Reports

Let’s start by answering a simple question: do people who respond to internal camapigns convert more or less than those that do not respond to internal camapigns? To answer this question use the Content > Site Search > Usage report. Here we can see that there were only eight visits that clicked an internal campaign. Sad! But it’s just test data.

Now let’s drill deeper ad identify which inernal camapigns are most effective. Use the Content > Site Search > Search Terms report. Rather than search phrases this report contains the names of all internal campaigns. Again, what was the response to the campaign? Was it worth the effort? Don’t forget to check the Goals tab and the Ecommerce tabs (if applicable) to measure outcomes!

But let’s drill deeper to understand which ads within those campaigns are working. Click on a campaign name and choose Category from the Analyze drop down.

Now we’re looking at all of the information that we put into the ici query string parameter for this particular campaign name. If we had multiple internal ads we’d be able to differentiate ad placements and creative variations.

Don’t forget to use the Goals and Ecommerce tabs to measure outcomes! This is what most people want to know: did internal campaigns, and specifically which internal campaigns, generated revenue and conversions?

But we can do more. Now change to the Content > Site Search > Start Pages report. Now you can see which page people were on when they click on an internal ad. Again, more insight into where visitors responded to an internal campaign.

And for all those marketing folks that are so concerned with internal campaigns, how about creating a nice custom report and automating the delivery or, better yet, use the Custom Report Sharing feature to share this report with others. People will love this because you can change the wording so it does not say Site Search it says Internal Campaigns Report.

But wait, there’s more! What about using a secondary dimension to view the external marketing campaigns (or sources, or mediums) that drive visitor to react to internal campaigns. Perhaps the extrnal creative has some influence over how visitors react to the internal campaign creative. The data isn’t so hot in the image below, but you get the idea.

And finally, the ultimate in analysis, internal campaign attribution. We can use the Search Term Refinement feature if visitors click on multiple internal campaigns. Google Analytics will track all subsequent site searches, but in our case follow up site searches are actually additional internal campaigns that the visitor responded to. Honestly, I have never found any insights from this type of analysis, but you can do it if you want!

Ok, I’ve officially entered nerdville.

I think you get the idea. By adding all this data you can do many different kinds of segmentation and analysis. More than enough to understand the behavior of your site visitors and how your internal campaigns perform.

Last but not least, I’ll mention that you can track internal campaigns using events and custom variables. But both of those solutions require coding. And that requires working with IT. Using Site Search, in most cases, will not require any code changes to your site.

Share this post:
  • Twitter
  • StumbleUpon
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
  • FriendFeed
  • Sphinn
  • Google Bookmarks
  • Reddit
  • email
  • Technorati
  • Yahoo! Buzz

New Google Analytics Goals

We all know that it’s critical to measure conversions, or goals, for our website. But for a long time Google Analytics limited the number of conversions, and types of conversions, you could track with Google Analytics. All that changes today (October 20, 2009).

You can now create up to 20 goals per profile in Google Analytics. I can literally hear the applause at eMetrics :)

In addition to expanding the number of goals Google has expanded the types of goals to include ‘threshold’ goals for pageviews per visit and time on site.

I think we all know the importance of tracking goals, so I’m not going to get too deep into why you should use goals. If you’re not using goals you should start NOW!

Let’s talk about this new feature.

Goal Sets

Goals are now organized into four sets. Each set of goals can contain up to five different goals.

Google Analytics Goal Sets

Sets have been introduced as a way to accommodate all the new data in GA. In the report tabs, rather than one goal tab there can be up to four goal tabs in a GA reports.

New Google Analytics Goal sets in a report

When creating a goal you can place it in any set as long as there is room. Once you place a goal in a set it’s best to NOT MOVE IT. Google Analytics sees this as a NEW goal and does not move the previously captured conversions to the new goal.

TIP: I like to organize goals by business function i.e. put goals that are related together. For example, if you’re a content site, you might create goals for spending a certain amount of time on site (1 minute, 2 minutes, etc.). I would group these goals in a set all related to time.

Goal Types

In the old days a goal was a pageview that represented the completion of some high value process, like a thank you page. Now goals can be based on actions that have nothing to do with viewing a page. Conversions can be based on how much time a visitor spends on the site or how many pages the visitor views.

Time Based Goals

Time based conversions are triggered after a visitor has spent a certain amount of time on the site. To configure a time based goal enter the hours, minutes and seconds that a visitor must spend on the site before a conversion is counted. Once the visitor reaches that amount of time on the site then a conversion is triggered.

Creating time based goals in Google Analytics.

What’s interesting here is that you can create a time based goal if a visit does NOT reach a certain amount of time. If you choose ‘Less Than’ Google Analytics will trigger a goal if a visit does NOT reach a certain length.

Less Than Goals in Google Analytics

Why on earth would you measure this? I like to think of ‘Less Than’ goals as ‘Failure’ metrics. We often define success metrics, like Conversion Rate, but rarely define metrics to measure our failures!

Using failure based metrics really packs a punch when you’re talking to co workers or clients. For example, when you configure a failure goal you can easily measure and say, “Did you know that 97% of our traffic does not spend at least 2 minutes on our site? We suck!”

Abandonment rate is another well know failure metrics.

Time on site can be configured as a Goal in GA

Time based goals can also be very useful if you’re trying to MINIMIZE the amount of time people spend on your site. For example, if you have a support section on your site you may want to understand what percentage of traffic spends a certain amount of time on your site. Long term you can try to reduce the number of visits that are too long.

How about setting up a goal set for various time intervals and then try to move visitors from one “goal” bucket to the next. 10 minutes, to 7 minutes, to 5 mintues… You guys are bright, you get the idea :)

Remember, time based goals can be affected by creating virtual pageviews and events. Both of these activities send data to Google Analytics and can change how visit length is calculated.

Pageview Based Goals

Another new goal type is pageviews per visit. Like time on site goals this this type of conversion is triggered when a visit exceeds a certain number of pages. I can literally hear all the advertisers clapping out there!

Pageviews goals are set up in the same manner as time based conversions. Just specify a condition (greater than or less than) and the number of pageviews in a visit.

Pageviews per Visit Goals in Google Analytics

Like time goals, pageview goals can also be affected by virtual pageviews. If you’re creating a lot of data using _trackPageview() you need to understand that this can change your overall goal calculation.

URL Destination Goals

The old standby! ‘Traditional’ goals are now called URL Destination Goals. You can still use a regular expression, head match or exact match to identify a page that represents a goal. This functionality has not changed (you can learn more about goals in this old post.)

URL Destination Goal in Google Analytics

Now that we have 20 goals we can easily measure all of those micro conversions (RSS subscription, email signup, reaching product page, downloading white paper… etc, etc, etc).

And yes, you can still use a virtual pageview as a URL Destination goal.

Funnels

Google did spend some time tweaking the interface. The old interface always showed 10 steps in the funnel. Now you can choose the number of fields the funnel form displays. You’re still limited to 10 steps in total. This isn’t such a big deal.

New Funnels interface in Google Analytics

But think about the bigger picture. Do we really need funnels if we have so many goals? With 20 goals we can use a goal to represent each stage in a process, rather than a funnel step? So do we still need funnels?

Yes. Funnels provide a nice visualization of critical processes, so I think they are still relevant. Plus, you need to configure a funnel if you want to measure Abandonment rate, a very nice failure metric that can make people squirm :)

Odds and Ends

A few random thoughts re: new goals:

If you’ve been creating lots of profiles for goals you may want to consider consolidating all goals to a single profile. The benefit is you can have all your conversions in one interface. No more messing with multiple browser tabs and adjusting the date range.

If you need to control the access to certain goals, you may need to create a profile for certain goals and then give only the people who need access to those goals access to the profile.

A visitor can only convert at each goal once per visit. This is the way it’s always been.

And finally, creating new goals will not modify your historical data, only future data. So all those new goals you’re going to create this week will only track from the day your create them onward.

Share this post:
  • Twitter
  • StumbleUpon
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
  • FriendFeed
  • Sphinn
  • Google Bookmarks
  • Reddit
  • email
  • Technorati
  • Yahoo! Buzz

Google Analytics Custom Variables Overview

Today Google releases Custom Variables (cv for short) in Google Analytics. This is an evolution of the custom segmentation feature. This post is meant to give you an overview of the feature. We’ll discuss how to use it in a later post.

Like Custom Segmentation, custom variables are a flexible way to add more information to Google Analytics. The big difference is that you can create LOTS of custom variables. How many? In theory you can set an infinite number of custom variables. But GA has some internal limits that keep you to 50,000.

What can we use custom variables for? The possibilities are endless:

  • Segmenting members from non-members
  • Segmenting customers from non-customers
  • Tracking all the campaigns a visitor sees prior to converting
  • Content categorization
  • Segmenting visitors based on landing page
  • Visitor segmentation based on demographic info
  • Customer segmentation based on order history

Google Analytics Custom Variables are like data decorations!

As my friend Phil likes to say, custom variables are decorations that you hang on your data. Almost like holiday decorations hanging on a tree! This is a really good analogy that I’ll continue in this post.

There are four critical attributes of a custom variable that we must understand in order to use them.

Name and Value

The easiest attributes to understand are Name and Value. The Name of a custom variable is literally the name you give to the variable. Each variable can have many, many values. For example, you could define a variable named ‘Baseball Team’ and then add the values:

  • Red Sox
  • Yankees
  • Phillies
  • Giants
  • Angels

This is totally different than the old Custom Segmentation feature. With Custom Segmentation you were limited to one variable (ie one Name) that could contain multiple values. Now you can create multiple variables each of which can have multiple values.

You can view all of your variable names in the new Custom Variables report.

Google Analytics Custom Variables Report

It’s important to note that the name of a variable, plus the value for a variable must be less than 64 characters. Why? The data is sent to Google via a request for an image file. The actual length of the request is limited and Google wants to insure that all of the data makes it to the server.

Scope

Google Analytics custom variables depends on the scope of the variable.

The real power of custom variables comes with something called the Scope. Think of scope as the different ‘levels’ of visitor data. When a visitor visits a website Google Analytics collects data at three levels:

  • Pageview level: This is data associated with each page viewed during a visits. Page level data can change from one page to the next.
  • Visit level: This is data associated with the visitor’s entire visit. This data can change from one visit to the next. But visit level data is applied to every page within a visit. This data only exists for the CURRENT visits.
  • Visitor Level: This data is applied to the visitor and every visit and every pageview that the visitor generates. This data persists across all visits that a person creates. How does it persist? Via a cookie.

This means we can set information, ie custom variables, at the page level, the visit level and the visitor level. If we think of custom variables as decorations “hanging” on our data then we could use the following graphic:

GA Custom Variables "hanging" on your data.

So scope is the same as level. Anyone drooling out there?

The ability to control the scope of a custom variable makes this feature extremely flexible. For example, if you want to group all of the content on your site you can add a page level custom variable to every page that identifies the groups that a page belongs to.

If you want to segment visitors by their purchase history you can add visitor level custom variable. The possibilities are truly endless.

Let’s take a look at some of the reporting so you can get a feel for some of the data.

Here’s the Custom Variables report. You’ll notice it looks a lot like the user defined report. This report contains all of the variables that you defined. If you click on a variable you’ll see all of the VALUES for that variable.

So why has google added a scope if we can’t see it in the reports? I’m just going to let you guys speculate. But it’s obviously a critical part of CVs and we should see that data.

Index

The last attribute that we need to discuss is something called the Index. To be honest, it’s really hard to define the index. Basically the index is a technical attribute that helps GA organize all the custom variables on a page.

It’s only used during the implementation, so we’re not going to dig any further in this post.

Speaking of the implementation, you’ve probably noticed that I haven’t talked much about the implementation. To be honest, we’re still playing with CVs. Obviously this data comes from JavaScript. So you have to do some coding to get this data.

But I’m going to hold off on the implementation talk until later. Implementation involves another concept called the Index which is, to be honest, vague and confusing.

Share this post:
  • Twitter
  • StumbleUpon
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
  • FriendFeed
  • Sphinn
  • Google Bookmarks
  • Reddit
  • email
  • Technorati
  • Yahoo! Buzz

Tracking Zero Result Searches in Google Analytics

I <3 Google Analytics Site Search reports. There’s amazingly actionable data in those reports. But they’re missing one vital piece of information: searches that don’t produce any results.

Why is this important? Don’t you want to know when visitors search and don’t get any results? Zero result searches can help your identify missing content on your site or a problem with your site search engine.

fenway-scoreboard

Many search solutions will provide this information for you. For example, I use Search Meter for WordPress and it shows me which search queries generate zero results. But I thought it would be interesting to add this data to Google Analytics. That way all my site search information would be in one place.

Unfortunately there is no easy way to add this data to GA. You need to do some programming to collect the data. So this post is really meant for those folks with programming resources AND for those developers that maintain GA plugins. Like my buddy Joost, who has a great GA plugin for WordPress.

If you’re interested in the data and analysis, skip to the bottom of this post.

Conceptual Overview

Our goal with this hack is to modify site search data in two ways. First, we’re going to put all search queries with zero results in a category. This will allow us to use the Search Categories report to easily find all the search terms that yielded zero results.

Second, we’ll modify the actual search terms to indicate that a term yielded zero results. This will make it easy to scan a list of all the search terms and identify which generated no results.

Before we get into the implementation, a big THANK YOU to Charles Miller, one of the lead consultants here. He wrote the JavaScript below. Thanks Charles.

Step 1: Identify No Result Search

The first step is to identify a zero results search page. Most websites have the same search results page regardless of the number of results. You need to identify some something that differentiates a zero results search page from a non-zero results search page.

This must be done programatically and is the hardest part of the implementation.

For example, a zero results search page on this blog has the text “No posts found. Try a different search?”

No Posts Found

I can create code (or more specifically, Charles can create code) to look for the text “No posts found. Try a different search?” If the code finds this text in the page then I can identify that the visitor’s search yielded zero results and than I can send the data sent to GA. Here’s the code that I’m using on this blog:

var content = document.getElementById('content');
if (content.innerHTML.search('No posts found.')) {

The code looks for a section of the page called ‘content’ and then searches that section for the phrase ‘No posts found.’. If ‘no posts found.’ is found (oh, the irony!) then we will modify the data sent to GA.

Important! The way you detect a zero result search page may be different. It’s VERY difficult to create an example that will work for everyone. Take this as a conceptual overview.

Step 2: Tweak GA Tracking Code

Once we know what differentiates a zero results search page we can add some code that tweaks the data. Remember, we want to modify the data in two ways: 1. by placing it in a special search category and 2. by modifying the search term to indicate it did not yield any results.

To create the category all we need to do is add an extra query string parameter to the URL.

To manipulate the search term we need to split apart the page URL and then put it back together with the phrase no-results.

Here’s the complete code.

<script type='text/javascript'>
var pageTracker = _gat._getTracker("UA-XXXXXX-1");
var content = document.getElementById('content');
if (content.innerHTML.search('No posts found.')) {
     // These lines get the search data from the URL and
     //  deconstruct the URL into parts
     var sn = "s";
     var sr = new RegExp(sn+"=[^\&]+"),
      p = document.location.pathname,
      s = document.location.search,
      sm = s.match(sr).toString(),
      srs = sm.split("="),
      // The next line is where we add the category and add
      // the phrase no-results to the search term.
      sre = sm.replace(sr,srs[0]+"=no-results:
 "+srs[1]+"&cat=no-results"),
      sf = s.replace(sr,sre);
      // Send the data to Google as a Pageview
      pageTracker._trackPageview(p+sf);
} else {
      // If this is a regular page on the site, use the standard GA code.
      pageTracker._trackPageview();
}
</script>

The code starts with the section that identifies a zero result search page.

Then we deconstruct the URL to identify the search term. Finally we add the category named ‘no_results’ and the phrase ‘no-results’ to the search term.

If the code does NOT find the term ‘No posts found.’ then a pageview is created as normal.

That’s it for the coding part (thank goodness!)

Step 3: Configure Site Search Settings

The last step is to add the new category parameter to the Site Search settings so GA can identify the no-results search category. This is easy, it’s in the profile setting section of Google Analytics.

How to set a search Category parameter in Google Analytics

I also like to set the ‘Strip Query Parameter’ to YES. This removes the category parameter after site search is done processing and normalizes your pageview data.

That’s it for the configuration! We’re cleared for insight-hunting!

Analyzing The Data

When a visitor performs a search that yields zero results the search term will be placed in a category named ‘no_results’. To find this data navigate to the Content>Site Search>Categories Report:

site-search-categories-google-analytics-2

Immediately you’ll be able to see what percentage of your searches yield zero results. Hopefully it’s very low! Want to see if this impacts conversions or revenue? Click the Goals or Ecommerce tab to check the conversion rate:

Zero Result Searches Impact on Website Outcomes

This is a bad picture, but you get the point.

Next you can click on the no-results line in the data and see exactly which search terms yielded zero results.

Search terms that had no results in Google Analytics

This is super-actionable data. Now you know where you may be missing content or if your site search engine might be broken. You should be asking yourself, “Why are there no results for these terms? Is there missing content or is there a problem with my site search engine?”

You’ll also notice that the search terms now have ‘no-results’ in them. This provides a lot of flexibility for view the search data other ways. Example, let’s use the Search Terms report:

Google Analytics site search queries

Here we can see the search terms ranked by searches. What percent of your top 10, 20 or 50 are no-result searches? How is that impacting your bottom line?

This is just the start. You can use other metrics, like %Search Exists to understand if visitors who receive zero results refine their search or exit.

While this is not the easiest thing to configure, I hope you see the value of the data. More so, I hope that all those folks that maintain plugins add this type of feature to their GA plugins. Joost, you listening!?

Share this post:
  • Twitter
  • StumbleUpon
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
  • FriendFeed
  • Sphinn
  • Google Bookmarks
  • Reddit
  • email
  • Technorati
  • Yahoo! Buzz

How Google Analytics Tracks ‘Bookmark’ Visits

I was recently inspired by a Tweet to write about how GA tracks visitors that use a bookmark to access a site.

Simply put, Google Analytics will attribute a ‘bookmark’ visit to the information in the Google Analytics campaign cookie.

Many people believe that GA tracks bookmark visits as (direct) traffic. Google Analytics does not track bookmark traffic as (direct) traffic unless (direct) is the value in the cookie. Whatever is stored in the campaign cookie becomes the source of the ‘bookmark’ visit.

The cookie is named __utmz, I’ve talked about a few times, in my series on Campaign Tracking and my post on GA – CRM integration. __utmz always stores where the visitor came from (organic search, campaign referral, etc.)

How about a quick video to walk through an example and save me some typing.

Share this post:
  • Twitter
  • StumbleUpon
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
  • FriendFeed
  • Sphinn
  • Google Bookmarks
  • Reddit
  • email
  • Technorati
  • Yahoo! Buzz

Count Me Out: GA.JS Version

A while back I wrote a post called Count Me Out! that explained how to exclude Google Analytics data based on the custom segment value.

My previous post was based on the old, urchin.js tracking code, and a lot of people have been waiting for an update. It’s taken a while, but here it is.

I will mention that my favorite way to exclude traffic from Google Analytics is using an IP exclude filter. An IP based exclude filter is very accurate unless you having a changing IP. The method below works best if you have a dynamic or changing IP address.

Even if you’re not interested in this post, there is a fun ‘group activity’ below. Please try it!

The old version of this hack method required you to add a new page to your website. That page would set the GA custom segment cookie (named __utmv) on your computer.

This technique works fine, but who wants to add a new page to their site? It can be a pain.

I’ve simplified this technique by removing that page. You can enter the JavaScript directly into your browser.

Step 1: Set Custom Segment Cookie

Go to the site that you are tracking with Google Analytics and view a page.

Copy the code below and paste it into the location bar of your browser and click ‘enter’ on your keyboard.

You should see a message that says, “Custom segment has been set. Time to create a filter.”

Here’s a tip, you can bookmark this JS to make it easy to reset the cookie in the future. I set the cookie every time I fire up my browser.

Step 2: Create Exclude Filter

Next, create an exclude filter in Google Analytics to exclude the user defined segment (i.e. the cookie) you just created:

This filter will exclude anyone with a custom segment cookie with a value of ‘remove-me’.

Remember, cookies are specific to a browser and computer. If you use mulitple browsers or multiple computers you need to set the cookie using all the browsers on all the computers you use.

Having Some Fun With This!

You’ve probbaly figured out that you can set the custom segment cookie on anyone’s website as long as they’re using GA. This means that you can add data to their User Defined report. Let’s try this on my site!

Navigate to www.cutroni.com/blog and place the following code in the location bar of your browser after the page has loaded. Change FOO to whatever you want and press enter on your keyword. That’s it. You’re now in my data.

I’ll post some of the more popular and creative values in Twitter and maybe here at a later date.

Please try to keep it clean. I often review data with my 4 year old son :)

Thoughts on the Old Method

The old version of this technique uses a form to set the custom segment cookie which is pretty handy if you have a lot of people in remote locations that need to be excluded from the data. Just send all your coworkers, contractors, etc. a link to the page and ask them to set the cookie on their computer. It’s a little easier than asking them to paste JS into their browser.

If you’re interested in using this technique here is a new version of the page and the process.

Step 1: Create a new page on your site using the code below.

** Note ** The information below is in an iFrame. If you receive this post via email you may not see the contents.

Step 2: Go to the new page you just added, fill out the form, and click the ‘Create Cookie’ button. Keep track of the value you enter into the form, you need it for step 3.

Step 3: Finally, create an exclude filter in Google Analytics to exclude the value that you entered into the form. Remember, you need to use a regular expression for the filter field. So if you entered ‘remove-me’ in the form, enter ‘remove-me’ as the Filter Field.

That’s it. Sorry for the lame post, but I’m trying to update a lot of the old code and posts on the site.

Share this post:
  • Twitter
  • StumbleUpon
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
  • FriendFeed
  • Sphinn
  • Google Bookmarks
  • Reddit
  • email
  • Technorati
  • Yahoo! Buzz