Platform guides Doc #3

Shopify: gateway setup

Add the Anacoic gateway to your Shopify store and send purchases server-side

This guide adds the Anacoic gateway (Fix) to your Shopify store, so its events reach the ad platforms from the server. The basic setup needs no code.

Purchases go through Customer Events. Shopify is retiring checkout Additional scripts, and the tracker can’t run inside checkout. Send purchases with a Customer Events custom pixel instead: Shopify: purchases with Customer Events. The methods below cover the storefront: page views, product views and other events before checkout.

Want to check your Shopify orders against what Meta recorded? That’s Watch, in early access, which connects through the Anacoic Shopify app: see Watch: getting started.

What you need

  • A Shopify store (any plan)
  • An Anacoic account
  • A Meta Pixel ID (if you advertise on Meta)

The quickest way to add the gateway to Shopify.

Step 1: copy your snippet

  1. Sign in to the app and open Fix in the sidebar.
  2. Add a gateway, or open one you have.
  3. Open the Setup tab.
  4. Copy the snippet under Install the tracking code:
<script src="https://edge.anacoic.com/v1/ana.js"
        data-gateway="YOUR_GATEWAY_ID"
        data-emq="optimize"></script>

Step 2: add it to your Shopify theme

  1. In the Shopify admin, go to Online Store → Themes.
  2. Choose Customize on your active theme.
  3. Open Theme settings (the gear icon) in the left sidebar.
  4. Select Custom code or Custom CSS/JS (it varies by theme).
  5. Paste the snippet in the Head section.
  6. Choose Save.

Step 3: check it’s installed

  1. Visit your store’s home page.
  2. Open your browser’s developer tools (F12).
  3. Go to the Network tab.
  4. Filter for “anacoic”.
  5. Reload the page.
  6. You should see a request to edge.anacoic.com/track.

Method 2: theme.liquid

For more control over where the tracker loads.

Add it to theme.liquid

  1. Go to Online Store → Themes → Edit code
  2. Find layout/theme.liquid
  3. Find the <head> section
  4. Paste your snippet right before </head>:
<!-- Anacoic tracker -->
<script src="https://edge.anacoic.com/v1/ana.js"
        data-gateway="YOUR_GATEWAY_ID"
        data-emq="optimize"></script>
  1. Choose Save.

Method 3: Google Tag Manager

If you already use GTM on your Shopify store.

Create the tag

  1. Open Google Tag Manager.
  2. Choose Tags → New.
  3. Name it “Anacoic tracker”.
  4. Tag type: Custom HTML.
  5. Paste your snippet.
  6. Trigger: All Pages.
  7. Save and submit.

Test in preview mode

  1. Choose Preview in GTM.
  2. Enter your store’s URL.
  3. Check that the Anacoic tag fires when the page loads.

Sending purchase events

Ad platforms match a purchase to a person using the identifiers you send with it (match keys). Pass the customer data you collected at checkout, with consent.

Add a custom pixel under Settings → Customer events that sends each completed checkout to the gateway, with the order, value, currency, items and the _fbp, _fbc and _ttp cookies, and only for visitors who allowed it. The full code and steps are in Shopify: purchases with Customer Events.

Legacy: Additional scripts

Shopify is retiring Additional scripts on the order status page. If your store still has it, the snippet below keeps working until Shopify switches it off; move to Customer Events before then. Under Settings → Checkout → Additional scripts:

<script src="https://edge.anacoic.com/v1/ana.js"
        data-gateway="YOUR_GATEWAY_ID"
        data-emq="optimize"></script>
<script>
  // Wait for tracker to load
  setTimeout(function() {
    if (window.anacoic) {
      window.anacoic.track({
        event_name: 'Purchase',
        event_id: 'order_{{ order.id }}',
        user: {
          email: '{{ order.email }}'
        },
        custom_data: {
          value: {{ order.total_price | divided_by: 100.0 }},
          currency: '{{ order.currency }}'
        }
      });
    }
  }, 1000);
</script>

Sending match keys

Match keyHow it’s sent
Emailuser.email from the customer object (hashed with SHA-256 at the gateway)
Phoneuser.phone from the customer object, E.164 format
External IDuser.external_id: the Shopify customer ID
Meta browser ID (_fbp)Captured automatically from the cookie
Meta click ID (_fbc)Captured automatically from the cookie or the fbclid parameter
IP address and user agentAdded automatically at the gateway

Meta scores how well it can match your events (Event Match Quality) in Events Manager → Data sources → your dataset. The app shows which match keys your events actually carry under the gateway’s Diagnostics, then Event quality.

A full purchase event

anacoic.track({
  event_name: 'Purchase',
  event_id: 'order_{{ order.id }}',
  user: {
    email: '{{ customer.email }}',
    phone: '{{ customer.phone }}',
    external_id: '{{ customer.id }}'
  },
  custom_data: {
    value: {{ order.total_price }},
    currency: '{{ shop.currency }}'
  }
});

Common Shopify issues

Events not firing

Check the theme’s Content Security Policy.

Some themes block outside scripts. Add this to your CSP:

script-src 'self' https://edge.anacoic.com;
connect-src 'self' https://edge.anacoic.com;

Customer data not available

Check which Liquid objects the page has.

Not all customer data is available on every page:

  • {{ customer }} - Only available when logged in
  • {{ order }} - Only available on order/confirmation pages
  • {{ checkout }} - Only available during checkout

Duplicate events

Use one stable event ID per order.

Give every event for the same order the same event_id, in the browser and on the server, so the platform can recognize the copies as one purchase:

event_id: 'order_{{ order.id }}'

Don’t add timestamps or random values to the ID: every copy then looks like a different purchase and gets counted twice.

More for Shopify

Signed-in customers

With enrichment on, the tracker adds a signed-in Shopify customer’s email and customer ID to each event, when the page exposes them:

<script>
  window.anacoic_config = {
    gateway_id: 'YOUR_GATEWAY_ID',
    emq: 'optimize',
    enrich: true  // adds the signed-in customer's email and ID
  };
</script>
<script src="https://edge.anacoic.com/v1/ana.js"></script>

Product views

Send product views for dynamic ads:

// On product page
anacoic.track({
  event_name: 'ViewContent',
  custom_data: {
    content_name: '{{ product.title }}',
    content_type: 'product',
    content_ids: ['{{ product.id }}'],
    value: {{ product.price | divided_by: 100.0 }},
    currency: '{{ shop.currency }}'
  }
});

Next steps

  1. Send purchases with Customer Events.
  2. Connect Meta’s Conversions API.
  3. Add a custom domain, so events go to your own subdomain.

Getting help