Skip to content

Instantly share code, notes, and snippets.

@nabettu
Created October 23, 2015 09:25
Show Gist options
  • Save nabettu/02c1f68e515752f746cd to your computer and use it in GitHub Desktop.
Save nabettu/02c1f68e515752f746cd to your computer and use it in GitHub Desktop.
LINEからの流入をGAに食わせる(?ref=lineが入っていた場合に動作)
<!--LINE ref検知-->
<script>
//URLの文字列を取得
function getQueryString(){
var result = {};
if( 1 < window.location.search.length ){
var query = window.location.search.substring( 1 );
var parameters = query.split( '&' );
for( var i = 0; i < parameters.length; i++ ){
var element = parameters[ i ].split( '=' );
var paramName = decodeURIComponent( element[ 0 ] );
var paramValue = decodeURIComponent( element[ 1 ] );
result[ paramName ] = paramValue;
}
}
return result;
}
var lineref = "http://line.me/";
if(getQueryString().ref == "line"){
delete window.document.referrer;
window.document.referrer = lineref;
window.document.__defineGetter__('referrer', function () {
return lineref;
});
window.history.pushState(null,null,document.location.origin + document.location.pathname);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment