ABjection.js: simple javascript library to A/B test with Google Universal Analytics

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.


Basically, it comes down to this:

A/B testing with Google Universal Analytics

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!