I needed a simple way to write new A/B tests on a WordPress website and I couldn’t find one that was working specifically for Google Universal Analytics so I wrote one.
https://github.com/AymericG/ABjection.js
Basically, it comes down to this:
The code will look for any DOM element with the class .ab-call-to-action and will either apply the default variant or the variant1 variant. The variant being applied is saved in a cookie and is set to the custom Google Universal Analytics dimension so that you can segment your traffic by that custom dimension (which I called Experiment in Google Universal Analytics).
Good luck with your testing!