Google Analytics and Google Image search: revisited

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

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.

Tags:


Yoast.com 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!

32 Responses

  1. webdesignBy 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 :)

  2. Joost de ValkBy 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.

  3. webdesignBy 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 :)

  4. Avinash KaushikBy Avinash Kaushik on 8 September, 2007

    Joost,

    This is a very elegant solution!

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

    -Avinash.

  5. John StevensBy 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.

  6. DennisGBy DennisG on 9 September, 2007

    Joost,
    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.

    Thanks
    Dennis

  7. Joost de ValkBy Joost de Valk on 9 September, 2007

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

  8. Rhoda SchuellerBy Rhoda Schueller on 9 September, 2007

    Hi,
    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?

    Thanks,
    Rhoda

  9. Joost de ValkBy Joost de Valk on 9 September, 2007

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

  10. glamcarsBy 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

  11. Joost de ValkBy Joost de Valk on 12 October, 2007

    It’s once a day yeah.

  12. GeorgeBy George on 18 October, 2007

    One quick tip for us part-time coders out there: make sure you change, in the code above, the “www.example.com” 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 example.com 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!

  13. Joost de ValkBy 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. GeorgeBy 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!

  15. MiticoBy Mitico on 8 December, 2007

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

  16. homicidalBy 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! :)

  17. KristjanBy Kristjan on 16 January, 2008

    Hi,

    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
    pageTracker._addOrganic(“search_engine_name”,”query”);

    Cheers
    Kristjan

  18. RhodaBy Rhoda on 17 January, 2008

    Hi,
    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 images.google.com but only as a referral. Clicking on the listing does not lead me to the keywords as it does with the organic listing for images.google.com 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.

    Rhoda

  19. webdesignBy 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.

  20. EoghanBy 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 http://javascriptcompressor.com/ 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?

  21. Joost de ValkBy 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…

  22. EoghanBy 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…

  23. Joost de ValkBy 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?

  24. RobinBy 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 :)

  25. Ion de la PaclisaBy 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…

Trackbacks

  1. [...] So I was doing some research on Google Caffiene changes and I noticed that keywords have become increasing more important to where you rank on organic search. This isn’t in itself a bad thing but some of your traffic is coming from Google Images you have no way of knowing how your visitors got to your site. Well after some light reading, I came across a blog article that addressed this very problem over at Yoast.com. [...]