How to do A/B test with Google Analytics Part 2

How to do A/B test with Google Analytics Part 2

Today we're going to learn:

How to do A/B test with Google Analytics.

In Part 1 we went over adding all of the code that was required to Shopify to create two different templates. So let's just quickly go and review what we've got set up.

If we go to the first product and append ?view=OptionA to the end of the URL we can see the price is added to the buy button.

Merchant is displaying the Shopify product variant that has the price coded into the buy button.

If we add ?view=OptionB , we now have a regular  button without the price. Now that the options are set up, we can add it into Google Analytics to split the traffic that comes to our website 50/50 between the two options and begin to measure which is more effective.

Merchant is displaying the Shopify product variant that does not have the price coded into the buy button.

In Google Analytics, we’ll set up a couple of things so that we can track the events. First, we’ll go to admin in the bottom left corner and we're going to select Goals under the View column on the right side.

Merchant is setting up a new goal in Google Analytics

You’ll need a special JavaScript trigger code for Google Analytics to know when the button has been pressed.

In the Product-OptionA.liquid, you’ll need to search from the AddToCart button code.

Then you’ll need to include “ onClick=”_gaq.push([‘_trackEvent’, ‘Click’, ‘Add to Cart’, ‘Yes’});’

Shopify merchant is adding a string of code to their theme to  use with Google Analytics                   

Back in Google Analytics, let's go and create a new goal. Go to goals, + NEW GOAL, it’ll be the add to cart template.

Merchant is setting up an add to cart goal in Google Analytics

Click continue. The goal description is going to be “Add to cart”, and it's going to be goal ID number two ( I've already got one set up). Afterward, I'll click continue and begin to fill out the category values.

Merchant is adding the variables they used in the Shopify code and attaching them to the goal details in Google analytics.

Reviewing our Shopify code, the first value we have is Click, so the first category in Google Analytics is also Click. The action is Add to Cart because that's what we called the second variable in our Shopify code. We’ll leave the Value blank, and set “Use the Event value as the Goal Value for the conversion” to YES.

Then we’ll click Save, and our goal is now set up.
                   

Note: There is no way to delete a goal. You can only turn goals on or off.

Now we need to set up our experiment. Go to the home page and select behaviors, and then experiments, and click ‘Create experiment’.

Merchant is setting up a behaviour experiment within the Google Analytics dashboardMerchant is setting up a behaviour experiment within the Google Analytics dashboardMerchant is setting up a behaviour experiment within the Google Analytics dashboardMerchant creating a goal set to test the behaviour experiment within the Google Analytics dashboard

Our experiment is to test displaying the price versus in the button vs no price in the button.


Name for this experiment

Price Vs No Price CTA

Objective for this experiment

Goal Set 1 > Add to cart

Percentage of traffic to experiment
100%

Email notification for important changes
Off

Click Next

              

Now we need to configure the experiment. Open the first product to test and add ?view=OptionA to end of the URL. Copy the URL and paste it in Google Analytics Original Page > Webpage to experiment.  Next add ?view=OptionB to the end of the URL. Copy the entire URL and paste it into Variant 1 > Web page to experiment.

Note: This experiment will not work if your store is password protected.

Merchant is adding the two Shopify product variants to Google Analytics for testing

Click Next. Now the experiment is configured and we have to manually insert the code. Click “Manually insert the code” and copy the script code to your clipboard.
Google Analytics has generated code for the merchant to copy and paste into Shopify

In Shopify, goto Themes > Online Store > Actions > Edit Code > Layout > theme.liquid and paste the code just beneath the <head> tag. Click Save.

The Google Analytics code is pasted into the users Shopify theme.liquid file beneath the <head> tag

Google Analytics will check to see that everything is configured correctly. Under “Review and start you will see two checkmarks beside Original and Variant 1 if everything is configured correctly. Now click Start experiment

Google analytics is verifying it sees the code and that it is working on the merchants Shopify store                   

And that basically wraps up everything you need to do to set up an A/B test inside Google.

Back to blog