Time-On-Page Goals in Google Analytics & Website Optimizer

September 5, 2007 by Justin Cutroni

Today the Website Optimizer team introduced some new features that will make Optimizer much easier to use. I’m going to defer to the guys at GrokDotCom for coverage on the new features. They got their post up pretty fast and included a snazzy interview with Tom Leung (the Website Optimizer product manager). Please take a moment and check it out.

I’d like to highlight a seemingly minor update to the WO documentation that opened my eyes. Along with the new product features, the WO team published a simple tutorial about how to track time-on-page based conversions. This method can be used to create conversions based on how much time a visitor spends on a page.

How much TIME!Why is this important? Some conversion activities have nothing to do with completing a process. Some conversions measure how engaged a visitor is with a website. While there are many ways to measure engagement, and many different opinions about what engagement is, time spent reading a certain page is one way to measure engagement.

Anyway, the method that the optimizer team published in their support doc can be used in Google Analytics to create time-on-page goals. The secret to the tracking is translating how much time a visitor spends on a page into a pageview. Remember, goal tracking in Google Analytics is based on a pageview. We need to create a pageview that indicates the visitor has been on a page for a certain amount of time.

How it Works

To translate time on page to a pageview we use a nifty JavaScript function called setTimeout(). This function will ‘do something’ after a specified interval of time. We can use setTimeout() to create a pageview after some period of time has elapsed. How do we create pageviews in GA? With urchinTracker().

Here’s the code that will create a pageview after a certain amount of time:


<script>
setTimeout('urchinTracker("/read-pages?page="+
_udl.pathname+_udl.search);', 20000);
</script>

You’ll notice that there are two parts to the setTimeout() function. They’re separated by a comma. The first is urchinTracker(). That’s what will create the pageview after a certain amount of time. The second part is the number 20000. That’s the amount of time that setTimeout() will wait before executing urchinTracker() and thus creating the pageview.

The time is in milliseconds. 1000 milliseconds equals one second. So 10000 milliseconds = 10 seconds.

Place the code, below the standard GA page tag. Once the page loads the timer will start. When the time limit is reached the urchinTracker() function will execute and a pageview will be created for the value passed to urchinTracker(). I’ve used a couple of Google Analytics variable to define the name of the pageview.

udl.pathname is the part of the URL that occurs after the domain extension (.com, .net, etc.) and before any query string parameters (which usually start with a question mark).

_udl.search is the list of query string parameters that appear after the path.

The code will create a pageview for a fictional page named ‘/read-pages’. Part of the fictional page URL will be a query parameter named ‘page’ that stores the name of the page that the visitor was on when the pageview was executed. This setup gives you a lot of flexibility when setting up the goal.

Here’s how the goal would be setup:

Goal Settings for Time on Page Goal

And here are some additional settings I’ve added to this goal:

Additional Settings for Time on Page Goal

The goal is defined as a regular expression. So any pageview that matches ‘/read-page\?page=’ will contribute to the goal total. Using this setup you can create one generic goal called ‘Read Page’ and then use the Goal Verification report to segment the conversions and identify which pages people actually read.

An Example

Let’s say we want to track how many people stay on the following page for 3 minutes:

http://www.epikone.com/blog/2007/08/29/segmenting-members-from-non-members/

First we need to translate minutes to milli seconds:

3 minutes = 180 seconds
1 second = 1000 milliseconds
3 minutes = 180000 milliseconds

Now we’re ready to add the code to the page. Remember, it must go below the standard GA page tag:


<script>
setTimeout('urchinTracker("/read-pages?page="+
_udl.pathname+_udl.search);', 180000);
</script>

After a visitor views the page for 3 minutes the code will create a pageview for:

/read-pages?page=/blog/2007/08/29/segmenting-members-from-non-members/

And a goal conversion will follow.

A Note About Website Optimizer

Obviously this technique will work for tracking conversion in Website Optimizer. The implementation is slightly different. You need to include the account number in the SetTimeout() function. The reason is that the GA code might have a different account number than the Website Optimizer.


<script>
setTimeout('_uacct="UA-XXXXXX-X";
urchinTracker("/read-pages?page="+_udl.pathname+_udl.search);',
20000);
</script>

Conclusion

I can’t believe that I didn’t think of this method before. :) Thanks WO team for posting that very cool article.

Now, what about number of number-of-visit goals or time-on-site goals? I’ve got the number of visits goal tracking figured out and I’m working on a generic time on site. Stay tuned.

Subscribe:

All About Google Analytics Goals

July 7, 2007 by Justin Cutroni

Goal!Google Analytics Goals are a way to measure conversions on your website. A conversion occurs when a visitor does something you want them to do. This could be completing some type of high value process or viewing a specific page on your website.

Setting up goals is one of the most important steps when configuring Google Analytics. Without goals, there is no easy way to measure conversions. If you’re unfamiliar with conversion, or the related metric conversion rate, please take a moment to read about why both of these metrics matter. In general, counting the number of conversions and tracking the conversions rate is a good way to measure the success of your website.

During this post I’m only going to cover how goals work and how to set them up. I’ll discuss how to use goals in my next post.

What’s A Goal (Technical)?

At its core, a goal is just a pageview. It’s could be a specific page on your website that you want the visitor to see or the page that is displayed when a visitor has completed a process. A goal is literally defined by the URL of said page. As GA processes site data, it increments the goal counter each time a pageview for the ‘goal’ page is found. It should be noted that if the goal page is found multiple times in a single visit then goal counter is only incremented once.

I’ll explain a little bit more about how goals work, at a technical level, at the end of this post. There’s a few things I need to cover before we get into the nitty-gritty tech stuff.

Creating A Goal

There are multiple ways to define a goal. The method you choose depends on the complexity of your website. The easiest way to create a goal is to copy the URL of your goal page from a browser into the Goal URL text field. So, if the process ends with http://www.epikone.com/thankyou.php, enter http://www.epikone.com/thankyou.php in the Goal URL field. Here’s another example. If the URL of the goal page is http://www.epikone.com/thankyou.php?submit=true then enter http://www.epikone.com/thankyou.php?submit=true into the Goal UL field.

Goal Settings

A goal can also be defined using a regular expression. Rather than enter an exact URL in the Goal URL field you can enter a regular expression. This is particularly helpful if the website is dynamic. If the goal page contains a unique identifier then you can’t copy and paste a URL into the Goal URL field. Every goal URL will be different. You need to use a regular expression for the Goal URL. I’ll discuss this below in the Additional Settings section.

Goal Name
When defining a goal you also need to give the goal a name. There’s nothing special here. The Goal name will be used to identify the goal in the Google Analytics reports. Don’t use anything too long, it can make the reports difficult to read.

Activate Goal
The Activate Goal setting is an on-off switch. Switching the setting to ‘Off’ will stop tracking for the goal. Why would you want to turn a goal off? Google Analytics will calculate an overall website conversion rate using all of the goals you define for the site. If you create a goal that is temporary, say for a specific campaign, then it could artificially skew the overall site conversion rate if you leave the goal on after the campaign, ends.

Additional Settings

Each goal has an Additional Settings section that can help configuration in unique situations. It’s located at the bottom of the page under the Funnel settings. By the way, you do not need to create a funnel when you create a goal. Defining a funnel is optional.

Additional Settings

Case Sensitive
The Case sensitive setting can be used with websites that have mixed-case URLs. So, if your Goal URL value is case sensitive then click the Yes radio button. However, profile filters can affect this setting. I’ll explain more at the end of this post.

Match Type
Match!
The Match Type setting is a powerful setting that can aid in goal tracking. For example, if each goal page contains a unique customer identifier then it will be impossible to paste a single URL into the Goal URL field without the use of the more sophisticated match types. Google Analytics has three different match types that can be used for Goals and Funnels.

Exact Match
When you choose Exact Match the value in the Goal URL field must exactly match the URL of the goal page displayed in the location bar of the visitor’s browser. This is the setting you want to choose if you copy the URL from the browser and paste it into the Goal URL field. If your website uses a unique identifier in the goal URL (like a visitor ID number or an order ID number) do NOT use an Exact Match. Use a Head Match or a Regular Expression.

Head Match
The Head Match is like a light-weight regular expression. You should use a head match when a small part of the goal URL differs from one visitor to another. With a head match, if the value entered into the Goal URL matches any part of the URL in the visitor’s browser then the goal will be counted. The Head Match will match both path data and query string variables.

For example, if there is a unique identifier in the goal URL then you can use the head match to define the goal. Let’s say the Goal URL for a visitor is http://www.epikone.com/thanks.html?submit=true&id=12345. The id query string parameter is a unique identifier that will change from one visitor to the next. So, I could use a HEad Match and enter the following into the Goal URL: http://www.epikone.com/thanks.html?submit=true. Because the Goal URL matches PART of the actual URL for the goal page, GA will count this goal.

Regular Expression
This setting defines a goal using a regular expression. If the regular expression entered into the Goal URL matches any part of the goal URL then the goal counter is incremented. Using a regular expression is particularly useful because it let’s ‘wrap up’ goal tracking so you track multiple goals in a single goal. You can track multiple goals using a single goal because a regular expression can match multiple URLs. For example, let’s say you want to create a goal that tracks and PDF file download. You could enter \.pdf into the Goal URL field. I actually wrote about using regular expressions to get more out of goals last year.

Goal Value
Money

The final option in the Additional Settings section is Goal Value. Use this field to monetize non-e-commerce goals. For example, if each Contact Form submitted by a user is worth $100, enter 100 in the Goal Value field. Google Analytics will use 100 to calculate return on investment (ROI) and other revenue based calculations. If e-commerce tracking is active for a profile, and you would like to use e-commerce data for your goals, simply leave the goal value field blank. Google Analytics will pull in the e-commerce data.

One thing to note is that the Additional Settings are applied to both the values in the Goal URL and Funnel steps. I know I’m not covering funnels in this post, but this is a common mistake. It is not possible to use an Exact Match for your funnel steps and a Regular Expression for the Goal URL.

Tips, Gotchas & More

Let’s dig a bit deeper and learn how GA actually counts goals. During data processing the value you use to define a goal is compared to the Request URI value. You remember the Request URI, right? It’s part of the URL (everything after the .com, .net or .org). I know this seems strange especially because a goal can be defined by a complete URL, but this is how the data processing works.

It is important to understand that the Request URI is used during goal processing because if you create a filter that modifies the Request URI then it might break your goals.

Here’s an example. Let’s say the Request URI, in its original form, is /pages/html/index.html. You decide to modify this value using an advanced filter and it becomes /pages/index.html. If you define a goal using /pages/html/index.html then the goal will not work. The reason is that the Request URI (/pages/index.html), which was changed by the advanced filter, no longer matches the value entered as a goal (/pages/html/index.html).

How about another example? If you force the case of the Request URI to lowercase, and then define a filter using all uppercase characters AND specify that the goal is case sensitive, then the goal will not work. Get it?

I know this seems strange, especially when most people use an exact match to define their goals. But that’s the way goals work, honest! Don’t be alarmed by this. Using an Exact Match is a perfectly fine way to define a goal.

Here’s a tip. You can also define goals based on data created by urchinTracker(). Remember, if you pass a value to urchinTracker() then that data becomes a pageview in Google Analytics. These pageviews can then be defined as goals. You can read more about urchinTracker() in this series of posts. I’m using this technique to track RSS subscriptions on my blog.

And finally… A great way to debug goals is to use the Top Content report. Remember, a goal is just a pageview. If GA is reporting 0 goals, then check the top content report. Does the goal page appear in the Top Content report? If it’s missing, then there is probably an issue with your page tags. But, if the goal page is present in the Top Content report then there is probably an issue with your goal setup.

Wow… that’s a long post. Does it all make sense? Leave a comment and let me know!

Subscribe: