> ## Documentation Index
> Fetch the complete documentation index at: https://docs.traceten.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Shopify

> Add Traceten to Shopify by editing theme.liquid.

## What this lets you do

Track AI-referred traffic on every page of your Shopify store, then attribute that traffic to orders via the [Shopify integration](/integrations/shopify).

## Before you start

* **Connect your store first**, under **Settings → Integrations → Shopify**. See the [Shopify integration guide](/integrations/shopify). Connecting is what tells Traceten your real storefront domain, so the tag you copy in a moment already carries the right `data-cookie-domain`. Pasting the snippet first works, it just means coming back to re-copy the tag afterwards.
* Your Traceten site key, from **Sites → Install** in the [dashboard](https://app.traceten.com/dashboard).
* Shopify admin access with permission to edit theme code.
* Note which theme is currently published (live). You'll edit that theme's files.

## Why you paste this by hand

Shopify used to let an app inject a script for you. It does not any more: script tag creation stops working on 1 October 2026, and script tags stop running on storefronts entirely on 1 March 2027. Every other automatic route (theme app extensions, web pixels, writing to theme files) needs an extension or an exemption that an app you created yourself cannot have.

So the snippet goes in your theme, by hand, once. Traceten asks for read access to your themes when you connect the store, so it can check the snippet is still there for you later, but that check is not switched on yet. For now, re-paste the snippet yourself whenever you change themes.

## Steps

<Steps>
  <Step title="Open the theme code editor">
    In your Shopify admin, go to **Online Store → Themes**.

    Next to your live theme, click **Actions → Edit code**.
  </Step>

  <Step title="Open theme.liquid">
    In the file tree on the left, under **Layout**, click **theme.liquid**.

    This file wraps every page in your store. Changes here apply everywhere.
  </Step>

  <Step title="Find the closing </head> tag">
    Use Ctrl+F (Cmd+F on Mac) to search for `</head>`. You'll see a line that ends the head section, usually right above `<body>`.
  </Step>

  <Step title="Paste the snippet just before </head>">
    ```liquid theme={null}
      {%- comment -%}Traceten AI traffic attribution{%- endcomment -%}
      <script
        async
        src="https://cdn.traceten.com/tt.min.js"
        data-site="ttid_7Rb4TrC1dTbnD8w3s1TS12"
        data-cookie-domain="example.com"
      ></script>
    </head>
    ```

    Copy the whole tag from **Sites → Install** for your site so `data-site` (your site key) is already yours.

    `data-cookie-domain` keeps one visitor as one visitor across your domains, which is what lets a visit to your blog and a purchase on your store count as one person. If you connected your store first, Traceten set it from the storefront domain Shopify reports and the attribute is already on the tag. Otherwise it appears once you confirm a value under **Sites → Settings → Cookies**.

    Keep the snippet on the line immediately before `</head>`.
  </Step>

  <Step title="Save the file">
    Click **Save** in the top right. The snippet is now live on every page of your store.
  </Step>
</Steps>

## Verify installation

Open your Shopify store in a browser, then open **Sites → Install** in the [dashboard](https://app.traceten.com/dashboard) and look at the **Verify** step. It should turn green within 30 seconds of a pageview.

## When you change themes

The snippet lives in one theme's `theme.liquid`. Switching themes, or publishing a duplicate you edited elsewhere, leaves it behind, and tracking stops with no error anywhere. Re-paste it into the new theme before you publish, and check the **Verify** step afterwards.

## Revenue attribution

The snippet alone tracks visits. To attribute those visits to Shopify orders, connect the Shopify integration from your Traceten dashboard. The integration uses the Shopify webhook API to match confirmed orders back to AI-attributed sessions.

<Card title="Connect Shopify" icon="bag-shopping" href="/integrations/shopify">
  Link orders to AI-referred sessions via the Shopify integration.
</Card>

## Notes

**Checkout pages.** Shopify's checkout (`/checkout`, `/thank_you`) runs on a subdomain (`checkout.shopify.com`) and does not include your `theme.liquid`. Traceten handles this in two ways: the session ID stored before checkout is used for attribution, and the snippet also writes a `_traceten_cart` cookie (24-hour, `SameSite=Lax`) when it detects the Shopify checkout context. This cart token is included in event payloads so the Traceten Shopify integration can match completed orders back to the originating AI session even for guest checkouts. The `_traceten_cart` cookie is never written for visitors who have opted out. See [Cookies](/privacy/cookies) for full details.

**Theme updates.** When you update or switch your theme, the `theme.liquid` edit needs to be re-applied to the new theme. Check after any theme change.

**Duplicate snippets.** Some Shopify apps inject their own scripts into `theme.liquid`. Make sure the Traceten snippet appears only once. Search for `traceten` in `theme.liquid` to verify.

**Headless Shopify.** If your storefront is built with a separate framework (Hydrogen, Next.js, custom), follow the [Next.js install guide](/install/nextjs) or [HTML guide](/install/html) for the frontend, and configure the Shopify integration for revenue attribution on the backend.

## Next steps

* [Verify the snippet is firing](/install/verify)
* [Troubleshooting](/install/troubleshooting)
* [Connect the Shopify integration](/integrations/shopify)
