On your server
Any server that talks to the Storefront API can run the SDK. Assigning on the server means the first HTML already shows the right test group.Step 1: Install the package
Step 2: Create the client for each request
Pass the incoming request tocreateABConvert, then add getSetCookieHeaders() to your response. If your framework gives you no Request object, pass its parts.
Server
Step 3: Pass the state to the browser
Hand the page’s state to the browser so it tracks for the visitor and renders the same test groups the server did. With React, passgetPageState() to the provider:
Browser (provider)
hydrateABConvert and call start() once the page has loaded:
Browser
Step 4: Write the cart attributes
Checkout applies a test only when the cart carries the visitor’s test groups. PassgetCartLineAttributes() with each line you add, and write getCartAttributes() with the cart’s own attributes each time you create or update the cart. See Connect the cart.
Step 5: Track page views and add to cart
Nothing on your stack publishes storefront events, so calltrack for them yourself, in the browser:
Browser
Caching
A page that shows one test group’s version must not be served to everyone from a shared cache. Cache tested pages per test group, or leave them uncached.isPageTested() on the client made from the request returns true when a test can change the page, so you can mark that response private.
Browser only
Use this when you cannot run code on the server. Pass the client options to the provider instead of a state:Browser (provider)
isReady is true. We trade a short delay for a simpler setup.
Browser (component)
Browser
track yourself.
Without React
createABConvert and hydrateABConvert do not need React. Use the client directly in Vue, Svelte, or plain JavaScript. The methods are the same as in useABConvert(), and track works the same. On a server-rendered page, hydrateABConvert is the browser side, as in Step 3; it also takes the provider’s onAssignment and expectCustomerPrivacy options. See the reference.
Next steps
- Render the test price everywhere a price appears.
- Redirect on your server for URL redirect tests.
- Do the rest of After setup.