Skip to content

Instantly share code, notes, and snippets.

@zionskynet
Last active August 24, 2025 13:28
Show Gist options
  • Select an option

  • Save zionskynet/b08525e7b295288d4f5365f6f185beec to your computer and use it in GitHub Desktop.

Select an option

Save zionskynet/b08525e7b295288d4f5365f6f185beec to your computer and use it in GitHub Desktop.
Voluum and Shopify events tracking integration code. It's based on native Shopify Customer Events, and it really works without any issues.
// https://help.shopify.com/en/manual/promoting-marketing/pixels/custom-pixels/code
// https://shopify.dev/docs/api/web-pixels-api/standard-events
function getPostbackURL() {
try {
const utmMedium = localStorage.getItem('utmMedium');
const xoClickId = localStorage.getItem('xoClickId');
if (utmMedium === 'xo' && xoClickId) {
return 'https://your-voluum.domain/postback?cid='+xoClickId;
}
} catch(e) {
console.log(e);
}
}
analytics.subscribe('page_viewed', async () => {
try {
const url = new URL(window.document.location.href),
utmMedium = url.searchParams.get('utm_medium'),
xoClickId = url.searchParams.get('utm_term');
if (utmMedium === 'xo' && xoClickId) {
localStorage.setItem('utmMedium', utmMedium);
localStorage.setItem('xoClickId', xoClickId);
}
} catch(e) {
console.log(e);
}
});
analytics.subscribe("product_added_to_cart", async () => {
if (getPostbackURL()) {
const timeStamp = Math.round(Date.now() / 10000);
navigator.sendBeacon(getPostbackURL()+'&et=add_to_cart&txid='+timeStamp);
}
});
analytics.subscribe("checkout_started", async () => {
if (getPostbackURL()) {
navigator.sendBeacon(getPostbackURL()+'&et=begin_checkout');
}
});
analytics.subscribe("checkout_completed", async (event) => {
if (getPostbackURL()) {
const checkout = event.data.checkout,
totalPrice = checkout.totalPrice.amount,
priceCurrency = checkout.totalPrice.currencyCode,
orderId = checkout.order.id;
navigator.sendBeacon(getPostbackURL()+'&et=purchase&payout='+totalPrice+'&currency='+priceCurrency+'&txid='+orderId);
}
});
@zionskynet

zionskynet commented Aug 23, 2025

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment