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' );