A Bundle of Love - Get one year of Dynamic Shortcodes + Code Snippets Pro - for just $39
View Offer
A Bundle of Love - Get one year of Dynamic Shortcodes + Code Snippets Pro - for just $39
View Offer

How to add Microsoft Clarity tracking code

If you want to add Microsoft Clarity tracking to your site, you will be asked to add some code to your site’s  <head> tag.

The easiest way to do this is add a snippet that hooks to the wp_head action. Here’s an example:

add_action( 'wp_head', function () { ?>

<script type="text/javascript">
    (function(c,l,a,r,i,t,y){
        c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
        t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
        y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
    })(window, document, "clarity", "script", "XXXXXXXXXX");
</script>

<?php } );

Remember to replace XXXXXXXXXX in the code above with your actual project ID.

Related Articles