Skip to content

Commit

Permalink
fix: microsoft clarity load and handle promise for identify
Browse files Browse the repository at this point in the history
  • Loading branch information
Sai Sankeerth committed Dec 9, 2024
1 parent f946102 commit 00649a5
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MicrosoftClarity {
}

isLoaded() {
return !!window.clarity;
return !!window.clarity && window.clarity('identify') instanceof Promise;
}

isReady() {
Expand All @@ -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(() => {

Check warning on line 58 in packages/analytics-js-integrations/src/integrations/MicrosoftClarity/browser.js

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js-integrations/src/integrations/MicrosoftClarity/browser.js#L58

Added line #L58 was not covered by tests
if (context?.traits) {
const { traits } = context;
const keys = Object.keys(traits);
keys.forEach(key => {
window.clarity('set', key, traits[key]);

Check warning on line 63 in packages/analytics-js-integrations/src/integrations/MicrosoftClarity/browser.js

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js-integrations/src/integrations/MicrosoftClarity/browser.js#L60-L63

Added lines #L60 - L63 were not covered by tests
});
}
}).catch(error => {
logger.error('[MicrosoftClarity] Error in identify call', error);

Check warning on line 67 in packages/analytics-js-integrations/src/integrations/MicrosoftClarity/browser.js

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js-integrations/src/integrations/MicrosoftClarity/browser.js#L67

Added line #L67 was not covered by tests
});
}
}

Expand Down

0 comments on commit 00649a5

Please sign in to comment.