PCサイトでスマホOSで来た場合にリダイレクトさせたい場合は
pc_script.js
if(/iphone|ipad|ipod|android/.test(navigator.userAgent.toLowerCase())){
location.replace("/sp/");
}
という感じで書いていると、URLの?以降やハッシュタグがついていた場合消えてしまう。
pc_script.js
if(/iphone|ipad|ipod|android/.test(navigator.userAgent.toLowerCase())){
location.replace("/sp/" + window.location.search + window.location.hash);
}
として、パラメータが消えないようにしましょう。
これをちゃんとやらないとGoogle Analyticsでちゃんとデータが取れなかったりするのでダメです。
また、同じ理由でGoogle Analyticsのscriptが読まれる前に上記リダイレクトのscriptを記載しましょう。
南無南無🙏