How to add Microsoft Clarity tracking for a new website

🧩 1. Create a Microsoft Clarity Project

  1. Go to https://clarity.microsoft.com and sign in with your Microsoft, Google, or Facebook account.
  2. Click “Add new project.”
  3. Enter:
    • Project name – something descriptive like ClientName – Website 2025
    • Website URL – your domain, e.g. https://example.com
    • Site category – pick the industry that fits best.
  4. Click Create.

📜 2. Get Your Tracking Code

Once the project is created:

  1. Clarity will display a tracking code snippet (JavaScript).
  2. Copy it – it 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-CLARITY-ID"); </script>

⚙️ 3. Install Clarity on Your Website

🔸 If the site is built with WordPress

  • Option A – use a plugin
    1. Install the free Microsoft Clarity plugin.
    2. Paste your Clarity Project ID (the short alphanumeric string from the snippet) in the plugin’s settings.
    3. Save and clear cache.
  • Option B – manual installation
    1. Open your theme’s header.php file or insert the code via a header/footer manager (e.g., Insert Headers and Footers plugin).
    2. Paste the script just before the closing </head> tag.
    3. Save and clear cache.

🔸 If the site is built with Shopify

  1. In your Shopify admin, go to Online Store › Themes › Edit code.
  2. Open theme.liquid and paste the code before </head>.
  3. Save.

🔸 If it’s a custom build (React, Next.js, etc.)

  • Add the script tag to your layout or <Head> component (e.g., _app.js or _document.js for Next.js).
  • Or inject it via your Tag Manager.

🧠 4. (Optional) Integrate with Google Analytics

To combine behavior insights:

  1. In Clarity, go to Settings › Setup › Google Analytics.
  2. Connect the same GA property.
  3. Clarity will then push session IDs into GA for richer reporting.

🕵️‍♂️ 5. Verify Installation

  • Visit your site and interact for 1-2 minutes.
  • Return to Clarity › Dashboard › you should soon see active sessions appear (can take up to 2 hours).
  • You’ll then be able to watch recordings, heatmaps, rage clicks, and scroll depth.

💡 Pro Tips

  • Filter internal traffic: exclude your agency’s IP under Settings › Masking & Filters.
  • Use tags: label recordings (e.g., “Contact Form Submit,” “Pricing Page View”).
  • Combine with Hotjar or GA4 for conversion analysis.
  • Test on staging before deploying live to ensure it doesn’t conflict with other scripts.