Created
January 21, 2013 08:44
-
-
Save shoyan/4584652 to your computer and use it in GitHub Desktop.
Anayticsで検索順位をロギングするjs。
co.jpも対応した。
参考
http://cutroni.com/blog/2013/01/14/a-new-method-to-track-keyword-ranking-using-google-analytics/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
if (document.referrer.match(/google\.(com|co\.jp)/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