Microsoft Clarity Integration

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Microsoft Clarity Integration

Microsoft Clarity is a free session recording and heatmap tool. No traffic limits, stores recordings for 90 days, integrates with Google Analytics 4. Works as a replacement for or addition to Hotjar on high-traffic sites.

Installation

Direct insertion:

<!-- Before </head> -->
<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>

Via GTM: Clarity is in GTM's tag gallery as a ready-made tag type — just enter Project ID.

NPM:

npm install clarity-js
import { clarity } from 'clarity-js';
clarity.start({
  projectId: import.meta.env.VITE_CLARITY_PROJECT_ID,
  upload: 'https://m.clarity.ms/collect',
  expire: 365,
  lean: false,
  track: true,
  content: true,
});

Custom Tags

Clarity allows attaching arbitrary metadata to sessions — similar to identify in other systems:

// Set tags — can be called anytime
window.clarity('set', 'user_id', 'usr_12345');
window.clarity('set', 'plan', 'enterprise');
window.clarity('set', 'page_type', 'product_detail');
window.clarity('set', 'ab_variant', 'B');

// Multiple values for one key
window.clarity('set', 'tag', 'vip');
window.clarity('set', 'tag', 'returning');

Tags are available in filters when viewing recordings: "show sessions where plan = enterprise and page_type = checkout".

User Identification

// Link session to user
window.clarity('identify', 'unique_user_id', 'session_custom_id', 'page_custom_id', 'friendly_name');

// Example for authenticated user
window.clarity(
  'identify',
  user.id,                          // unique user ID
  `session_${Date.now()}`,          // optional session ID
  window.location.pathname,          // optional page ID
  user.email                         // display name in interface
);

Custom Events

// Send event with context
window.clarity('event', 'checkout_started');
window.clarity('event', 'form_error', 'phone_field_invalid');
window.clarity('event', 'video_played', 'intro_video');

Events display in the recording timeline — you can jump to the specific moment when an event occurred.

GA4 Integration

In Clarity settings: "Settings → Integrations → Google Analytics" — select the GA4 property. After activation:

  • GA4 gets a custom dimension clarity_session_url with link to Clarity recording
  • In Clarity, filter sessions by GA4 segments
  • Clarity data visible in GA4 via BigQuery export

SPA and Route Tracking

// React Router
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

export function ClarityRouteTracker() {
  const location = useLocation();

  useEffect(() => {
    // Set tag with current route
    window.clarity?.('set', 'page', location.pathname);
    // Notify of page change
    window.clarity?.('event', 'page_change', location.pathname);
  }, [location.pathname]);

  return null;
}

Data Masking

Clarity automatically masks password fields. For others — use attributes:

<!-- Completely hide element from recordings -->
<div data-clarity-mask="True">
    <span>Passport: 4510 123456</span>
</div>

<!-- Allow showing (if parent is masked) -->
<div data-clarity-mask="True">
    <p>Private data</p>
    <button data-clarity-unmask="True">Public button</button>
</div>

Via project settings: "Settings → Masking" — set "Strict" mode, which masks all text and unmask only needed blocks via data-clarity-unmask.

Using Clarity API

Clarity provides REST API for programmatic data access:

# Get metrics for period
curl -X GET \
  'https://www.clarity.ms/api/v1/projects/YOUR_PROJECT_ID/metrics?startDate=2024-01-01&endDate=2024-01-31' \
  -H 'Authorization: Bearer YOUR_API_TOKEN'

Response contains aggregated data: dead clicks, rage clicks, quick backs, scroll depth for each page.

Installation Verification

// In browser console
window.clarity  // should be a function, not undefined

// Check that script loaded
document.querySelector('script[src*="clarity.ms"]')  // not null

// Force state check
window.clarity('upgrade', 'test_check');

In Clarity interface → "Setup" shows status "Recording" with session count for last 24 hours. First recordings appear within minutes of traffic starting.

Timeline

Installation and verification — 30 minutes. Custom tags and identification setup — 2 hours. GA4 integration and masking configuration — 1 more hour.