Tracking multiple pages with the same URL in Google Analytics

What Jar of All-Black M&Ms Candies courtesy djwudi @ do you do when you’re trying to put Google Analytics on a dumb-ass checkout process which uses the same identical URL like /stupidcommerce.cgi for every step?

Naturally any web analytics package is going to see every step every user performs as views of the same page and count them all together as the same page, which is basically as ridiculous and impossible as attempting to determine the ratio of red M&M’s to green M&Ms in a jar full of black M&M’s (see diagram at left).

Though far from obvious to most, fortunately Google Analytics is flexible enough to let you solve this dumb problem and add some color back to your candy jar, but not before wading knee-deep through the help file to decipher the steps required. Until now…

The documentation for Google Analytics is terrible for novice webmasters (or web designers suddenly given webmaster responsibilities) who have little or no JavaScript experience. Since these are the least sophisticated and thus the largest segment they’re targeting with this service, you would think they would take the time to hold a new webmaster’s hands through the process of understanding how to implement a GA solution with, say, a poory-implemented yet somehow successful e-commerce site that doesn’t do any PPC (yet?) with an uncooperative and poorly-documented commercial shopping cart platform. You know, just for instance…

Let’s consult this poor excuse for documentation we get from Google, shall we:

To get around this, you can call the _trackPageview function within each step (probably within an onload event), as follows: [Novice: oh probably, yes, but I don’t have time to party at some event… I need stats damnit!]

Note that the path/filename argument need not represent an existing path or filename. The argument to _trackPageview simply provides a made-up pagename to which Google Analytics can attach pageviews. [Novice: I try to avoid arguments, especially with my computer.]

Important: Please note that your analytics tracking code and calls to _gat._getTracker must be placed on the page above the call to _trackPageview. [Novice: Dreamweaver let me paste it into the very top of the page, but will it still work if I make the code really small and the same color as the background so it doesn’t show up anymore?]

As if that’s not bad enough, Google’s help page for this problem ends on this little high note:

To verify that _trackPageview is being called correctly, you can check your Top Content report 24-48 hours after the updated tracking code has been executed [all emphasis added]. You should be able to see the assigned pagename in your report.

Oh that’s okay Google, I didn’t need to know if my code changes and conversion tracking configuration actually worked for at least a couple more days anyway. Seriously, they can’t do better than this?

Anyhow, enough Google-bashing (for now). Here’s a real-world fake example of actual working code you can easily adapt to fit your situation:

Let’s say your e-commerce site has four conversion steps: 1) View Cart, 2) Shipping Address, 3) Billing Info and 4) a Thank You page. Let’s say the URL, /stupidcommerce.cgi, never changes, not even with a unique URL argument like /stupidcommerce.cgi?step=2 but literally just /stupidcommerce.cgi for every step in the process. With me so far?

Ok, so here’s a typical Google Analytics code snippet:

<script src="" type="text/javascript">
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");

The highlighted line is where the visitor’s browser actually contacts Google to inform them of the page view. If the parentheses are left blank — as in (); — the current actual URL is used. This is the default behavior which should work under normal circumstances with either static pages or a dynamic system like e-commerce with a more search-friendly design.

However, you don’t have one of those, so you need to modify this line of code in each page (or template file more likely) of your checkout process, and insert between the parentheses a unique identifying URL enclosed in single quotes. You should literally make it up out of thin air, but you don’t have to create the files on the server. Just invent fake unique URL’s you’ll never actually use, like for the View Cart page you could use (’/ConversionEvents/ViewCart’); and the Billing Info page you could use (’/ConversionEvents/Billing’); and of course the Thank-You page after a successful order should have (’/ConversionEvents/OrderComplete’);.

Neither the directory /ConversionEvents nor any files within it such as ViewCart actually exist, you understand, they’re just literally invented to send to Google Analytics when the user hits that step in the checkout process so a unique URL gets recorded instead of the generic /stupidcommerice.cgi URL.

Here’s a full example of the Google Analytics tracking code to insert into the template (or whatever) for the Shipping Address form:

<script src="" type="text/javascript">
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");

Then all you have to do is log into your Google Analytics account and go to Analytics Settings > Profile Settings > Goal Settings page to configure these custom URLs for goal tracking.

For “Goal URL” enter the invented thank-you page URL you made up above (starting with a slash but not the domain, like “/ConversionEvents/OrderCompleted” without the quotes). Set the “Goal Name” to something like “Order Completed”.

Under “Define Funnel” enter the URLs in the same slash-first format, in the linear order of the checkout (or whatever) process, defining some name that will be meaningful to you when viewing reports.

That’s it. Save your changes and wait 1-2 days for the world’s largest server cluster network to catch up to you, and you will finally get to see an accurate conversion rate and the drop-out rates for each step, no thanks to your insipid e-commerce software.


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

One Response to “Tracking multiple pages with the same URL in Google Analytics”

  1. Hi! This is a great article – how can i pass the ? var along as well though, and not just make the link into a static one? In my case knowing what the variable was is invaluable, and not just strip it as in your example above.

    Leaving the google code as default will pass the url intact with the argument, but it’s a bit too long. I’m hoping to replace it with a static word + text after the ?.

    Is this possible?

Leave a Reply

You must be logged in to post a comment.