# Microsoft Advertising UET Tag

> Adds the Microsoft Advertising (Bing Ads) Universal Event Tracking tag to every public page for conversion tracking and remarketing.

- Type: PHP
- Runs: Frontend only
- Category: [Analytics & Tracking](https://wpide.com/library/category/analytics/)
- Tags: microsoft-ads, bing, uet, conversion
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/analytics-microsoft-uet/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Microsoft Advertising UET Tag" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
