Last active
February 5, 2016 09:34
-
-
Save RyoSugimoto/f480db22b5886cd0a7fc to your computer and use it in GitHub Desktop.
JSによるリダイレクトを行なう際に、リダイレクト先のHMTLに実装するスクリプト。GAのcreateと
sendの間に記述することで、GAに正しい参照元情報を送ることができる。
http://qiita.com/1987yama3/items/5ff58b6195fe6c3f268b
This file contains hidden or 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
ga('create', 'UA-0123456-1'); | |
// ここから | |
if (location.search.indexOf('referrer=') >= 0) { | |
var params = location.search.replace('?', '').split('&'); | |
for (var i = 0; i < params.length; i++) { | |
var kv = params[i].split('='); | |
if (kv.length == 2 && kv[0] == 'referrer') { | |
ga('set', 'referrer', decodeURIComponent(kv[1])); | |
break; | |
} | |
} | |
} | |
// ここまで | |
ga('send', 'pageview'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment