Introduction
Microsoft Clarity can analyze user behavior on websites, and this site has also integrated it.
Personally, I find it quite useful. You can check the website's traffic whenever you have free time.
It's also very simple to use - just add the line of code provided by the dashboard into the <head> tag.

However, many ad blocker rules will block Clarity's domain, resulting in missing user connection information. This can be avoided by using nginx reverse proxy to your own domain. Here are the specific steps for your reference.
Analyzing Requests
Below is an example of code added in the <head> tag.
Or you can open the browser's developer tools to capture packets and see that the relevant code will first request https://www.clarity.ms/tag/abcdefg , which downloads a JavaScript script:
There are 3 links in it:
- https://c.clarity.ms/c.gif
- https://www.clarity.ms/s/0.8.13-beta/clarity.js
- https://z.clarity.ms/collect
These links need to be replaced one by one.
Replacing Links and Setting Up Reverse Proxy
Assuming your domain is example.com, you can create a subdomain clarity.example.com and point it to a public nginx server.
At this point, you can save the script requested from https://www.clarity.ms/tag/abcdefg to /var/www/html/tag/abcdefg.
Then replace the 3 links above as follows:
- https://clarity.example.com/c.gif
- https://clarity.example.com/s/0.8.13-beta/clarity.js
- https://clarity.example.com/collect
After that, you also need to download https://www.clarity.ms/s/0.8.13-beta/clarity.js to /var/www/html/s/0.8.13-beta/clarity.js. The version may be different when you read this, so just modify accordingly. The /var/www/html directory above can also be changed, but pay attention to permissions to ensure the nginx process can access it. The directory structure is as follows:
nginx reverse proxy configuration reference:
Reconfiguring the Website
Replace www.clarity.ms in the script originally added to your website's <head> with clarity.example.com. That's it! Try visiting your website and check if there are real-time online users in the dashboard!
Drawbacks
- The drawback after doing this is that the dashboard will show all visits as coming from the nginx server's location. It would be great if Microsoft could determine geographic location from request headers.
- It cannot automatically follow Microsoft's
clarity.jsupgrades, but you can write a script to automate it. Reference code: