Getting Google Analytics to extract keywords from Google Image searches

Google Analytics doesn’t get the keywords people used to find your site using Google Image search, and thus labels them as “referral” instead of as “organic”.

Google Image search gives you referral URL’s that aren’t really readable. The query string that the searcher used to get to that referring URL is hidden somewhere deep down in this URL in the &prev variable. Since Google Analytics can’t read that, it doesn’t get the keyword out of it. That’s the reason why it thinks it’s a normal reffering URL, and Google image search will show up as a referral instead of organic search in your statistics.

Now if your site relies on image search for a significant part of it’s traffic, you’ll probably want to know which keywords were used. I’ve been working hard to find a way to get that fixed, and the solution I have now involves a customized urchin.js, and adding some extra search engines. You will have to put this urchin.js on your own server, but it will still call the small image file from the Google Analytics servers. It basically “rewrites” the referrer to the original Google Image search URL, so no other information is lost.

Next to the customized urchin.js you need the latest version of my custom_se.js, to add all the different Google image search domains. The list of search engines in that file is an array, and Google Analytics will stop at the first encounter of a match, which is why the image subdomains have to be on top. Otherwise, all image searches would look like plain Google searches.

Your code should look something like this:

<script src="" type="text/javascript"></script>
<script src="" type="text/javascript"></script>
<script type="text/javascript">
_uacct = "UA-******-*";

And here are the files to download:

Adding these will make the searches show up in Google Analytics as coming from, etc. etc. Have fun with it!

This post will tell you how to do this with the new ga.js script.

Tags: runs on the Genesis Framework

Genesis theme frameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides you with the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Read our Genesis review or get Genesis now!

9 Responses

  1. Peter van der GraafBy Peter van der Graaf on 4 August, 2007

    Hello Joost,

    I’ve seen periodic changes in the Google Analytics javascript. Do you plan to periodically update your custom version?

  2. Joost de ValkBy Joost de Valk on 4 August, 2007

    Yes of course :) (until I find a way to do this without altering urchin.js)

  3. Peter van der GraafBy Peter van der Graaf on 5 August, 2007

    Then I’m more then willing to test you script. Thanks.

  4. JoseBy Jose on 4 September, 2007

    I just noticed this defect on google analytics too. Is there a reason for them not to fix it? Thanks

  5. TomBy Tom on 24 October, 2008

    Is this the only change you made? I can keep the JS up to date myself if it is:

    if ( != -1) {
    var ref = _ubd.referrer;
    var tldregex = new RegExp("[^\/]+)");
    var tldmatch = tldregex.exec(ref);
    var imgregex = new RegExp("&prev=([^&]+)");
    var refmatch = imgregex.exec(ref);
    refmatch = refmatch[1].replace(/%26/g,"&");
    refmatch = refmatch.replace(/%3F/g,"?");
    refmatch = refmatch.replace(/%3D/g,"=");
    _ur = "" + tldmatch[1] + refmatch;
    } else {

  6. TomBy Tom on 24 October, 2008

    Never mind, just spotted the trackback from your later post. You should add a notice to this one. :-)