Microsoft Advertising UET Tag
Adds the Microsoft Advertising (Bing Ads) Universal Event Tracking tag to every public page for conversion tracking and remarketing.
Opens WPIDE on
Code
add_action( 'wp_head', function () {
$tag_id = '00000000'; // UET tag ID.
$require_consent = false; // true: wait for consent from the WPIDE cookie banner.
if ( '00000000' === $tag_id || current_user_can( 'edit_posts' ) ) {
return;
}
?>
<script>
(function (run) {
if (!<?php echo $require_consent ? 'true' : 'false'; ?> || /(?:^|; )wpide_consent=granted/.test(document.cookie)) { run(); return; }
document.addEventListener('wpide:consent', function (e) { if (e.detail === 'granted') { run(); } });
})(function () {
window.uetq = window.uetq || [];
var s = document.createElement('script');
s.async = true;
s.src = 'https://bat.bing.com/bat.js';
s.onload = function () {
if (typeof UET !== 'function') { return; }
var options = { ti: <?php echo wp_json_encode( $tag_id ); ?>, enableAutoSpaTracking: true, q: window.uetq };
window.uetq = new UET(options);
window.uetq.push('pageLoad');
};
document.head.appendChild(s);
});
</script>
<?php
} );
Notes
Replace 00000000 with your UET tag ID from Microsoft Advertising > Tools > UET tag. Nothing is output while the placeholder is in place.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.