How to implement UET Microsoft consent mode in the checkout
This guide will help you enable Microsoft Consent Mode in the checkout, so that you can track your checkout events with user consent.
You need to have Microsoft consent mode implemented on your store, if you sell to the EU and track users from the EEA. Microsoft is even disabling campaigns that are not following this new standard.
While Pandectes GDPR offers a direct integration for Microsoft Consent Mode, as you know checkout extensibility does not allow for app scripts to run on it.
So, the custom pixel below will allow you to send consent to microsoft and track the purchase event in the checkout with consent!
In essence, the Pandectes integration and the Pixel work in tandem: The integration covers the entire store, while the Pixel handles the checkout.
Go to the Shopify Settings > Customer Events. Then click on "Add Custom pixel"

Give it a nice name and click "Add pixel"

Set the permission to "Not required"

And paste the below code in the code section:
You need to Add your UET tag id at the top, so that the events are sent to your tag, and click Connect.

And you are ready! Now, the pixel will read the pandectes cookie to know what the consent state is, update microsoft about it, and track the event!
Purpose
You need to have Microsoft consent mode implemented on your store, if you sell to the EU and track users from the EEA. Microsoft is even disabling campaigns that are not following this new standard.
How it works with our integration
While Pandectes GDPR offers a direct integration for Microsoft Consent Mode, as you know checkout extensibility does not allow for app scripts to run on it.
So, the custom pixel below will allow you to send consent to microsoft and track the purchase event in the checkout with consent!
In essence, the Pandectes integration and the Pixel work in tandem: The integration covers the entire store, while the Pixel handles the checkout.
Integrating:
Go to the Shopify Settings > Customer Events. Then click on "Add Custom pixel"

Give it a nice name and click "Add pixel"

Set the permission to "Not required"

And paste the below code in the code section:
// Pandectes Pixel for Microsoft UET consent mode and events tracking
const uetTagId = '' // Input your UET tag Id
const DENIED = "denied"
const GRANTED = "granted"
const STORE_POLICY = DENIED; // You can change to GRANTED if you would like to have a loose policy
const getCookie = (cookieName) => {
const cookieString = document.cookie;
const cookieStart = cookieString.indexOf(cookieName + "=");
if (cookieStart === -1) {
return null;
}
let cookieEnd = cookieString.indexOf(";", cookieStart);
if (cookieEnd === -1) {
cookieEnd = cookieString.length;
}
const cookieValue = cookieString.substring(cookieStart + cookieName.length + 1, cookieEnd);
try {
const decodedValue = atob(cookieValue);
const parsedValue = JSON.parse(decodedValue);
return parsedValue;
} catch (error) {
console.error("Error parsing cookie value:", error);
return null;
}
};
function setCookie(name, value, days) {
const date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
const expires = 'expires=' + date.toUTCString();
document.cookie = `${name}=${value}; ${expires}; path=/; secure; samesite=strict`;
}
const getStorage = (preferences) => {
const p4 = (preferences &4) === 0;
output = {
ad_storage: p4 ? GRANTED : DENIED
}
return output;
}
if (window.location.href.includes("/checkout/") ||window.location.href.includes("/checkouts/")){
window.uetq = window.uetq || [];
const cookie = getCookie("_pandectes_gdpr");
const defaultStorage = getStorage(STORE_POLICY === DENIED ? 7:0);
STORE_POLICY===DENIED ? setCookie('_uetmsdns', '1', 365) : setCookie('_uetmsdns', '0', 365);
window.uetq.push('consent', 'default', defaultStorage);
if (cookie && cookie.preferences !== null && cookie.preferences !== undefined) {
const updateStorage = getStorage(cookie.preferences);
window.uetq.push('consent', 'update', updateStorage);
if (updateStorage.ad_storage==GRANTED) {
setCookie('_uetmsdns', '0', 365);
}
}
/*
* UET tag Initialization
*/
(function(w,d,t,r,u){var f,n,i;w[u]=w[u]||[],f=function(){var o={ti:uetTagId, disableAutoPageView: true, enableAutoSpaTracking: false};o.q=w[u],w[u]=new UET(o),w[u].push("pageLoad")},n=d.createElement(t),n.src=r,n.async=1,n.onload=n.onreadystatechange=function(){var s=this.readyState;s&&s!=="loaded"&&s!=="complete"||(f(),n.onload=n.onreadystatechange=null)},i=d.getElementsByTagName(t)[0],i.parentNode.insertBefore(n,i)})(window,document,"script","//bat.bing.com/bat.js","uetq");
/*
* Events Tracking
*/
analytics.subscribe("page_viewed", (event) => {
window.uetq.push('event', 'page_view', { 'page_location': event.context.window.location.href });
});
analytics.subscribe("checkout_completed", event => {
let productIds = '';
let revenueValue = 0;
let currency = '';
if (event.data?.checkout) {
revenueValue = event.data.checkout.totalPrice?.amount;
currency = event.data.checkout.totalPrice?.currencyCode;
if (Array.isArray(event.data?.checkout?.lineItems)) {
const lineItemIds = event.data.checkout.lineItems.map(item => String(item.variant.product.id));
productIds = lineItemIds.join(',').slice(0, 50);
}
window.uetq.push('event', 'purchase', {
'ecomm_prodid': productIds,
'ecomm_pagetype': 'purchase',
'revenue_value': revenueValue,
'currency': currency
});
}
});
}
You need to Add your UET tag id at the top, so that the events are sent to your tag, and click Connect.

And you are ready! Now, the pixel will read the pandectes cookie to know what the consent state is, update microsoft about it, and track the event!
Updated on: 25/04/2025
Thank you!