✦ Southern Swells · Tracker setup

Step 1 · Add the tracker to Shopify (5 minutes)

  1. In Shopify admin, go to Settings › Customer events.
  2. Tap Add custom pixel, name it Southern Swells Tracker.
  3. Delete what's in the code box, paste everything below, tap Save, then Connect.
// Southern Swells ad tracker. Paste into Shopify: Settings > Customer events > Add custom pixel
const ENDPOINT = "https://go.shopsouthernswells.com/c", SITE = "9c1c8fa4f69512c0";
const KEYS = ["utm_source","utm_medium","utm_campaign","utm_content","utm_term","campaign_id","adset_id","ad_id","fbclid","ttclid","gclid"];
const store = browser.localStorage;
async function vid() { let v = await store.getItem("ssv_id"); if (!v) { v = Date.now().toString(36) + Math.random().toString(36).slice(2, 10); await store.setItem("ssv_id", v); } return v; }
async function remember(href) {
  const u = new URL(href), t = {};
  KEYS.forEach(function (k) { const x = u.searchParams.get(k); if (x) t[k] = x.slice(0, 200); });
  if (!Object.keys(t).length) return;
  t.ts = Date.now(); t.landing = u.pathname;
  await store.setItem("ssv_last", JSON.stringify(t));
  if (!(await store.getItem("ssv_first"))) await store.setItem("ssv_first", JSON.stringify(t));
}
async function send(ev, extra) {
  const body = Object.assign({ k: SITE, ev: ev, vid: await vid(), url: init.context.document.location.href,
    last: JSON.parse((await store.getItem("ssv_last")) || "null"), first: JSON.parse((await store.getItem("ssv_first")) || "null"),
    mob: /Mobi/i.test(init.context.navigator.userAgent) }, extra || {});
  fetch(ENDPOINT, { method: "POST", body: JSON.stringify(body), keepalive: true, headers: { "content-type": "text/plain" } });
}
analytics.subscribe("page_viewed", async function (e) { await remember(e.context.document.location.href); send("view", { url: e.context.document.location.href }); });
analytics.subscribe("product_added_to_cart", function (e) { send("add_to_cart", { value: Number(e.data && e.data.cartLine && e.data.cartLine.cost && e.data.cartLine.cost.totalAmount && e.data.cartLine.cost.totalAmount.amount || 0) }); });
analytics.subscribe("checkout_started", function (e) { send("checkout", { value: Number(e.data && e.data.checkout && e.data.checkout.totalPrice && e.data.checkout.totalPrice.amount || 0) }); });
analytics.subscribe("checkout_completed", function (e) {
  const c = e.data.checkout;
  send("purchase", { value: Number(c.totalPrice && c.totalPrice.amount || 0), order: { id: String(c.order && c.order.id || c.token), total: Number(c.totalPrice && c.totalPrice.amount || 0),
    currency: c.currencyCode, items: (c.lineItems || []).reduce(function (n, l) { return n + (l.quantity || 0); }, 0),
    lines: (c.lineItems || []).map(function (l) { return { t: l.title || (l.variant && l.variant.product && l.variant.product.title) || "", q: l.quantity || 1 }; }) } });
});

Step 2 · Put the tracking key on every Meta ad

  1. In Ads Manager, open an ad and scroll to Tracking › URL parameters.
  2. Paste this line (Meta fills in the names and numbers by itself):
utm_source=facebook&utm_medium=paid&utm_campaign={{campaign.name}}&utm_content={{ad.name}}&campaign_id={{campaign.id}}&adset_id={{adset.id}}&ad_id={{ad.id}}

Tip: select all your ads at once and paste it in one go with Edit.

Step 3 · Let the tracker read your ad spend

Claude will walk you through this one. It needs a Meta access token and your ad account number.

Step 4 · Connect Shopify customers (read-only)

Lets the tracker see who bought, spot repeat customers and drop test or cancelled orders. It can only read, never change anything.

  1. Shopify admin › Settings › Apps and sales channels › Develop apps › Create an app, name it Ad Tracker.
  2. Configure Admin API scopes: tick read_orders and read_customers, then Save.
  3. Install app, then reveal the Admin API access token once and send it to Claude with your store address (yourstore.myshopify.com).

Step 5 · Save the tracking key on every order (2 minutes)

Some phones block the pixel. This small piece of code also writes the ad's tracking key onto the shopper's cart, so it shows up on the order itself.

  1. Shopify admin › Online Store › Themes › on your live theme tap ⋯ › Edit code.
  2. Open layout › theme.liquid.
  3. Find the line </head> (use the search box), paste the code just above it, and tap Save.
<script>/* Southern Swells ad tags: saves which ad a shopper came from on their cart, so it lands on the order */
(function () { var K = ["utm_source","utm_medium","utm_campaign","utm_content","utm_term","campaign_id","adset_id","ad_id","fbclid"];
try { var u = new URLSearchParams(location.search), t = {}, n = 0;
K.forEach(function (k) { var v = u.get(k); if (v) { t[k] = v.slice(0, 200); n++; } });
if (n) { t.ts = Date.now(); localStorage.setItem("ss_adtags", JSON.stringify(t)); }
var s = JSON.parse(localStorage.getItem("ss_adtags") || "null"); if (!s || Date.now() - s.ts > 2592e6) return;
fetch("/cart.js").then(function (r) { return r.json(); }).then(function (c) {
  if (c && c.attributes && c.attributes._ss_ts === String(s.ts)) return;
  var a = { _ss_ts: String(s.ts) }; K.forEach(function (k) { if (s[k]) a["_ss_" + k] = s[k]; });
  return fetch("/cart/update.js", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ attributes: a }) });
}).catch(function () {}); } catch (e) {} })();
</script>

Optional · Order backup

Shopify can also send each order straight to the tracker in case a phone blocks the pixel. Shopify admin › Settings › Notifications › Webhooks › Create webhook: event Order creation, format JSON, URL:

https://go.shopsouthernswells.com/hooks/shopify

Then give Claude the signing secret shown on that page.

← Back to the dashboard