How to A/B test discounts on checkout upsells with Script Editor
Overview
A/B testing allows you to compare different discount strategies for your checkout upsell offers to determine which performs better. By creating multiple versions of an upsell offer and applying distinct discounts using Shopify's Script Editor, you can analyze customer responses and optimize your sales approach.
To A/B test which discount converts best, we need a couple of things: an A/B test offer and a Shopify Script with different discount per version.
Step-by-Step Guide
- Log in to Shopify Admin
- Access your Shopify Admin panel using your credentials.
- Open the UpsellPlus App
- Navigate to Apps in your Shopify Admin.
- Select UpsellPlus from your installed apps.
- Create an A/B Test Offer
- Click on Create Offer and select Checkout as the offer type.
- Configure the initial upsell offer (Version A) by selecting the product and customizing the offer details.
- After setting up Version A, click on Add an A/B Version to duplicate the offer as Version B.
- Modify Version B as desired to test different variables, such as product selection, discount rates, or messaging.
- Install and Open the Script Editor App
- If not already installed, download the Script Editor app from the Shopify App Store.
- Open the Script Editor from your list of installed apps.
- Create a New Script
- Click on Create Script.
- Choose the Line Item script type.
- Insert the A/B Test Discount Script
- Copy and paste the following script into the editor:
After you've created an A and B version of your offer in the app, go to your Script Editor. There, add in the script below. This will apply a 50% discount on both the A and B version of the upsell.
Input.cart.line_items.each do |line_item|
if line_item.properties.has_key?("__upsell_id") and line_item.properties["__upsell_id"].include? "e766cbff-060d-4ed7-9797-ccb9d2bdcf1a"
line_item.change_line_price(line_item.line_price * 0.5, message: "Flash Sale")
end
end
Output.cart = Input.cart
To discount the A and B version with a different discount, we need to target the specific version. The script below will discount version A and discount version B with different discounts, 50% and 25%.
Input.cart.line_items.each do |line_item|
if line_item.properties.has_key?("__upsell_id")
upsell_id = line_item.properties["__upsell_id"]
if upsell_id == "7d705281-6409-49e9-90ee-1d40ec945a80"
line_item.change_line_price(line_item.line_price * 0.50, message: "Discount")
elsif upsell_id == "7d705281-6409-49e9-90ee-1d40ec945a80_versionB"
line_item.change_line_price(line_item.line_price * 0.75, message: "Sale")
end
end
end
Output.cart = Input.cart
We add the suffix '_versionB' to the same offer ID we used to discount version A to target version B with a 25% discount in this example.
Parameters to Customize:
- Offer ID A: Replace
7d705281-6409-49e9-90ee-1d40ec945a80
with the Offer ID for Version A of your upsell. - Offer ID B: Replace
7d705281-6409-49e9-90ee-1d40ec945a80_versionB
with the Offer ID for Version B of your upsell. - Discount Rates: Adjust
0.50
and0.75
to reflect the desired discount percentages for each version. For example,0.50
represents a 50% discount, while0.75
represents a 25% discount. - Discount Messages: Customize
"50% Off - Version A"
and"25% Off - Version B"
to the messages you want customers to see for each version.
- Locate the Offer IDs in UpsellPlus
- In the app, navigate to each upsell offer (Version A and Version B).
- The Offer ID is displayed at the top of the offer details page.
- Copy the respective Offer IDs and replace both Offer ID A and Offer ID B in the script accordingly.
- Save and Publish the Script
- Click **Save **to apply the script.
Key Considerations
- Testing: Allow the A/B test to run for a sufficient period to gather meaningful data. Ensure that each version receives an adequate number of views and interactions to determine statistical significance.
- Analysis: Monitor the performance of each version through UpsellPlus analytics to identify which discount strategy yields better results.
- Iteration: Based on the insights gained, refine your upsell offers and consider testing additional variables to further optimize performance.
Related Articles
Updated on: 14/02/2025
Thank you!