I'm trying to find the best approach to perform some A/B tests on a site currently being built. The site is hosted on WPEngine and uses Wordpress. They use full page caching, and that should be enabled anyway. A/B tests require different HTML for each variant. As the element that changes is the site's main menu, it would be bad to dynamically load it by AJAX with another HTTP request.
I can't imagine any other approach than a completely client-side one. My idea is to include both variants in the page and display only one.
<script src="set-variant.js"></script> <!-- sets variant variable -->
<div id="variants">
<!-- <div id="variant1"></div> -->
<!-- <div id="variant2"></div> -->
</div>
<script>
if(variant==1){
document.write(retrieveVariant1FromComment());
} else {
document.write(retrieveVariant2FromComment());
}
</script>
It works, but it looks odd (I would rather avoid document.write...) and also I'm not sure about SEO.
Does anyone know a better way to do this when pages are cached? Any recommendations?