Skip to content

Instantly share code, notes, and snippets.

@jice-lavocat
Last active October 24, 2016 03:03
Show Gist options
  • Save jice-lavocat/67359a5d90bf7737263e8b504c98e58e to your computer and use it in GitHub Desktop.
Save jice-lavocat/67359a5d90bf7737263e8b504c98e58e to your computer and use it in GitHub Desktop.
Change a page content/layout with GA Experiments
<!-- Load the JQuery library -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
// Needs to be loaded after jquery
var chosenVariation = cxApi.chooseVariation();
console.log("Experiments is ON. Visitor will see variant : ", chosenVariation);
// Define JavaScript for each page variation of this experiment.
var pageVariations = [
function() { // Original: We don't change the page at all
console.log("variation 0 is used");
},
function() { // Variation 1 we show the CTA signup above the testimonials:
console.log("variation 1 is used");
$("#testimonials").insertAfter("#signup");
},
];
// Wait for the DOM to load, then execute the view for the chosen variation.
$(document).ready(
pageVariations[chosenVariation]
);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment