Articles on: Discounts

How to A/B test discounts on checkout upsells

To A/B test which discount converts best, we need a couple of things:

- A/B test offer
- Shopify Script with different discount per version

After you've created an A and B version of your offer in the app, go to your Script Editor. There, add in the following script:

Input.cart.line_items.each do |line_item|
if line_item.properties.has_key?("__upsell_id") && 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


Parameters we can change:
Offer ID: 'e766cbff-060d-4ed7-9797-ccb9d2bdcf1a'
Discount: '0.5'
Discount message: 'Flash Sale'

This script will discount version A of upsell offer with offer ID e766cbff-060d-4ed7-9797-ccb9d2bdcf1a. To add a discount to version B, add the following script:

Input.cart.line_items.each do |line_item|
if line_item.properties.has_key?("__upsell_id") && line_item.properties["__upsell_id"].include? "e766cbff-060d-4ed7-9797-ccb9d2bdcf1a_versionB"
line_item.change_line_price(line_item.line_price * 0.7), message: "Flash Sale")
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 30% discount in this example.

Updated on: 16/12/2022

Was this article helpful?

Share your feedback

Cancel

Thank you!