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
18 Responses to “Google Analytics: How to Track Image Referrals”
Leave a Reply
Recent Comments
- ppc_tools (PPC Tools) on How to Optimize Your Site for Image Search
- Eric on SEO Beginner’s Checklist: 10 Tactics to Rank Higher
- Eric on Prioritise Your Link Building to Increase Traffic Fast
- wordpress customization on Blog Your Way to Success With Frequency and Long Tail Keywords
- wordpress customization on Prioritise Your Link Building to Increase Traffic Fast






RT @mercylivi: Google Analytics: How to Track Image Referrals http://dailyseotip.com/google-analytics-how-to-track-image-referrals/458/
[Reply]
RT: @mercylivi: Google Analytics: How to Track Image Referrals http://dailyseotip.com/google-analytics-how-to-track-image-referrals/458/
[Reply]
RT @mercylivi: Google Analytics: How to Track Image Referrals http://dailyseotip.com/google-analytics-how-to-track-image-referrals/458/
[Reply]
Google Analytics: How to Track Image Referrals http://dailyseotip.com/google-analytics-how-to-track-image-referrals/458/
[Reply]
good code.. thanks
[Reply]
it’s means the images also help to improve the ranking ?
[Reply]
That, or get Mint Analytics - since it already does this as a core function. I’m glad someone figured it out for GOOG users.
[Reply]
Ya its good news, Now we can optimize a page with images too..
[Reply]
How will the result look like in Google Analytics?
Can you post a screen shot?
[Reply]
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.
[Reply]
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.
[Reply]
@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.
[Reply]
It would have been even nicer if you had highlighted the difference between original code and modified code. I know i’m lazy
[Reply]
Thanks Gaurav for this image!
[Reply]
Thanks. It’s very useful for my image gallery website…
[Reply]
Great and useful post, thanks for sharing.
[Reply]
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
* http://www.google.com/images or http://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.
[Reply]
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
[Reply]