Google Analytics: How to Track Image Referrals
*The guest tip was provided by Gaurav Sharma*
Google Analytics classifies traffic from Google Images as referral traffic. Websites which get a lot of traffic from Google Images are not able to analyze the keywords they get the traffic from. There is a way to force GA to treat Google Images as a search engine. Below is how GA code will look like:
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("YOUR-GA-ID");
var refferer = document.referrer;
if (refferer.search(/images.google/) != -1 && refferer.search(/prev/) != -1) {
var regex = new RegExp("images.google.([^\/]+).*&prev=([^&]+)");
var match = regex.exec(refferer);
pageTracker._setReferrerOverride("http://images.google." + match[1] + unescape(match[2]));
}
pageTracker._trackPageview();
} catch(err) {}
</script>
The script by Yoast
Ann Smarty
Latest posts by Ann Smarty (see all)
- What is the Current State with Directories? - April 29, 2013
- Get on Top of Google SERP by Optimizing for Local Search Results - February 9, 2013
- Get Tweets and Likes at Viral Content Buzz - October 12, 2012
29 Responses to “Google Analytics: How to Track Image Referrals”






RT @mercylivi: Google Analytics: How to Track Image Referrals http://dailyseotip.com/google-analytics-how-to-track-image-referrals/458/
RT: @mercylivi: Google Analytics: How to Track Image Referrals http://dailyseotip.com/google-analytics-how-to-track-image-referrals/458/
RT @mercylivi: Google Analytics: How to Track Image Referrals http://dailyseotip.com/google-analytics-how-to-track-image-referrals/458/
Google Analytics: How to Track Image Referrals http://dailyseotip.com/google-analytics-how-to-track-image-referrals/458/
good code.. thanks
it’s means the images also help to improve the ranking ?
That, or get Mint Analytics – since it already does this as a core function. I’m glad someone figured it out for GOOG users.
Ya its good news, Now we can optimize a page with images too..
How will the result look like in Google Analytics?
Can you post a screen shot?
While I appreciate that there is a way to track image searches in GA this code looks quite big and messy. I can’t really imagine putting this on every single page of mine.
I still use the one line GA inclusion where I can.
Hi Gaurav,
Thanks for providing GA code for Tracking image referral. but it could be more better if it provided with some snap shot of result after implementation of this code. I’ll appreciate your efforts.
@Tina & @Dipali – Here is the screenshot on how ‘images.google’ will show up as traffic sources http://farm3.static.flickr.com/2655/4195909530_88db996002.jpg
Once you click the ‘images.google’ you will see exactly same interface like you see on clicking Google, Yahoo or Bing.
This will skew your reports – drop in referral traffic and increase in search engine traffic. So, it might be better to implement at the end of a reporting cycle.
Also, it relies on Google Images’ referral URL. If Google changes that in future, like they are doing for web search, this code will need to be updated.
@Tad – Yes, the code will slow down things (haven’t benchmarked), but the stats outweigh performance if a website gets a lot of traffic from Google images.
@Kurt – Didn’t know Mint supported that, good to know.
It would have been even nicer if you had highlighted the difference between original code and modified code. I know i’m lazy
Thanks Gaurav for this image!
Thanks. It’s very useful for my image gallery website…
Great and useful post, thanks for sharing.
Comments…
* Google has changed the value of &prev=/ so that it no longer shows a domain name, thus you can removed from expression.
* RegEx missing a couple of escapes e.g. images\.google\.
* https: searches will not be matched
* www.google.com/images or www.google.com/imglanding will not be matched, but can be fixed with this filter e.g…
^https?://(images|www)\.google\.(.{2,8})/(images|imghp|imgres|imglanding).*(%3F|%26|%23)q(%3D)(.+)%26
AND
^https?://(images|www)\.google\.(.{2,8})/(images|imghp|imgres|imglanding).*([?&#])q=([^&]+)&
Updated script…
try {
var pageTracker = _gat._getTracker(“YOUR-GA-ID”);
var ref = document.referrer;
if (ref.search(/images.google/) != -1 {
var regex = new RegExp(“images\.google\.([^\/]+)/”); var match = regex.exec(ref);
pageTracker._setReferrerOverride(”http://images.google.” + match[1] );
}
pageTracker._trackPageview();
} catch(err) {}
Also here is an alternative version…
try {
regex = new RegExp(“^https?://images\.google\.([^/]+)/”);
var match = regex.exec(document.referrer); if (match != null)
{_gaq.push(['_addOrganic', 'images.google.'+match[1], ‘q’, true],['_setReferrerOverride','http://images.google.'+match[1] ]);}
} catch(err) {}
Thanks
Phil.
Has anyone tried Phil’s updated tracking code? This seems to be a hot topic on the GA blog but nobody seems to have a solid solution for this…Web Analytics TV sites this blog post so it must be legit…
Thanks in advance
wow, thanks for helping about google analytic bro
Interesting stuff, but I gotta agree that posting this on every page would be a bit much.
Gracias, excelente blog.
I know no one who wants to go can not. So no one “stay” I did not say. Put inmind what to go with me for a heart
thanks for this analytic code… I will try this one..
very useful post, Thanks a lot admin..
I should say the best DAILY SEO TIP.
Daha fazla bilgi cevap insanlar varsay?yoruz.
Onlar?n tavsiyelerini takip etmek thanks admin very good.
Thank you for sharing this info, it is really useful and interesting.
It´s great to learn how we can optimize a page with images too. Thank you indeed.
Don’t even know what to say on this topic. So much ideas are mixed in my head after reading it. Very problematic article I think