I'm currently experimenting with Google Analytics and Content Experiments for A/B testing on my website, but I'm encountering some challenges in making it seamless.
To utilize the Google API properly, a few steps need to be taken. Firstly, I need to include a script tag to load the cxApi from Google, specifying an experiment id. Once loaded, the Google documentation recommends adding a listener on the window for the 'load' event. At this point, I should request Google for a variation of the content I want to display and provide a callback function. After selecting a variation, JavaScript can be used to show/hide the relevant content.
However, the main issue I'm facing is content flash during page load; if I'm testing a H2 element, for instance, I don't want the original one to appear first and then quickly switch. Does anyone have any suggestions?
The workaround I've thought of so far involves adding a style tag to hide the content (e.g., setting text color to transparent so the space remains consistent on the screen without causing reflow). Still, I'm looking for a more effective solution and curious if anyone knows how optimizely tackles this issue?
Thanks