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="http://www.example.com/urchin.js" type="text/javascript"></script>
<script src="http://www.example.com/custom_se.js" type="text/javascript"></script>
<script type="text/javascript">
_uacct = "UA-******-*";
urchinTracker();

And here are the files to download:

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

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

6 Responses to “Getting Google Analytics to extract keywords from Google Image searches”

  1. Hello Joost,

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

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

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

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

    if (_ubd.referrer.search(/images.google/) != -1) {
    var ref = _ubd.referrer;
    var tldregex = new RegExp("images.google.([^\/]+)");
    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 = "http://www.images.google." + tldmatch[1] + refmatch;
    } else {
    _ur=_ubd.referrer;
    }

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

Comments closed, if you feel you have something to say:
drop me a line.

3 Trackbacks to “Getting Google Analytics to extract keywords from Google Image searches”