Microsoft Clarity
repository·master·Indexed 25 days ago
https://github.com/microsoft/clarityAn open-source behavioral analytics library focused on privacy and performance. It includes clarity-js for website instrumentation, clarity-decode for transforming telemetry payloads into human-readable formats, clarity-visualize for rendering session replays, and clarity-devtools, a Chromium-based browser extension for live captures.
What's inside microsoft-clarity
- Clarity is an open-source behavioral analytics library written in TypeScript. It is designed with a focus on privacy and performance to help developers understand how users navigate, interact, and browse websites across modern devices and browsers. It uses the same codebase that powers Microsoft's hosted behavioral analytics solution.
Overview of clarity-decode
masterTheclarity-decodepackage is a utility designed to decode telemetry payloads generated byclarity-js. It takes the encoded input payload and transforms it back into its original, human-readable format, allowing for the analysis of user behavior captured by the Clarity library.Overview of Clarity packages
masterClarity is an open-source behavioral analytics library focused on privacy and performance. The project is divided into several specialized packages depending on your use case:
- clarity-js: Instrumentation code for websites to track user interactions and layout changes.
- clarity-decode: Server-side code used to decode incoming telemetry data back into its original format.
- clarity-visualize: Converts decoded data into pixel-perfect session replays.
- clarity-devtools: A Chromium-based browser extension for generating live captures on any website.
Overview of clarity-visualize
masterTheclarity-visualizepackage is responsible for taking decoded telemetry data (produced byclarity-decode) and rendering it into pixel-perfect session replays. It allows developers to see exactly how users interacted with a website across modern devices and browsers, providing insights into navigation and feature performance.Privacy and Data Masking in Clarity
masterClarity is designed to handle sensitive data with care. By default, sensitive content on a webpage is masked before it is uploaded to the server to ensure user privacy.Understand Clarity Developer Tools data collection and privacy
masterClarity Developer Tools follows these data collection principles:
- Triggered Instrumentation: The extension only begins instrumenting a website after you explicitly open the browser developer tools and click on the
Claritytab. - Local Data: All data captured by the extension remains on your local device and is not uploaded to any external servers.
- Triggered Instrumentation: The extension only begins instrumenting a website after you explicitly open the browser developer tools and click on the
Build the Clarity Developer Tools extension
masterTo build the Clarity Developer Tools extension, ensure your development environment is set up according to the project's contribution guidelines. Run the build command from the root of the repository. The resulting extension files will be located in the
extensionfolder.yarn buildInstall and use the Clarity Developer Tools extension
masterFollow these steps to load the unpacked extension into your browser and use it for live session replays:
- Open your browser's extensions page (e.g.,
edge://extensionsorchrome://extensions). - Enable Developer mode.
- Click on Load unpacked.
- Select the
extensionfolder generated by the build process. - Navigate to any website.
- Open the browser's Developer Tools (F12).
- Click on the Clarity tab to see the live replay in action.
- Open your browser's extensions page (e.g.,
Setup Git MCP Server for Claude Code
masterIf you are using Claude Code for development, you can enable the Git MCP (Model Context Protocol) server to perform enhanced Git operations via natural language.
Prerequisites
- Ensure Python 3 is installed:
python3 --version - Install the Git MCP Server using pip:
pip3 install mcp-server-git
Enable the Server
You can enable the server in two ways:
Option 1: Auto-enable (Recommended) Add the following to your
.claude/settings.local.jsonfile:{ "enableAllProjectMcpServers": true }Option 2: Explicit approval Claude Code will prompt you to approve the MCP server upon its first use.
pip3 install mcp-server-git- Ensure Python 3 is installed:
Configure the Clarity JS client via the Config interface
masterTheConfiginterface defines the settings for the Clarity JavaScript integration. Use these properties to control data collection, privacy masking, and reporting behavior.Configure the Visualizer via Options
masterWhen calling
setup(target, options), use theOptionsinterface to configure the playback environment. Key options include:version: (string) The version of Clarity being used.dom:Layout.DomEvent- Initial DOM state.onresize:ResizeHandler- Callback when the container resizes.logerror:ErrorLogger- Callback for error reporting.useproxy:LinkHandler- Function to handle link proxying.onclickMismatch:ClickLogger- Callback for click mismatches.onalphafallback:AlphaFallbackLogger- Callback when the Alpha selector is used as a fallback.pointer:boolean- Enable pointer visualization.canvas:boolean- Use canvas for rendering.keyframes:boolean- Enable keyframes.mobile:boolean- Simulate mobile view.locale:string- Set the locale.
Configure Playwright projects for Clarity packages and E2E tests
masterThe Playwright configuration dynamically generates test projects based on the contents of the
packagesdirectory.- Package Projects: For every directory in
packages/that contains both atestdirectory and apackage.json, a project is created with the package name as thenameand thetestdirectory as thetestDir. - E2E Project: A manual project named
e2eis defined to run tests located in the roottestdirectory using thechromiumbrowser.
To add a new project, ensure it follows the directory structure expected by the dynamic mapper or add it explicitly to the
projectsarray.- Package Projects: For every directory in