WordPress Help Articles

MS Clarity Exclude Logged In Users

MS Clarity Exclude Logged In Users

How to Use

Download > Install > Activate. Use your favorite IDE or just edit within the WordPress plugin editor. Change “xxxxxxxxxx” to be your Clarity ID.

Not associated with Microsoft® Clarity®

Example

This prevents me from recording my logged in, back-end work. Prevents script from executing while logged in as Author or above so it will still run for WooCommerce customers.

Source

This code can be pasted into the functions.php file of your child theme or, download and install the plugin for simple code activation.

function viawebs_plugins_clarity_exclude_logged_in(){
    if ( ! current_user_can( 'edit_posts' ) ) {
        ?>
    
<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"); // <--- add the site id here
</script>

    <?php
    }
}
add_action( 'wp_head', 'viawebs_plugins_clarity_exclude_logged_in' );

Via Webs Offers Wordpress Hosting & Maintenance Services For Those That Prefer To Focus On Something Other Than The Technical Aspects

Our rollover development time lets you save unused hours for future assistance. Stay updated and optimized, with the flexibility to invest in new functionality.

Browse Our Most Recent Plugins

You never know what you might be able to use.

Article Categories

Dive in to something specific you are wanting to learn more about.

Let's Get Started!