My Authors
Read all threads
A simple A/B testing setup for developers, a thread:
Lately, I’ve been experimenting and learning about AB testing!

In this post, I’ll walk through how simple it is to do AB testing with Google Analytics and a bit of custom code. I'll show you an example of a successful AB test and some things I learned.

Inspired by @levelsio
I don’t use Google Optimize, Mixpanel, etc as I found them to be way too clunky and hard to figure out.
The original feature

The AB test here has to do with email collection.

Image 1: The original feature, or the "A" in the AB test:

Image 2: The new thing we want to try. Instead of just asking to join the newsletter, I wanted to test out a "content upgrade".
Getting set up with Google Analytics:

The key here is to use Google Analytics' custom dimensions.

Go to Admin -> Custom Dimensions and create a dimension for every AB test you want to try:
Server-side code:

For every request made to our server, run a simple method putting the user into the random bucket.

In this case, there are only two buckets: 'control' (A) and 'upsell_widget' (B). It picks a random bucket and assign a cookie (as long as it's not already there)
Client-side code:

Now, on the client-side, you need to send this data over to Google Analytics for every pageview or event.

Keep in mind, you must send the mapping as well as the values. Took me forever to figure this out.

For me, it looks like something like this this:
The last thing is to change your code based on the test that each user is in.

This is as simple as looking at what cookie they have:

(pseudocode)
Now, set an event in your calendar to review the results a few weeks later.
The results:

In Google Analytics, go to Acquisition -> All Traffic -> Channels.

Right above the grid, look for the dropdown of Secondary Dimension, and search for your AB test:
For this AB test, I'll use GA "Goals" because I'm tracking email collection conversion rate, but you might be testing something else such as time on site, pageviews, etc.

Since the AB test is a custom dimension inside GA, you can do pretty much anything!
I added all of these up inside Google Sheets and here are the results:
Bucket B in the AB test wins!

Then I plugged this into @neilpatel's AB test calculator, it shows we are statistically significant.
And that’s it!

Now that it’s confirmed to be statistically significant, I’ll remove the old code and think of the next AB test to run!

Thanks for reading!

Here’s also 3-minute video that walks through this as well.

loom.com/share/9ff05905…
Missing some Tweet in this thread? You can try to force a refresh.

Keep Current with Pat Walls

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!