Skip to content

Instantly share code, notes, and snippets.

@RyoSugimoto
Last active February 5, 2016 09:34
Show Gist options
  • Save RyoSugimoto/f480db22b5886cd0a7fc to your computer and use it in GitHub Desktop.
Save RyoSugimoto/f480db22b5886cd0a7fc to your computer and use it in GitHub Desktop.
JSによるリダイレクトを行なう際に、リダイレクト先のHMTLに実装するスクリプト。GAのcreateと sendの間に記述することで、GAに正しい参照元情報を送ることができる。 http://qiita.com/1987yama3/items/5ff58b6195fe6c3f268b
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