Google Product Forums

Re: Tracking keywords from google image search

Sjixxxy Mar 30, 2010 6:32 AM
Posted in group: Google Analytics

Categories: Discuss issues related to your accounts, reports and data :

@blizzard1488 Here is how I rewrote Joost's code for the asynchronous code. I added it to my site yesterday and I'm seeing images.google.com appear as search results now.

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
 
        var ref = document.referrer;
        if (ref.search(/images.google/) != -1 && ref.search(/prev/) != -1) {
                var regex = new RegExp("images.google.([^\/]+).*&prev=([^&]+)");
                var match = regex.exec(ref);
                _gaq.push(['_clearOrganic']);
                _gaq.push(['_addOrganic','images.google.'+match[1],'q']);
                _gaq.push(['_setReferrerOverride', 'http://images.google.'+match[1]+unescape(match[2])]);
        }  
 
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>