Search code examples
javascripthtmlcssgoogle-analytics-apiab-testing

How does optimizely do their A/B testing from a technical standpoint?


I'm trying to use Google Analytics and Contents Experiments to set up A/B testing on my website but I'm having trouble getting it to appear seamless.

There are a few things that need to happen in order to use the google API. First I add a script tag to load the cxApi from Google, specifying an experiment id. After it has loaded the google docs suggest putting a listener on window for the 'load' event after which point you should ask google for a variation of the content you wish to display and give it a callback. Once it has selected a variation you can then use javascript to show/hide the relevant content.

The issue though is that I get content flash on page load; if I am A/B testing a H2 for example, I don't want to see the original one first and then see it quickly replaced. Does anyone have any tips?

The best solution I've come up with so far would be adding a style tag to hide the relevant content (by setting the text color to transparent for example, so the content still takes up the same amount of space on the screen and doesn't cause reflow) but I'm after a better solution and would be interested if anyone might have any insight into how optimizely do this?

Cheers


Solution

  • The below article (from which screenshot is taken) explains how Optimizely interacts with the DOM: https://help.optimizely.com/hc/en-us/articles/200040335

    enter image description here