Install or Embed Microsoft Clarity Tag or SDK
Overview
Installing Microsoft Clarity is straightforward: add a JavaScript snippet to your website's <head> section, and you're done. This guide covers installation methods for every major platform, from manual HTML to WordPress, Shopify, and everything in between.
Choose the method that matches your tech stack and follow the step-by-step instructions.
Prerequisites
Before installing, ensure you have:
- Microsoft Clarity account – Sign up at https://clarity.microsoft.com/
- Clarity project created – Each website gets its own project
- Project ID and tracking code – Found in Clarity dashboard under Settings > Setup
- Website access – Ability to edit HTML or install plugins
Getting Your Tracking Code
- Log into Clarity dashboard at https://clarity.microsoft.com/
- Select your project (or create a new one)
- Go to Settings > Setup
- Copy the entire tracking code block
Your tracking code looks like this:
<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", "YOUR_PROJECT_ID");
</script>
Note: YOUR_PROJECT_ID will be replaced with your actual project ID.
Installation Methods
Manual HTML Installation
Best for: Static HTML sites, custom applications, developers with direct code access
Step-by-Step Instructions
Open your website's HTML template or main layout file
- Look for files like
index.html,header.php,layout.html,app.html - You want the file that's included on every page
- Look for files like
Locate the
<head>section<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Your Website</title> <!-- Other head content -->Paste the Clarity tracking code just before the closing
</head>tag<head> <meta charset="UTF-8"> <title>Your Website</title> <!-- Other head content --> <!-- Microsoft Clarity --> <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", "YOUR_PROJECT_ID"); </script> </head>Save the file and deploy to your server
Verify installation:
WordPress Installation
Best for: WordPress sites of any size
Method 1: Official Plugin (Recommended)
Install the plugin:
- In WordPress admin, go to Plugins > Add New
- Search for "Microsoft Clarity"
- Install Microsoft Clarity by Microsoft
- Click Activate
Configure the plugin:
- Go to Settings > Clarity
- Paste your Project ID (just the ID, not the full script)
- Click Save Changes
Verify installation:
- Visit your site
- Check page source for
clarity.msscript
Method 2: Insert Headers and Footers Plugin
If the official plugin doesn't work with your theme:
Install Insert Headers and Footers plugin:
- Plugins > Add New > Search "Insert Headers and Footers"
- Install and activate
Add Clarity code:
- Go to Settings > Insert Headers and Footers
- Paste the full Clarity tracking code in Scripts in Header section
- Save
Method 3: Manual Theme Edit
For developers comfortable editing theme files:
Edit theme header:
- Go to Appearance > Theme File Editor
- Select
header.php(orfunctions.phpfor child themes)
Add Clarity code:
- In
header.php: Paste code before</head> - In
functions.php: Usewp_headhook:
function add_clarity_tracking() { ?> <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", "YOUR_PROJECT_ID"); </script> <?php } add_action('wp_head', 'add_clarity_tracking');- In
Save changes
Shopify Installation
Best for: Shopify stores
Method 1: Shopify App (Recommended)
Install the Clarity app:
- Visit Shopify App Store
- Search "Microsoft Clarity"
- Install the official Clarity app
- Authorize the app
Connect your Clarity account:
- Sign into Microsoft Clarity when prompted
- Select the project to link to this store
- Authorize the connection
Verify:
- Visit your store
- Check page source for Clarity script
Method 2: Manual Installation (Theme Edit)
Access theme code:
- In Shopify admin, go to Online Store > Themes
- Click Actions > Edit Code on your active theme
Edit theme.liquid:
- In the left sidebar, click Layout > theme.liquid
- Find the
</head>tag - Paste Clarity tracking code just before it
Save and verify
Google Tag Manager (GTM)
Best for: Teams managing multiple marketing tags, marketers without developer access
Installation Steps
Create a new tag in GTM:
- In GTM workspace, go to Tags > New
- Name the tag: "Microsoft Clarity"
Configure tag:
- Click Tag Configuration
- Select Custom HTML
- Paste your full Clarity tracking code
Set trigger:
- Click Triggering
- Select All Pages (or create custom trigger for specific pages)
Save the tag
Preview and test:
- Click Preview in GTM
- Visit your website in preview mode
- Verify the Clarity tag fires on page load
- Check for errors in GTM debug panel
Publish:
- Click Submit in GTM
- Add version name and description
- Click Publish
Verify:
- Visit your live site
- Check that sessions appear in Clarity dashboard within 15 minutes
Other CMS Platforms
Wix
- Open Wix Editor
- Go to Settings (gear icon on the left) > Custom Code
- Click + Add Custom Code
- Paste Clarity tracking code
- Set:
- Name: Microsoft Clarity
- Add Code to Pages: All pages
- Place Code in: Head
- Code Type: Essential
- Click Apply
- Publish your site
Squarespace
- In Squarespace dashboard, go to Settings > Advanced > Code Injection
- Paste Clarity tracking code in Header section
- Click Save
- Changes apply immediately to your published site
Webflow
- In Webflow project, go to Project Settings > Custom Code
- Paste Clarity code in Head Code section
- Save settings
- Publish your site
- Tracking begins immediately on published domain (not Designer preview)
Wix (Alternative: Tracking & Analytics)
- In Wix dashboard, go to Settings > Tracking & Analytics
- Click + New Tool > Custom
- Paste Clarity code
- Set to load on all pages
- Save and publish
Drupal
- Install "Google Analytics" module (it works for any JS snippet)
- Go to Configuration > System > Google Analytics
- Paste Clarity tracking code in custom code section
- Save configuration
- Clear cache: Configuration > Development > Performance > Clear all caches
Joomla
- Install "Custom HTML" module or edit template directly
- Edit template's
index.phpfile:- Extensions > Templates > Templates
- Select your active template
- Edit
index.php - Paste Clarity code before
</head>
- Save and clear cache
Ghost
- In Ghost admin, go to Settings > Code Injection
- Paste Clarity tracking code in Site Header section
- Save
- Clarity tracks immediately on your live site
Magento
- Go to Content > Configuration
- Select your store view
- Expand HTML Head section
- Paste Clarity code in Scripts and Style Sheets field
- Save configuration
- Clear cache: System > Cache Management > Flush Magento Cache
BigCommerce
- Go to Storefront > Script Manager
- Click Create a Script
- Configure:
- Name: Microsoft Clarity
- Description: Behavior analytics
- Location: Head
- Script type: Script
- Script: Paste Clarity tracking code
- Pages: All Pages
- Save
Single Page Applications (SPAs)
React
Option 1: Add to public/index.html
<!-- public/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>React App</title>
<!-- Microsoft Clarity -->
<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", "YOUR_PROJECT_ID");
</script>
</head>
<body>
<div id="root"></div>
</body>
</html>
Option 2: Load programmatically in App.js
// src/App.js
import { useEffect } from 'react';
function App() {
useEffect(() => {
// Load Clarity
(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", "YOUR_PROJECT_ID");
}, []);
return <div>Your app content</div>;
}
Vue.js
Add to public/index.html:
<!-- public/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vue App</title>
<!-- Microsoft Clarity -->
<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", "YOUR_PROJECT_ID");
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
Angular
Add to src/index.html:
<!-- src/index.html -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Angular App</title>
<base href="/">
<!-- Microsoft Clarity -->
<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", "YOUR_PROJECT_ID");
</script>
</head>
<body>
<app-root></app-root>
</body>
</html>
Next.js
Add to pages/_document.js:
// pages/_document.js
import { Html, Head, Main, NextScript } from 'next/document';
export default function Document() {
return (
<Html>
<Head>
{/* Microsoft Clarity */}
<script
type="text/javascript"
dangerouslySetInnerHTML={{
__html: `
(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", "YOUR_PROJECT_ID");
`,
}}
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
Verification Steps
After installation, verify Clarity is working:
1. Check Page Source
- Visit your website
- Right-click > View Page Source
- Search (Ctrl+F / Cmd+F) for "clarity.ms"
- Confirm the script appears in the
<head>section
2. Check Browser Console
- Open DevTools (F12)
- Go to Console tab
- No Clarity-related errors should appear
3. Check Network Requests
- Open DevTools > Network tab
- Reload the page
- Filter by "clarity"
- You should see:
https://www.clarity.ms/tag/YOUR_PROJECT_ID(script load)https://www.clarity.ms/collect(data collection)
4. Check Clarity Dashboard
- Return to Clarity dashboard
- Go to Dashboard or Recordings
- Within 5-15 minutes, sessions should appear
- Click on a recording and verify:
- Layout renders correctly
- Clicks are captured
- No visual glitches
Troubleshooting
Script Not Appearing in Page Source
Possible Causes:
- Code not saved properly
- Cache not cleared
- Code added to wrong template file
Solutions:
- Double-check file was saved
- Clear browser cache (Ctrl+Shift+R)
- Clear CDN/server cache
- Verify editing the correct template (main layout, not a single page)
No Data in Clarity Dashboard
Possible Causes:
- Wrong Project ID in code
- Ad blockers preventing tracking
- CSP headers blocking script
Solutions:
- Verify Project ID matches dashboard
- Test in incognito mode without extensions
- Update CSP headers to allow
clarity.ms - See Troubleshooting Guide for detailed fixes
Recordings Show Broken Layout
Possible Causes:
Solutions:
- Add CORS headers to CSS files
- Host CSS on same domain as site
- Accept that Shadow DOM elements may not render perfectly
Best Practices
✅ Do:
- Place Clarity code in the
<head>section - Use the official async tracking code from Clarity dashboard
- Test in staging before production deployment
- Verify recordings look correct after installation
- Document where and how you installed Clarity
❌ Don't:
- Place code at the end of
<body>(loads too late) - Manually create the script tag (breaks async loading)
- Install on development environments that aren't publicly accessible
- Forget to verify data is flowing to Clarity dashboard
Next Steps
After installation:
- Configure privacy settings: Setup Guide
- Set up custom events: Event Tracking
- Integrate with Google Analytics: Integrations Guide
- Review first recordings: Learn what users are actually experiencing
Additional Resources: