Tracking A/B tests in Mixpanel using url parameters (Rails Application)

Update January 2015: I wrote a 3,000 word introduction to a/b testing, and I’d love it if you checked it out!

So you have a Rails application, and you’re trying to setup A/B tests. You probably also aren’t in the mood to pay for Optimizely  because it makes more sense to roll your own. I understand, yet you also want to be able to track the results of these A/B tests in Mixpanel (specifically in a funnel.)

You’re reading the right article – I’m going to dive in and show you a super-simple way to set this up.

First, if you’re using utm parameters (utm_campaign, utm_content, etc), you need to stop. These are great when you are linking from an external site, but if you use these internally, you’re messing with important data about where your customers are coming from. I did this for a while, and it’s BAD. Please learn from my mistakes, it will save you in the long run.

Setup the Variations in your View

First, let’s say you’re going to test out two different calls to action on a specific page, with both variations sending visitors to the same landing page. Let’s setup the links in your view below:

Note: I’m setting two parameters here, one is to track the overall performance of the campaign, while the other parameter is for the specific variation.

Setup Instance Variables in your Controller

In your controller, setup instance variables that pick up the parameters in the url, it’s quite simple.

def landing_page @campaign = params['campaign'] @variation = params['variation'] end

Setup Mixpanel Tracking Code

The last step of this process is to interpolate the instance variables into properties on a specific event. In this case, we have an event setup on the landing page to track views.

mixpanel.track('viewed_landing_page', { 'campaign': "#{@campaign}", 'variation': "#{@variation} });

I’ve found this approach works quite well. Mixpanel also has the ability to fire an event based on a click, but if you’re A/B testing, you need to see the different results of the variation as they work their way through specific funnel steps.

In a future post, I’ve dive into more A/B testing practices, I hope you enjoy this post.

Luke Thomas

About Luke Thomas

I'm a Mainer in technology who likes growing internet companies and sharing stories about what I learn along the way. Also reading, soccer, and experimenting.

Comments