docs を使用して、リダイレクトなしで Google コンテンツ テストを作成しました。
基本的な実装には、次のコードを使用して実験のバージョンを選択する JavaScript スニペットが含まれます。
<!-- Load the Content Experiment JavaScript API client for the experiment -->
<script src="//www.google-analytics.com/cx/api.js?experiment=YOUR_EXPERIMENT_ID"></script>
<script>
// Ask Google Analytics which variation to show the user.
var chosenVariation = cxApi.chooseVariation();
</script>
<!-- Load the JQuery library -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
// Define JavaScript for each page variation of this experiment.
var pageVariations = [
function() {}, // Original: Do nothing. This will render the default HTML.
function() { // Variation 1: Banner Image
document.getElementById('banner').src = 'bay-bridge.jpg';
},
function() { // Variation 2: Sub-heading Text
document.getElementById('heading').innerHTML = 'Look, a Bridge!';
},
function() { // Variation 3: Button Text
document.getElementById('button').innerHTML = 'Learn more';
},
function() { // Variation 4: Button Color
document.getElementById('button').className = 'button button-blue';
}
];
// Wait for the DOM to load, then execute the view for the chosen variation.
$(document).ready(
// Execute the chosen view
pageVariations[chosenVariation]
);
</script>
ただし、シークレット ウィンドウを使用してページにアクセスすると、実験の最初のバリエーションしか表示されません。コンソールにチェックインするchosenVariation
と、常に0
. 実際、コンソールで呼び出すcxApi.chooseVariation();
と、常に が返されます0
。
cxApi.chooseVariation();
これは、Google が私のシークレット ブラウザ ウィンドウを認識しているためですか、それとも私の実装で何か壊れているのでしょうか?