Meta Pixel Bridge (Shopify Custom Pixel)
An optional Shopify Custom Pixel snippet that fires Meta (fbq) and TikTok (ttq) browser-side
events for upper-funnel activity, sharing Shopify's own event identifier with the server-side events AxiTrace already
sends via Conversions API - so Meta and TikTok can deduplicate the pair instead of double-counting.
AxiTrace's Shopify app already forwards your events server-side via Facebook Conversions API and TikTok Events API - that pipeline works today and needs nothing from this page. A redundant browser pixel is a second, independent copy of the same events, fired directly from the customer's browser via a Shopify Custom Pixel . Meta and TikTok both support receiving the same logical event twice (once server-side, once browser-side) and merging them into one, as long as both copies share the same event ID. Having both improves match quality and gives you a browser-side signal even if a customer's network briefly drops the server-side call.
This bridge covers PageView, ViewContent, AddToCart and InitiateCheckout only. It never subscribes
to Shopify's checkout_completed event, and it must not be extended to do so without re-reading this
section.
Purchase carries real revenue, and Shopify itself documents checkout_completed as lossy (Shop Pay
accelerated checkouts and platform outages can skip it entirely). AxiTrace's server-side Conversions API
integration already sends Purchase reliably from your order webhooks. Adding a second, browser-fired Purchase
event on top of that - matched only by an unverified cross-pixel-instance event ID - risks
double-counting or under-counting real revenue if the identity assumption ever turns out to be wrong for your
store. That risk is not worth taking for a number that feeds your ad account's optimization and your own
revenue reporting. Purchase stays 100% CAPI-only by design.
How the event ID matching works
Every event Shopify's Customer Events system delivers to a pixel carries a Shopify-generated event.id.
Both the AxiTrace app pixel (already installed with your Shopify connection, forwarding to our servers) and this
Custom Pixel are independent subscribers to the same underlying Shopify event - so they both
receive the same event.id for the same customer action. The Custom Pixel below passes that ID straight
through to Meta as {eventID: event.id} and to TikTok as {event_id: event.id}, matching
exactly what AxiTrace's server-side forwarding sends as its own event_id for the corresponding event.
Setup
- Open your workspace's Facebook Conversions API connection page in the AxiTrace admin panel - a personalized version of the snippet below, with your Pixel ID (and TikTok Pixel ID, if connected) already filled in, is shown there once your Pixel ID is saved.
- In your Shopify admin, go to Settings → Customer events.
- Click Add custom pixel, name it (e.g. "AxiTrace Meta Pixel Bridge"), and paste the snippet into the code editor.
- Set the pixel's data-collection permissions the same way as the AxiTrace app pixel (see the consent callout below).
- Save and connect the pixel.
Example snippet
The example below uses placeholder pixel IDs. The copy in your admin panel already has your real IDs substituted.
// AxiTrace Meta Pixel Bridge — Shopify Custom Pixel
// Fires Meta (fbq) and, when configured, TikTok (ttq) browser-side
// events for upper-funnel activity only, sharing Shopify's event.id
// with AxiTrace's server-side Conversions API forwarding so
// Meta/TikTok can deduplicate the pair instead of double-counting.
//
// Scope: PageView, ViewContent, AddToCart, InitiateCheckout ONLY.
// Purchase (checkout_completed) is intentionally NOT subscribed here
// — see the AxiTrace docs page linked from your admin panel for why.
(function () {
"use strict";
var META_PIXEL_ID = "YOUR_META_PIXEL_ID";
function get(obj, path, fallback) {
var cur = obj;
for (var i = 0; i < path.length; i++) {
if (cur === null || typeof cur === "undefined") {
return fallback;
}
cur = cur[path[i]];
}
return (cur === null || typeof cur === "undefined") ? fallback : cur;
}
function pageUrl(event) {
return get(event, ["context", "document", "location", "href"], undefined);
}
// --- Meta Pixel loader (init only — this snippet controls every
// track() call explicitly, no auto-tracked PageView) ---
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version="2.0";n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,"script","https://connect.facebook.net/en_US/fbevents.js");
fbq("init", META_PIXEL_ID);
var TIKTOK_PIXEL_ID = "YOUR_TIKTOK_PIXEL_ID";
// --- TikTok Pixel loader (load only — this snippet controls
// every track() call explicitly, no auto-tracked page event) ---
!function (w, d, t) {
w.TiktokAnalyticsObject = t;
var ttq = (w[t] = w[t] || []);
ttq.methods = ["page", "track", "identify", "instances", "debug", "on", "off",
"once", "ready", "alias", "group", "enableCookie", "disableCookie",
"holdConsent", "revokeConsent", "grantConsent"];
ttq.setAndDefer = function (obj, method) {
obj[method] = function () {
obj.push([method].concat(Array.prototype.slice.call(arguments, 0)));
};
};
for (var i = 0; i < ttq.methods.length; i++) {
ttq.setAndDefer(ttq, ttq.methods[i]);
}
ttq.load = function (pixelId, options) {
var src = "https://analytics.tiktok.com/i18n/pixel/events.js";
ttq._i = ttq._i || {};
ttq._i[pixelId] = [];
ttq._i[pixelId]._u = src;
ttq._t = ttq._t || {};
ttq._t[pixelId] = +new Date();
ttq._o = ttq._o || {};
ttq._o[pixelId] = options || {};
var script = d.createElement("script");
script.type = "text/javascript";
script.async = true;
script.src = src + "?sdkid=" + pixelId + "&lib=" + t;
var firstScript = d.getElementsByTagName("script")[0];
firstScript.parentNode.insertBefore(script, firstScript);
};
ttq.load(TIKTOK_PIXEL_ID);
}(window, document, "ttq");
// Upper-funnel Shopify Customer Events only. checkout_completed
// (Purchase) is NEVER subscribed here by design.
analytics.subscribe("page_viewed", function (event) {
var url = pageUrl(event);
fbq("track", "PageView", { page_url: url }, { eventID: event.id });
if (typeof ttq !== "undefined") {
ttq.track("Pageview", { url: url }, { event_id: event.id });
}
});
analytics.subscribe("product_viewed", function (event) {
var variant = get(event, ["data", "productVariant"], null);
var url = pageUrl(event);
var value = Number(get(variant, ["price", "amount"], 0)) || 0;
var currency = get(variant, ["price", "currencyCode"], "");
var productId = String(get(variant, ["product", "id"], ""));
fbq("track", "ViewContent", {
content_ids: [productId],
content_type: "product",
value: value,
currency: currency,
page_url: url
}, { eventID: event.id });
if (typeof ttq !== "undefined") {
ttq.track("ViewContent", {
contents: [{ content_id: productId, content_type: "product" }],
value: value,
currency: currency
}, { event_id: event.id });
}
});
analytics.subscribe("product_added_to_cart", function (event) {
var line = get(event, ["data", "cartLine"], null);
var variant = get(line, ["merchandise"], null);
var qty = Number(get(line, ["quantity"], 1)) || 1;
var totalAmount = Number(get(line, ["cost", "totalAmount", "amount"], 0)) || 0;
var price = Number(get(variant, ["price", "amount"], 0)) || 0;
var value = totalAmount > 0 ? totalAmount : price * qty;
var currency = get(line, ["cost", "totalAmount", "currencyCode"], "") ||
get(variant, ["price", "currencyCode"], "");
var productId = String(get(variant, ["product", "id"], ""));
var url = pageUrl(event);
fbq("track", "AddToCart", {
content_ids: [productId],
content_type: "product",
value: value,
currency: currency,
page_url: url
}, { eventID: event.id });
if (typeof ttq !== "undefined") {
ttq.track("AddToCart", {
contents: [{ content_id: productId, content_type: "product", quantity: qty }],
value: value,
currency: currency
}, { event_id: event.id });
}
});
analytics.subscribe("checkout_started", function (event) {
var checkout = get(event, ["data", "checkout"], null);
var lineItems = get(checkout, ["lineItems"], []) || [];
var value = Number(get(checkout, ["totalPrice", "amount"], 0)) || 0;
var currency = get(checkout, ["totalPrice", "currencyCode"], "");
var url = pageUrl(event);
var contentIds = lineItems.map(function (li) {
return String(get(li, ["variant", "product", "id"], ""));
});
fbq("track", "InitiateCheckout", {
content_ids: contentIds,
content_type: "product",
value: value,
currency: currency,
num_items: lineItems.length,
page_url: url
}, { eventID: event.id });
if (typeof ttq !== "undefined") {
ttq.track("InitiateCheckout", {
contents: contentIds.map(function (id) {
return { content_id: id, content_type: "product" };
}),
value: value,
currency: currency
}, { event_id: event.id });
}
});
// NOTE: checkout_completed / Purchase is intentionally NOT
// subscribed here. AxiTrace's server-side Conversions API
// integration already sends Purchase reliably; adding a second,
// unverified client-side Purchase path risks double- or
// mis-counted revenue. Purchase coverage stays CAPI-only.
})();
Shopify gates Custom Pixels behind customer privacy consent by default. Set this pixel's permissions the same
way as the AxiTrace app pixel: analytics = false, marketing = false,
sale_of_data = disabled - i.e. do not require marketing/analytics consent to
run it. If you leave the default gating in place, EEA/UK visitors who decline cookies will silently produce
zero bridge coverage while everything still looks "connected". This exact failure mode has previously affected
the AxiTrace app pixel itself, so double-check this setting explicitly rather than assuming the default is fine.
Verifying deduplication
- Open Meta Events Manager → your pixel → Test Events.
- Browse your store in the same tab Test Events is watching: view a product, add it to cart, start checkout.
- For each event, confirm you see one entry with status "Deduplicated" (or two entries, browser + server, explicitly matched) rather than two separate, unmatched entries.
- If you also have a TikTok connection, repeat the same check in TikTok's Events Manager test tool.
- If events show as separate/unmatched instead of deduplicated, see the Pixel Deduplication troubleshooting guide.
- Covers PageView, ViewContent, AddToCart, InitiateCheckout - browser-side, in addition to your existing server-side Conversions API events.
- Purchase stays CAPI-only. This snippet never subscribes to
checkout_completed. - Set consent permissions to match the AxiTrace app pixel, or coverage silently drops to zero for consent-declining visitors.
- Verify with Meta/TikTok Test Events before relying on the reported coverage numbers.