Advanced Google Analytics: Conversion Goals (Part Three)
May 29, 2008 in Analytics, Expert AdviceIn part one of this series I covered the basics of setting up goals in GA (Google Analytics).
In part two I covered setting up funnels.
These are both straightforward techniques that everyone should be using because you can do them without ever touching your website (assuming you have the GA code installed on your site, of course).
Today, I'm going to cover a more technically advanced topic. Namely, tracking things that don't have a distinct page view associated with them. This one will require some web page editing know-how, and a little bit of programming savvy, but not a ton if you carefully follow along.
Tracking goals with no distinct associated pageview
Remember that goals are really just a pageview that you've specified as being a goal inside GA. To track a goal without a distinct pageview associated, we're going to simulate a pageview using simple javascript.
First, let's define what we mean.
Here are a couple examples:
Let's say you've got a software download you offer, but visitors just click a download link to get the software. There is no specific pageview, just a link someone clicks to download a file.
Or, you have a registration form that when filled out - doesn't go
to a specific unique page you can enter into GA. Maybe it goes to their
new profile page, but that's not a page that only constitutes
the completion of a goal because this same user (and others) will
return to that same page many times in the future.
Here's how we handle that:
It's simple and brilliant really, you just use a snippet of javascript code (provided by Google) which simulates a pageview.
When the action you desire has taken place (say, they clicked the download software link, or they filled out the form), you use the little javascript call to simulate a pageview.
Let's walk through an example:
First, set up your goal as before. This time pick Exact Match, and
for your Goal URL, you can make it anything you'd like. Start with the
slash, (/) and then use a fairly descriptive name, no spaces. It can be
anything you want. This is the pageview we'll be simulating in a moment. For the Goal name, this is how it'll appear in the report, so put something meaningful. (Only you will see it.)
Define a funnel if you wish, these would be the pages leading up to the goal. Perhaps you have a product screenshot tour, followed by the download link. Put the steps to the tour in the funnel.
Now comes the technical part.
Move the original GA code to the top of the page
First - On the page where the goal happens (from our example above, the page where the software download link is) you're going to need to move the original GA code to the top of the page instead of the bottom (which is where they initially tell you to put it). The safest place to put it is right after the first <body> tag. It must appear before the new snippet we'll be using below to simulate the pageview. If needed, you can do this for every page, not just the ones where the goal happens.
Make the pageview simulation javascript call
Don't get freaked out! This sounds complicated, but it's simple. All you need to do is have the following javascript where your desired action takes place.
pageTracker._trackPageview('/GOALPAGEHERE')
So, for our example above, on the software download link, I'd do the following:
<a href="MySoftware.zip" onclick="pageTracker._trackPageview('/DownloadSoftware')"> Download Software!</a>
The part in red, is the part I added. the "onclick=..." mumbo jumbo says, when someone clicks this link, make this javascript call which simulates a pageview. Note the value I have in the parenthesis and single quotes matches the value I put as the Goal URL above. These values must match.
Ok let's do another one with our second example, someone is filling out a signup form.
Here's how we'd define our goal inside GA.
You have two options with simulating the pageview. You can either trigger it when the form is submitted this way:
Option 1:
Put the part in red in the form tag on your signup form.
<form action="..." method="..." onsubmit="pageTracker._trackPageview('/NewSignUp)">
Option 2:
Or, you can use your backend code to show the following on the profile page, only after a signup happens. I'd put this at the bottom of the page just before the </body> tag:
<script type="text/javascript">
pageTracker._trackPageview('/NewSignUp');
</script>
And that's it!
This tip requires a bit more technical savvy, but if you have a scenario where you need to track a goal without a distinct pageview associated, it's the best way.
Hope this helps.
In our next, and final installment, we'll discuss how to track track the income from certain goals (goal value tracking).
This series has been great! My analytics will never be the same. I have changed my use of analytics completely.
Thanks.
Posted by: Mike Michalowicz | Jun 3, 2008 2:16:21 PM
Thanks for the feedback Mike, I'm glad you've found it useful.
Posted by: Carson | Jun 3, 2008 2:21:45 PM
Great tutorial Carson, you really made it easy to understand - and I only have about 6 months of self taught html behind me.
Can't wait to see some figures on what was previously "hidden"!
Posted by: Jon Weston | Sep 19, 2008 11:30:55 PM
great ive been looking for this thanks
Posted by: el | Nov 9, 2008 9:51:05 PM
Hey this was a really great post..helpful!
I have a question about tracking new sign ups. Sometimes when users are signing up on my website, they make errors in the sign up form (not matched password ,not everythings filled out ect) which they only find out after hitting the submit 'sign up'button that we are using as a simulated page view. Since they hit sign up , would this count as the completed goal?....even tho the real 'goal' *tracking new sign ups* isn't completed because the user signing up must go back to fix the errors in their sign up page? Or Would the use of option 2 under your new sign ups section, rectify this problem?
Thanks for the answer and thanks for the post!
Brittany
Posted by: brittany | Mar 8, 2009 5:14:27 AM
Hello Carson,
This is a great post! You are a great teacher.
Even I understood how to implement it.
I have a question about Google Analytics Goal Setting & Funnel functionality.
This functionality on GA always give me smaller number than actual.
When I try to reconcile GA's conversions and conversions from database, they are very different. I think it happens because my site allow visitors to make multiple submission within 1 visit(session) and GA only counts 1 submission from 1 visit even if a visitor made more than 1 submission during the visit.
Do you know a way to track and count multiple conversions from one visit(session)?
I think it is a common issue but I could not find any solutions on the web.
I'd be happy if you can give a comment about this.
Thanks very much!
Rich
Posted by: Rich | Mar 24, 2009 9:46:42 AM
Hi Rich, GA will only count any conversion once per visitor session. You can have multiple conversions, but they have to be on different goals. This is to prevent people from refreshing the confirmation page, or something and getting counted twice. If you need to count multiple conversions to the same goal for a visitor, GA probably won't be your best choice for tracking software in that case.
Posted by: Carson McComas | Mar 24, 2009 1:03:03 PM
Carson,
I see. I guess it is just not made to do what I want. Thank you for your comments. I'm going to study a bit more about E-commerce functionality of Google Analytics to see if I can get what I need.
Thanks!
Posted by: Rich Ueno | Mar 26, 2009 8:47:16 AM
Just found this in a Google search. I followed your instructions and it worked. Thank you so much for the resource, very easy to follow.
Posted by: Erica | Apr 23, 2009 11:32:08 AM
Youre a LIFE SAVER!!!!!!
THANKS
Posted by: Online Sports Betting | Apr 27, 2009 2:55:16 AM
Hi,
thats great!
However my final analytics code is globally set before the tag.
So I decided to add the same code twice, one in the beginning, one in the end.
And the onsubmit code inbetween (where the form is).
You thinks this works?
Thanks -wg
Posted by: Wellness Guy | Jun 27, 2009 2:47:59 AM