Google Analytics and Google Image search: revisited

September 06th, 2007 – 32 Comments

I wrote earlier about using a custom urchin.js to get Google Analytics to extract the keywords from Image Search. Now my colleague Roy recently spoke about this with an engineer from Google, and this engineer suggested that I could just rewrite the one function and add that as an extra javascript instead of using a completely custom urchin.js. This is, of course, way more preferable, because it saves quite some bandwidth, and you won’t have to update every time Google updates it.

What you have to do is this:

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

The custom_se.js adds the extra image search engines amongst other things, so you can see stuff is coming from image search. Otherwise the hits would be counted as “plain” Google. The track-imagesearch.js rewrites the _uInfo function, and makes sure Google “get’s” it’s own image search parameters.

You can download the two zipped together: Track Image-search Scripts.

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

32 Responses to Google Analytics and Google Image search: revisited

  1. Ion de la Paclisa
    By Ion de la Paclisa on 9 July, 2009

    Finally I think I managed to get it work…
    After I checked the “Track extra Search Engines” in the plugin options it appeared in the analytics code
    "... wp-content/plugins/google-analytics-for-wordpress/custom_se.js" type="text/javascript">

    You never said that on the plugin page.. you just kept on putting links…

  2. Robin
    By Robin on 10 May, 2009

    How do I know if this is recording data? How will it show up in my analytics account – under which section? Thanks :)

  3. Joost de Valk
    By Joost de Valk on 19 February, 2008

    By it’s nature, obfuscated code is hard to read ;) Can’t you just minimize it and NOT obfuscate it?

  4. Eoghan
    By Eoghan on 19 February, 2008

    Joost, thanks for the quick reply. If it was only white space removal I would be fully confident however it also obfuscates the Javascript code, hence my doubt. Do you think that the obfuscating would make it work any different? A quick look at the code the compression tool pumps out might give some indication, unfortunately I don’t have the javascript knowledge to make such a call…

  5. Joost de Valk
    By Joost de Valk on 19 February, 2008

    Eoghan: it would probably work just as well! There’s a lot of whitespace etc. in the file…

  6. Eoghan
    By Eoghan on 19 February, 2008

    Joost, Thanks for making this script available. I have been using it for several months now. As I am going through an effort to reduce the size of my website I ran the 9kb custom_se.js script through the compressor at and the compressed version is just over 50% smaller. Do you know if there would be any problems with this smaller version? Would it work as the original version?

  7. webdesign
    By webdesign on 20 January, 2008

    i tried the code as well !! it worked fine ! you can see every referer !! i even added a few of my own.

  8. Rhoda
    By Rhoda on 17 January, 2008

    I would like to say that I converted one web site to the new ga.js for Google Analytics. I also converted the custom_se.js file listing the search engines. I now see but only as a referral. Clicking on the listing does not lead me to the keywords as it does with the organic listing for in the old system with the urchin.js. In the old system I also have image listings from other engines too all called organic which will lead to keywords by clicking on the organic listing.

    Not sure what the problem is.


  9. Kristjan
    By Kristjan on 16 January, 2008


    All these improvements are great, but could you tell
    the visitors if all this works with new google tracking code at the start with red color or something. Saves a lot of buzz.

    Does your image search work if I change search engine list according to ga.js


  10. homicidal
    By homicidal on 19 December, 2007

    hi Joost,
    An excellent script, I read it this morning and set it up today, and already am I seeing the hits coming from image searches enter in the ‘search engines’ section rather than the ‘referring sites’ section, which makes everything a lot more clearer (ie bounce rates, exit rates are generally higher for image searches). I run a small NSFW-ish blog :P with a lot of celebrity images so I attract a lot of image search hits.
    Amazing actually that Google sofar hasn’t put this functionality standard in Analytics, they should take your script and give you credit for it!

    Thanks again, a new big fan of your blog! (counts as a conversion! :)

  11. Mitico
    By Mitico on 8 December, 2007

    I have included your scripts but Analytics continues showing (referal). Any idea?

  12. George
    By George on 18 October, 2007

    Thanks for that info!

    Now I wonder what I did to cause all my images to drop out of the Google Image search results.

    Blog images are fine (blog is in a subdirectory of my main site), but all the images from my main portfolio site are no longer in GIS when they used to be on the first page for the same keyword searches.

    The hunt goes on I guess. Thanks again!

  13. Joost de Valk
    By Joost de Valk on 18 October, 2007

    @George: “I read somewhere that when 301 redirecting you should leave the old content up for a few months, which I didn’t do – I thought that was what the redirect was there for).”

    You were right and what you read was NOT true.

  14. George
    By George on 18 October, 2007

    One quick tip for us part-time coders out there: make sure you change, in the code above, the “” to your own domain! I noticed my stats were dropping off and I finally went back and looked at the code – I realized I never updated the text to my own domain!

    I made some other mistakes that hurt my Google Image search in general (not sure exactly why, but I read somewhere that when 301 redirecting you should leave the old content up for a few months, which I didn’t do – I thought that was what the redirect was there for).

    I am hoping that renaming the image files and pages was what hurt my image search results, and that they will eventually be reindexed. I wish I would have found your mod_rewrite for underscores to dashes first! I did need to rename some files anyways.

    I guess when you learn this way you never make those mistakes twice!

  15. Joost de Valk
    By Joost de Valk on 12 October, 2007

    It’s once a day yeah.

  16. glamcars
    By glamcars on 12 October, 2007

    I`ve just installed this plugin and waiting results. I have one question – is google-analytics system updates every domain once per day? I`ll be very happy if it`ll make this even twice per day… Thanks a lot for plugin

  17. Joost de Valk
    By Joost de Valk on 9 September, 2007

    @Rhoda: it will not affect any of the other engine image searches.

  18. Rhoda Schueller
    By Rhoda Schueller on 9 September, 2007

    I want to thank you for your method to track image searches. I added the original files with added images engines like Yahoo and Ask. A few others too though I have not seen much from the others. Yahoo has sent traffic for images. I would like to try your new file out that is specifically for Google image searches. However, will it cause problems with the Yahoo image searches? Or will it just process the Google image searches and not affect any of the other engine image searches?


  19. Joost de Valk
    By Joost de Valk on 9 September, 2007

    Yeah Dennis, it does :) In fact, adding blogsearch is probably a great idea.

  20. DennisG
    By DennisG on 9 September, 2007

    Thank you very much.
    Through Mybloglog I already know that image search is a big part of my search engine traffic. Now, getting it consolidated in Analytics makes a lot of sense.

    Does this mean that you can tweak the track-image.js for other search engines from Google.
    Blogsearch.Google comes to mind here.


  21. John Stevens
    By John Stevens on 8 September, 2007

    Joost, thanks to share this with us. What is more important to you? To know what really comes from the plain search (so filter out the image search) or to find out how many users and via what keyword visitors ends on your website?

    Personally I don’t give much attention to Google Image search… should I do that ? Maybe your tool can convince me.

  22. Avinash Kaushik
    By Avinash Kaushik on 8 September, 2007


    This is a very elegant solution!

    Thanks so much for putting this out there for the good of all us analytics practitioners! :)


  23. webdesign
    By webdesign on 7 September, 2007

    ok good to hear that !
    i dont use wordpress for myself but i come along it way to often to let such a plugin uninstalled :)

  24. Joost de Valk
    By Joost de Valk on 7 September, 2007

    The WordPress plugin I’m building which supports this is nearing completion to, testing that with a few people now.

  25. webdesign
    By webdesign on 7 September, 2007

    This is indead a much better approach to the script !
    thx for the tip cause this saves a lot of editing work when google updates !
    keep up the good work and kick those Ba**ER*S of Dmoz for me :)

Check out our must read articles about Analytics