For the complete documentation index, see llms.txt. This page is also available as Markdown.

Add Your Own Code to Any Test

Read which group a visitor is in for a price, template, theme or URL redirect test, and make your own change for that group.

Make an extra change for visitors in one group of a price, template, theme or URL redirect test. Shoplift measures the test's change and yours together, as one variant. This guide is for the developer who adds the code to the theme.

You need: a live or draft test · access to your theme code · about 30 minutes

Not a developer? To decide whether a combo test fits your idea, read Combo tests.

Before you start

Steps

1. Get the variant's hypothesis ID

Each group in a test has an ID called a hypothesis ID. For a template, theme or URL redirect test, copy it in Shoplift: hover over the info icon next to the variant's name on the test's draft, or in the test report once it's live. For a price test before launch, look it up with the Get test request.

export SHOPLIFT_API_KEY="YOUR_API_KEY"
curl https://app.shoplift.ai/api/public/v1/tests/YOUR_TEST_ID \
  -H "Authorization: Bearer $SHOPLIFT_API_KEY"
  • YOUR_API_KEY: your Shoplift API key.

  • YOUR_TEST_ID: the test's ID from the List tests response.

Expected result: a JSON test object. variant.id is the variant's hypothesis ID, and control.id is the original's.

2. Add the check to your theme

Add this script to layout/theme.liquid in your live theme, just before the closing </body> tag, so it runs on every storefront page that uses your main layout (all of them, on most themes). For a theme test, add it to the variant theme as well, so it runs for both groups. It waits for Shoplift, then checks whether the visitor is in the variant.

  • YOUR_VARIANT_HYPOTHESIS_ID: the variant.id from step 1. It works the same way for every test type.

Expected result: for visitors in the variant, the page's body gets the combo-variant class. Style your change with that class, or replace the classList line with your own code. Visitors in the original, visitors outside the test, and visitors whose page can't load Shoplift keep your normal store. If Shoplift loads after the 15-second wait, the visitor sees your normal store on that page, and the change appears from the next page.

The check uses getVisitorData() and only reads the visitor's assignment. Match on hypothesisId, not testId.

3. Check again when it matters

A visitor joins a test at a set moment, and your check only finds them after that:

Test type
When a visitor joins

Price test

When a tested price first scrolls into view

Theme test

On their first page view

Template test

When they first reach the tested type of page

URL redirect test

When they first land on the tested URL

For a price test, a visitor joins when a tested price first scrolls into view, which can be after your check runs. On that page, call applyComboChange() again at the moment your change matters, such as in your cart drawer's open handler. For template, theme and URL redirect tests, the visitor's group is already set when Shoplift is ready, so the check in step 2 finds it.

4. Check both groups

Open your store in a private browser window, not Shoplift's preview: the preview shows the test's own change only. For a theme test, first confirm the script is in the variant theme too. Reach the point where visitors join the test, then run this in your browser's console:

Expected result: a list of the hypothesis IDs for the groups you're in. If the variant's ID is there, your change should show. If not, close all private windows and open a new one to try for the other group. In most browsers, private windows share one session until you close them all.

Visits you make this way are counted in the test's results, like any visitor's.

Verify it worked

In a private window where the console lists the variant's ID, your change shows on every page where you added the script. In a window where it doesn't, your normal store shows.

Troubleshooting

The change never shows: the visitor hasn't joined the test yet, or the ID doesn't match. Run the console check from step 4 on the same page, and compare the IDs with variant.id.

The change shows on later pages but not the first one: the visitor joined the test after your check ran. Call applyComboChange() again at the moment the change matters, as in step 3.

The change never shows for the variant of a theme test: the script is only in your live theme. Add it to the variant theme as well.

The change still shows while the test is paused: your check can still find the visitor's group while the test is paused. Remove or turn off your change while the test is paused.

window.shoplift is undefined in the console: Shoplift hasn't loaded on the page. See Common issues.

Next steps

Related articles


Still need help? Contact support to chat with the Shoplift team in the app, or email help@shoplift.ai. Include your store URL and the name of your test.

Was this helpful?