How to Install Convert on a Shopify Hydrogen or Headless Storefront
Run experiments and track orders on Hydrogen, Oxygen and other Storefront API front ends with the Convert Shopify App and the headless snippet.
In Convert Experiences, a headless Shopify storefront (Hydrogen on Oxygen, or any front end built on Shopify’s Storefront API) needs one extra piece of code: the Convert headless snippet. The Convert Shopify App’s tracking embed only runs in Liquid themes. On a headless storefront, the snippet does that job: it passes each visitor’s experiences to the Shopify cart, so Convert can credit every order and its revenue to the variation the visitor saw.
This article shows what to set up and in which order. Your developer will also need the Headless & Custom Shopify Storefronts developer guide, which has the working code for each step.
What you can do after reading this article
- Check whether your storefront needs the headless snippet
- Get ready before you start
- Step 1: Add the Convert tracking script to your storefront
- Step 2: Add the headless snippet to Global Project Javascript
- Step 3: Fill in your configuration
- Step 4: Connect your cart
- Understand how purchases and revenue are tracked
- Check your installation
- Fix common problems
- FAQ
Check Whether Your Storefront Needs the Headless Snippet
Find your setup in the table.
| Your storefront | Headless snippet | What to do |
|---|---|---|
| A Liquid (Online Store 2.0) theme | Not needed | The app’s Convert Tracking Script app embed does this for you. Follow Integrate with Shopify through our Shopify Convert App. |
| Hydrogen, Oxygen, Next.js, Nuxt or another front end built on the Storefront API | Needed | Follow this article. In Step 4, use option A or B. |
| A storefront that sends shoppers to checkout on a different domain with cart permalinks | Needed | Follow this article. In Step 4, use option C. |
| A Shopify store with a Webflow front end | Not supported | Convert can’t reach a Shopify cart from this setup, so orders can’t be credited to experiences. |
📒Note: The headless snippet is for Convert Web projects connected through the Convert Shopify App. If you use a Fullstack project with the JavaScript SDK, follow the Shopify guide for Fullstack projects instead.
Get Ready Before You Start
Make sure you have:
- A developer who can change your storefront’s code. Every headless storefront is custom code, so the exact changes depend on how yours is built.
- The Convert Shopify App installed on your Shopify store and connected to your Convert Web project. See Integrate with Shopify through our Shopify Convert App, Steps 1 to 4.
- On the app’s Project Configuration tab: your project, a Currency Selection, a Checkout Completed Goal, and Setup Order Completed Webhook or not set to Enabled. Save the tab.
- If you sell subscriptions: a Subscription Goal and a Non-Subscription Goal on the app’s Other Goals tab (optional).
- For options A and B in Step 4: your store’s
myshopify.comdomain and a public Storefront API access token. - Your storefront’s domain listed under Active Websites on your Convert project’s Configuration tab. Without it, Convert can’t remember which goals a visitor already triggered, and goals can be counted twice.
💡Tip: You can skip Step 5 of the app setup (Enable the Tracking Script). It turns on the app embed in a Liquid theme, and a headless storefront doesn’t use one. Step 1 below replaces it.
Step 1: Add the Convert Tracking Script to Your Storefront
Add the Convert tracking script to every page of your storefront, the same way you would on any other site.
- In Convert, open your project, click the Configuration tab and open Environments & Tracking Code.
- In the row of the environment your live store uses, usually Production, open the ⋯ menu and click Install Code Snippet.
- On the Basic snippet tab, copy the code.
- Add it to the
<head>of your storefront’s root layout, so it loads on every route.

The two numbers before .js in the script’s address are your account ID and your project ID. You need both in Step 3. The tag looks like this:
<script type="text/javascript" src="//cdn-4.convertexperiments.com/v1/js/ACCOUNT_ID-PROJECT_ID.js?environment=production"></script>
The headless snippet needs the current tracking script. If your project still uses the legacy tracking script, switch first. See Migrate from the Legacy Tracking Script to the New Tracking Script.
⚠️ Important: If your storefront sends a Content Security Policy, add Convert’s sources to it and give the tracking script tag your policy’s nonce, or the browser blocks Convert. Hydrogen versions up to 2026-04 add a policy by default. From Hydrogen 2026-10, your storefront sets its own. See How to Configure Your Website’s CSP Policy for Convert Experiments, which also covers nonces.
Hydrogen changes pages without a full page load. Convert’s tracking script handles this on its own. See Running Experiments on Single Page Apps.
Step 2: Add the Headless Snippet to Global Project Javascript
The snippet has to run inside the Convert tracking script, so it goes in your project’s Global Project Javascript. That is the only supported place for it.
- In Convert, open your project, click the Configuration tab and open Global Javascript.
- Under Select Environment, choose All Environments, so the snippet runs in every environment.
- Paste three parts, in this order:
- Your configuration, which you fill in at Step 3.
- The headless snippet. Copy it unedited from the Shopify Headless Cart Attributes recipe.
- The carrier stub from the developer guide. It holds the Convert cart attributes until your storefront sends them in Step 4.
- Click Save Changes.

⚠️ Important: Don’t move the snippet into your storefront’s code, such as a React effect, a router hook, a dynamic import or a timer. The snippet must be registered before Convert checks goals on page load. If it is registered later, it fails silently: you see no error, no cart attributes are written, and orders aren’t credited to your experiences.
Convert runs Global Project Javascript again each time your storefront changes route. The snippet sets itself up once, so you don’t need extra code for route changes.
📒Note: When a new version of the snippet is published, copy part 2 from the recipe again. Your configuration in part 1 stays as it is, because it sits above the snippet.
Step 3: Fill In Your Configuration
Part 1 sets seven values for the snippet. Replace each placeholder with your own value from the Convert Shopify App and from Convert, so the snippet and the app use the same settings. The developer guide shows the same block.
window.convertHeadless = window.convertHeadless || {};
window.convertHeadless.config = window.convertHeadless.config || {
accountId: 'YOUR_ACCOUNT_ID',
projectId: 'YOUR_PROJECT_ID',
currency: 'YOUR_CURRENCY_CODE',
revenueGoalId: 'YOUR_CHECKOUT_COMPLETED_GOAL_ID',
subscriptionGoalId: 'YOUR_SUBSCRIPTION_GOAL_ID',
oneTimePaymentGoalId: 'YOUR_NON_SUBSCRIPTION_GOAL_ID',
webhookId: 'enabled'
};
| Value | What to enter |
|---|---|
accountId | Required. The first number in your tracking script’s file name. |
projectId | Required. The second number in the file name. It must be the project selected on the app’s Project Configuration tab. |
currency | The three-letter currency code chosen in Currency Selection on Project Configuration. |
revenueGoalId | The ID of the goal chosen as Checkout Completed Goal on Project Configuration. |
subscriptionGoalId | The ID of the Subscription Goal on Other Goals. Use '' if you haven’t chosen one. |
oneTimePaymentGoalId | The ID of the Non-Subscription Goal on Other Goals. Use '' if you haven’t chosen one. |
webhookId | Any text, such as 'enabled'. Keep Setup Order Completed Webhook or not set to Enabled in the app. If webhookId is empty, the snippet doesn’t write the Convert cart attributes, which is how orders get credited on a headless storefront. |
To find a goal’s ID, open your project’s Goals tab in Convert and look at the ID column.
📒Note: If accountId or projectId is empty, the snippet does nothing at all.
Step 4: Connect Your Cart
The snippet prepares the Convert cart attributes, but it never sends them itself, because only your storefront knows its cart. Choose the option that matches how your storefront creates carts. The developer guide has working code for each one.
| Option | Use it when | What your code does |
|---|---|---|
| A. Existing cart | Your storefront keeps a Storefront API cart and updates it. This is the usual Hydrogen and Oxygen setup. | Merges the Convert attributes with the cart’s current attributes and saves them with the cartAttributesUpdate mutation. If there is no cart yet, it passes the attributes to cartCreate when your storefront creates the cart, for example on the first add to cart. |
| B. Cart created at click | A buy button creates the cart with cartCreate and sends the shopper to checkout. | Passes the Convert attributes in the attributes input of cartCreate. |
| C. Cart permalinks | Checkout is on a different domain from your storefront, reached through /cart/<variant>:<quantity> links. | Adds the Convert attributes to each permalink when the shopper clicks it. This code goes in Global Project Javascript, below part 3. |
Options A and B go in your storefront’s code, not in Global Project Javascript.
📒Note: With option B, a shopper who clicks buy before Convert has finished loading, or within about 300 ms after, checks out before the attributes are ready, and that order isn’t credited to the experience.
📒Note: With option C, the app’s Other Goals for storefront events, such as product views, collection views and searches, don’t fire. Revenue at checkout is still credited. To track storefront actions with any option, use goals you create in Convert.
⚠️ Important: Don’t rely on posting to /cart/update.js from a headless storefront. Use one of the three options above.
The headless snippet handles tracking and order attribution only. It doesn’t apply the app’s Pricing Rules or Shipping Rules.
Understand How Purchases and Revenue Are Tracked
You don’t need a separate revenue tracking code. Once your cart carries the Convert attributes, the Convert Shopify App reads them when the shopper completes checkout. It records the purchase and its revenue for the variation the visitor saw. The order webhook (Setup Order Completed Webhook or not) records the same purchase as a backup. See Event Codes Visibility for Shopify Order Pages.
- Your Checkout Completed Goal records each order and its revenue.
- If you set a Subscription Goal and a Non-Subscription Goal, the order’s subscription items are recorded on the first and its one-time items on the second. An order that has both kinds of items counts on both goals.
- Keep the goal IDs and the currency in part 1 the same as in the app. If you change the Currency Selection, Checkout Completed Goal, Subscription Goal or Non-Subscription Goal in the app, update part 1 to match.
- Other goals you create in Convert, such as page visits, clicks or custom JavaScript goals, are tracked by the tracking script on your storefront. They need no change to the snippet.
Check Your Installation
Test with a visitor who is in an active experience. A QA audience keeps real visitors out while you test. See QA Guide.
- Open your storefront in a private window, on a page where the experience runs.
- Open your browser’s console and run
window.convertHeadless.version. It prints the snippet version, for example4, which shows the snippet is in place. Quote this number if you contact support. - After the page settles, run
window.convertHeadlessCart.attributes. You should see oneexperience_<id>entry for each experience you’re in, plus__data. If it showsnull, see Fix common problems. - With option A, run
typeof window.convertHeadlessCart.send. It must print'function'. - With option A, add a product to the cart and check that the cart’s attributes carry the same keys. With option B, check the order in the next step instead.
- Place a test order. In Shopify admin, the order should list the
experience_attributes. Then check the experience report for the purchase.
💡Tip: For more detail, add ?convert_log_level=debug to the page URL and watch the console.
Fix Common Problems
Q: Nothing happens and I see no errors.
- Check that the snippet is in Global Project Javascript and not loaded from your storefront’s code. A late snippet never runs, on every page load. See Step 2.
- If your project has goals that use country, region, city or weather conditions, Convert first loads extra visitor data with a request to
/getjs/extra/data.js. If an ad blocker, your Content Security Policy or a consent tool blocks that request, the snippet never runs. Check your browser’s Network tab for it.
Q: window.convertHeadlessCart.attributes stays null.
- Check that
webhookIdin part 1 isn’t empty. - Check that you’re in an active experience. A visitor who isn’t in any experience has nothing to attribute.
Q: window.convertHeadlessCart is undefined.
- Part 3, the carrier stub, is missing from Global Project Javascript.
Q: The attributes show in the console, but the cart has none.
- Check your option A code that saves the attributes, your option B
cartCreateinput, or, for option C, that its code sits below part 3 in Global Project Javascript.
Q: Some visitors have no experience data.
- If you ask visitors for consent before Convert tracks them, a visitor who hasn’t given consent has no experience data. This is expected.
Q: The same conversion is counted twice.
- Check that your storefront’s domain is listed under Active Websites on your project’s Configuration tab. Without it, Convert can’t remember which goals a visitor already triggered.
Q: I followed an older Convert guide for Hydrogen.
- Replace that code with the headless snippet. The older guides, with code such as
getConvertCartAttributeor a custom cart-attributes route, were written for earlier versions of Hydrogen and of the Convert tracking script.
FAQ
Q: Do I still need a revenue tracking code on a Hydrogen store?
- No. The Convert Shopify App records purchases and revenue at checkout. The snippet only makes sure each order carries the visitor’s experiences. See Understand how purchases and revenue are tracked.
Q: Do I have to update the snippet every time I add a goal?
- No. New goals in Convert need no change. Update part 1 only when you change the Currency Selection, Checkout Completed Goal, Subscription Goal or Non-Subscription Goal in the app.
Q: Why doesn’t Convert work on Hydrogen without extra code?
- The Convert Shopify App adds its tracking through a theme app embed, and only Liquid themes can load app embeds. Hydrogen replaces the Liquid theme with your own code, so the headless snippet does the same job from Global Project Javascript.
Q: I get convert.getDefaultSegments is not a function.
- That error means older helper code called the tracking script’s methods before the script had finished starting up. The headless snippet only calls them after the tracking script has loaded and evaluated your goals. Replace the old code with the snippet.