Platforms / Shopify
On this page

Shopify Manual Revenue Attribution Recipe

Connect your Shopify storefront and order revenue to SourceTrack using manual snippet placement and Shopify webhooks.

See which ads, searches and AI referrals turn into paid Shopify orders, not just visits.

Who This Is For

This guide is for eCommerce developers and shop owners using Shopify who want to track marketing campaigns and attribute purchases back to click channels (like Google Ads or AI referrals) using custom code and Shopify webhook triggers.

Key Terms Defined:

  • Theme Liquid (theme.liquid) — the layout file in your Shopify theme that wraps all pages.
  • Cart attributes — custom metadata fields stored on a Shopify cart. We use this to save the anonymous visitor ID (st_aid) so it flows into the final order.
  • Webhook — an automatic server message sent by Shopify when an action occurs (like orders/paid).
  • Signing secret — a value Shopify gives you so SourceTrack can confirm each webhook really came from your store.

What You Will Set Up

You will set up storefront visitor tracking by injecting our pixel, save the visitor ID as a cart attribute, and send Shopify order webhooks to SourceTrack so each paid order is tied back to the visit that earned it.

Integration notice: Integrations offers a one-click Connect Store (OAuth) for Shopify. It registers a SourceTrack web pixel that loads the tracker and subscribes the 8 order, refund, privacy and uninstall webhooks for you. The manual steps below are the fallback for merchants who do not use the OAuth connect, or whose connect reports that the pixel or webhooks could not be registered. SourceTrack does not promise visitor tracking through Shopify checkout from the connect alone; the cart attribute step below is what ties an order back to its marketing source.

Steps: Shopify Integration

The complete install, end to end. Steps 6 and 7 are both required: the webhook delivers the order revenue, and the cart attribute is what lets SourceTrack tell you which marketing source earned it.

  1. In your Shopify Admin, go to Online Store → Themes.
  2. On your current theme, click the action dropdown (the three dots) and select Edit Code.
  3. Open the layout/theme.liquid file.
  4. Paste the tracking script directly before the closing </head> tag.
  5. Save theme.liquid. Shopify publishes the change to your live theme straight away.
  6. Still in your theme, add the cart-attribute snippet so the anonymous visitor ID (st_aid) is saved onto the Shopify cart and travels with the order.
  7. In Shopify Admin → Settings → Notifications, create an orders/paid webhook pointing at /api/webhooks/shopify/YOUR_SITE_KEY. The webhook delivers the order revenue; step 6 is what makes that revenue attributable, so a store with the webhook alone records purchases against no visitor.
  8. In Shopify Admin → Settings → Customer events, click Add custom pixel and paste the checkout pixel snippet to track checkout_started events in Shopify's sandboxed checkout.

Step 1: Storefront Pixel Tracking

Add the standard SourceTrack pixel script to your storefront theme to log UTMs and referrers:

  1. In your Shopify Admin, go to Online Store → Themes.
  2. Click the action dropdown (the three dots) and select Edit Code.
  3. Open the layout/theme.liquid file.
  4. Paste the tracking script directly before the closing </head> tag. Replace YOUR_SITE_KEY:
<!-- Paste inside layout/theme.liquid before </head> -->
<script async src="https://api.srctk.com/tracker.min.js" data-site-key="YOUR_SITE_KEY"></script>

Step 2: Capture Visitor ID in Shopify Cart

To link checkout purchases with marketing sessions, you must store the anonymous visitor ID (st_aid) as a cart attribute. Add this Javascript snippet to your checkout or cart templates:

// Read st_aid from localStorage and forward as a cart attribute
const visitorId = localStorage.getItem('st_aid');
if (visitorId) {
  fetch(window.Shopify.routes.root + 'cart/update.js', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      attributes: {
        'st_aid': visitorId
      }
    })
  });
}

Step 3: Connect Order Webhooks

Configure a webhook inside Shopify to forward order details to your SourceTrack endpoint on purchase confirmation:

  1. In your Shopify Admin, go to Settings → Notifications.
  2. Scroll to the Webhooks section and click Create Webhook.
  3. Configure the webhook details:
    • Event: orders/paid (recommended) or orders/create. With orders/create, SourceTrack only records orders that are already paid — unpaid carts and pending orders are ignored.
    • Format: JSON
    • URL: https://api.srctk.com/api/webhooks/shopify/YOUR_SITE_KEY
    • API Version: Latest / stable
  4. Save the webhook, then copy the Shopify signing secret (shared with all webhooks for the shop) and paste it intoIntegrations → Shopify webhook recipe. SourceTrack uses it to reject any webhook that was not signed by your store.

Attribution stitching: the order webhook reads the visitor ID from thest_aid cart attribute that Step 2 saves, so keep that attribute name exactly as written.

Dedupe: if Shopify redelivers a webhook, SourceTrack records the order once, not as a second conversion.

Step 4: Sandboxed Checkout Funnel Pixel

Because Shopify hosts checkout inside an isolated sandbox, standard theme scripts cannot execute there. Add a Custom Pixel in Shopify Admin to capture checkout_started funnel events:

  1. In your Shopify Admin, go to Settings → Customer events.
  2. Click Add custom pixel, name it SourceTrack Checkout, and click Add pixel.
  3. Paste the code snippet below into the code editor:
// In Shopify Admin > Settings > Customer events > Add custom pixel
analytics.subscribe('checkout_started', (event) => {
  const checkout = event.data?.checkout;
  fetch('https://api.srctk.com/api/track', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    keepalive: true,
    body: JSON.stringify({
      site_key: 'YOUR_SITE_KEY',
      event: 'checkout_started',
      properties: {
        shopify_source: 'web_pixels',
        currency: checkout?.currencyCode,
        checkout_total: checkout?.totalPrice?.amount ? Number(checkout.totalPrice.amount) : undefined,
        item_count: Array.isArray(checkout?.lineItems) ? checkout.lineItems.length : undefined
      }
    })
  });
});

How to Verify It Worked

  1. Place a test order on your storefront theme using Shopify test checkout methods.
  2. In the Shopify Admin webhook settings, click Send test notification on your created webhook to verify the connection.
  3. Go to the SourceTrack dashboard Event Debugger. Verify that a success webhook event logs for the order, and the revenue appears in your overview graphs.

Common Mistakes

  • Missing Cart Attribute: If you forget Step 2, Shopify won't store the visitor ID on the cart. Without it, the order webhook cannot stitch the purchase back to the acquisition source, and the conversion will show as unattributed.
  • No Storefront Script: Ensure your storefront theme is loaded with the tracking pixel so the visitor ID gets generated and stored.

Next Step

Your Shopify integration is complete! You can explore additional API options or customize dashboard views in ourDeveloper Portal.

Still stuck?

Email support@sourcetrack.ai with your site and what you have tried.

Start 28-day free trial