AFFNHelp centerSign in

Shopify setup

About 10 minutes. You'll need access to your theme code and the free Shopify Flow app.

1. Set your offer's landing URL

https://yourstore.myshopify.com/?s2s_click={click_id}

2. Save the click ID on the order

  1. 1
    In Shopify admin go to Online Store → Themes → … → Edit code.
  2. 2
    Open layout/theme.liquid and paste this just before </body>. Then save.
theme.liquid
<script> (function () { var KEY = 's2s_click'; var id = new URLSearchParams(location.search).get(KEY); if (id) localStorage.setItem(KEY, id); id = id || localStorage.getItem(KEY); if (!id) return; // Attach the click ID to the cart so it is saved on the order fetch('/cart/update.js', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ attributes: { s2s_click: id } }) }); })(); </script>

This remembers the click ID when the visitor lands and attaches it to the cart, so every order carries an s2s_click attribute.

3. Send the postback with Shopify Flow

  1. 1
    Install Shopify Flow from the Shopify App Store and create a new workflow.
  2. 2
    Trigger: Order created, or Order paid if you only pay for paid orders.
  3. 3
    Add a condition: the order's custom attributes include the key s2s_click.
  4. 4
    Action: Send HTTP request, method GET, with this URL:
HTTP request URL
https://affn.io/api/public/postback?click_id={% for a in order.customAttributes %}{% if a.key == "s2s_click" %}{{ a.value }}{% endif %}{% endfor %}

Include &amount={{ order.currentSubtotalPriceSet.shopMoney.amount }}&order_id={{ order.name }} so percent and product commission rules apply. Turn the workflow on.

No Flow? Use a custom pixel (fallback)

Go to Settings → Customer events → Add custom pixel and paste the code below. It runs in the shopper's browser, so ad blockers can stop it. Use Flow whenever you can.

Custom pixel
const KEY = 's2s_click'; analytics.subscribe('checkout_completed', async () => { const id = await browser.localStorage.getItem(KEY); if (!id) return; fetch('https://affn.io/api/public/postback?click_id=' + encodeURIComponent(id), { keepalive: true }); });
Test your setup
  • Open a partner link and confirm the address bar shows ?s2s_click=…
  • Place a test order (Bogus Gateway or a 100% discount code)
  • In the order's Additional details, s2s_click is listed
  • Flow's run history shows the HTTP request with status 200
  • The conversion appears under Conversions in AFFN