Skip to content

Instantly share code, notes, and snippets.

@hermpheus
Created February 25, 2013 19:00
Show Gist options
  • Save hermpheus/5032295 to your computer and use it in GitHub Desktop.
Save hermpheus/5032295 to your computer and use it in GitHub Desktop.
GA: Rank Tracking Based on User visits
<script type="text/javascript">
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, true]);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment