How to exclude development sessions from Clarity recordings? I couldn't find any options in their settings. Also, is it possible to restrict session recordings to certain countries?
How to exclude localhost session recordings on Microsoft Clarity?
1.8k Views Asked by Harsha N Hegde AtThere are 3 best solutions below
On
I have since switched to using Google Tag Manager for managing all the tags. GTM has an option to fire a tag based on hostname pattern match. I have set all tags to fire on production host only.
On
To exclude localhost on Clarity, you can use a Segment.
First click Filter, then look for the path section Create a path match using a regular expression (regex). You can use a Regex with a negative lookup.
After this you can save this filter as a segment for future use
Here is the regex
^(?!.*localhost).*
Explanation:
^ Asserts the start of the line.
(?!.*localhost) is a negative lookahead that asserts that what immediately follows the current position in the string isn't localhost. If localhost is found, the regex will fail.
.* matches any character (except for a newline) 0 or more times.
This will match any string that does not contain the word "localhost".


The easiest way is to not include the script on localhost with a simple check on the current hostname:
Full snippet like this:
(Replace XXXXX with your key/code from clarity)