How to A/B test discounts on checkout upsells with Script Editor
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 script below. This will apply a 50% discount on both the A and B version of the upsell.
Parameters we can change:
Offer ID: 'e766cbff-060d-4ed7-9797-ccb9d2bdcf1a'
Discount: '0.5'
Discount message: 'Flash Sale'
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%.
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.
- 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 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
Parameters we can change:
Offer ID: 'e766cbff-060d-4ed7-9797-ccb9d2bdcf1a'
Discount: '0.5'
Discount message: 'Flash Sale'
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.
Updated on: 23/07/2024
Thank you!