diff --git a/packages/analytics-js-integrations/src/integrations/MicrosoftClarity/browser.js b/packages/analytics-js-integrations/src/integrations/MicrosoftClarity/browser.js index 68dced8b8..b1196853e 100644 --- a/packages/analytics-js-integrations/src/integrations/MicrosoftClarity/browser.js +++ b/packages/analytics-js-integrations/src/integrations/MicrosoftClarity/browser.js @@ -33,7 +33,7 @@ class MicrosoftClarity { } isLoaded() { - return !!window.clarity; + return !!window.clarity && window.clarity('identify') instanceof Promise; } isReady() { @@ -55,14 +55,17 @@ class MicrosoftClarity { if (context?.traits?.customPageId) { customPageId = context.traits.customPageId; } - window.clarity('identify', userId, sessionId, customPageId); - if (context?.traits) { - const { traits } = context; - const keys = Object.keys(traits); - keys.forEach(key => { - window.clarity('set', key, traits[key]); - }); - } + window.clarity('identify', userId, sessionId, customPageId).then(() => { + if (context?.traits) { + const { traits } = context; + const keys = Object.keys(traits); + keys.forEach(key => { + window.clarity('set', key, traits[key]); + }); + } + }).catch(error => { + logger.error('[MicrosoftClarity] Error in identify call', error); + }); } }