If you are using Bing/Microsoft Advertising you may have been asked to ensure your site is UET for Consent Mode compliant.

What is Microsoft UET?

Microsoft Universal Event Tracking (UET) helps track conversions and build remarketing audiences in your Microsoft Ads campaigns. It works by placing a lightweight JavaScript snippet on your site, similar to Google Ads tags.

Why Consent Mode Matters

Under GDPR and privacy laws, you must respect user cookie preferences before tracking for advertising or analytics. Consent Mode allows UET to adjust its behavior based on user consent:

  • Consent given: UET tracks conversions and remarketing fully.

  • Consent denied: UET sends cookieless pings to maintain limited measurement without cookies.

This keeps you compliant while retaining valuable ad insights.

Using BigCommerce’s Native Cookie for Consent

BigCommerce automatically sets a cookie named:

bc_consent

Looking at the value of the 'bc_consent' cookie, the default value is 'deny':

%7B%22allow%22%3A%5B%5D%2C%22deny%22%3A%5B2%2C3%2C4%5D%7D

That string is a little tricky to understand, so lets have a look at it when it is URL-Decoded:

{"allow":[],"deny":[2,3,4]}

After Consent is given the cookie value is updated to something like this:

%7B%22allow%22%3A%5B2%2C3%2C4%5D%2C%22deny%22%3A%5B%5D%7D

When URL-decoded it looks like this:

{"allow":[2,3,4],"deny":[]}

Based on this information we can control the output of the Conset Mode code.

Code to use

Add the following code to Storefront > Script Manager > Create Script. Enter something like 'UET Consent - Dynamic' for the Script Name. Select the Placement you prefer. Location is 'All Pages'. The Script Category is 'Essential' and Script Type is 'Script'.

Make sure you include the opening and closing <SCRIPT> tags around the code.




// Global variable to track current consent state
let currentConsentState = null;

function checkConsentAndUpdateUET() {
    // Function to get cookie value by name
    function getCookie(name) {
        const value = `; ${document.cookie}`;
        const parts = value.split(`; ${name}=`);
        if (parts.length === 2) return parts.pop().split(';').shift();
        return null;
    }
    
    // Function to update UET consent (no script creation needed after initial load)
    function updateUETConsent(consentType, consentValue) {
        // Initialize UET queue if not already done
        window.uetq = window.uetq || [];
        
        // Push the consent update
        window.uetq.push('consent', consentType, {
            'ad_storage': consentValue
        });
        
        console.log(`UET consent updated: ${consentType} - ad_storage: ${consentValue}`);
    }
    
    // Get the bc_consent cookie
    const consentCookie = getCookie('bc_consent');
    
    // Define the expected values
    const grantedValue = '%7B%22allow%22%3A%5B2%2C3%2C4%5D%2C%22deny%22%3A%5B%5D%7D';
    const deniedValue = '%7B%22allow%22%3A%5B%5D%2C%22deny%22%3A%5B2%2C3%2C4%5D%7D';
    
    let newConsentState;
    
    if (consentCookie === grantedValue) {
        newConsentState = 'granted';
    } else if (consentCookie === deniedValue) {
        newConsentState = 'denied';
    } else {
        newConsentState = 'denied'; // Default
    }
    
    // Only update if the consent state has changed
    if (currentConsentState !== newConsentState) {
        currentConsentState = newConsentState;
        
        if (newConsentState === 'granted') {
            updateUETConsent('update', 'granted');
        } else {
            updateUETConsent('update', 'denied'); // Changed from 'default' to 'update' for real-time updates
        }
    }
}

// Function to start monitoring for cookie changes
function startConsentMonitoring() {
    // Initial check
    checkConsentAndUpdateUET();
    
    // Set up polling to check for cookie changes every 1 second
    setInterval(checkConsentAndUpdateUET, 1000);
    
    // Also listen for storage events (though this won't catch same-page cookie changes)
    window.addEventListener('storage', checkConsentAndUpdateUET);
    
    // Listen for focus events in case cookies changed while user was on another tab
    window.addEventListener('focus', checkConsentAndUpdateUET);
}

// Run the monitoring function when the DOM is ready
if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', startConsentMonitoring);
} else {
    startConsentMonitoring();
}


Testing

You can test this by manually changing the bc_consent cookie value in your browser's developer tools, and you should see the consent update in real-time with a console log message.

Conclusion

Adding Microsoft UET Consent Mode with BigCommerce’s native cookie is a fast, privacy-compliant upgrade that preserves your Microsoft Ads measurement while respecting user choices. It keeps your business aligned with evolving privacy regulations without disrupting user experience or requiring complex integrations.