GA Snippet for Keyword Tracking

From the original Place this immediately after your GA Code. For sites using a TLD other than a .com just remove .com

<script>
if (document.referrer.match(/google\.com/gi) && document.referrer.match(/cd/gi)) {
  var myString = document.referrer;
  var r        = myString.match(/cd=(.*?)&/);
  var rank     = parseInt(r[1]);
  var kw       = myString.match(/q=(.*?)&/);

  if (kw[1].length > 0) {
    var keyWord  = decodeURI(kw[1]);
  } else {
    keyWord = "(not provided)";
  }

  var p        = document.location.pathname;
  _gaq.push(['_trackEvent', 'RankTracker', keyWord, p, rank]);
}

if (document.referrer.match(/google\.([a-zA-Z]{2,5})/gi)) {
  var myString = document.referrer;
  var r        = myString.match(/cd=(.*?)&/);
  var rank     = parseInt(r[1]);
  var kw       = myString.match(/q=(.*?)&/);

  if (kw[1].length > 0) {
    var keyWord  = decodeURI(kw[1]);
  } else {
    keyWord = "(not provided)";
  }

  var p        = document.location.pathname;
  _gaq.push(['_trackEvent', 'ReferralCheck', keyWord, p, rank]);
}
</script>

Give it a few days and navigate to your Google Analytics dashboard > Content > Events > Top Events

The .AVG Value is your average value for that keyword/phrase.

Why this way?

To take away the client focus on a singular vanity search term or must have terms and show the value and increase over time of those all important long tail queries.

dean-cruddace

Comments are closed.