Skip to content

Commit

Permalink
fix: microsoft clarity load and handle promise for identify (#1964)
Browse files Browse the repository at this point in the history
* fix: microsoft clarity load and handle promise for identify

* fix: loading logic

* fix: send set calls to clarity while identify is called before load

* fix: error handling

* chore: address review comments

---------

Co-authored-by: Sai Sankeerth <[email protected]>
  • Loading branch information
sanpj2292 and Sai Sankeerth authored Dec 26, 2024
1 parent 3cd77a1 commit 11e890e
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class MicrosoftClarity {
}

isLoaded() {
return !!window.clarity;
// queue would be undefined if the Clarity script is loaded
return !!window.clarity && !window.clarity.q;
}

isReady() {
Expand All @@ -55,7 +56,13 @@ class MicrosoftClarity {
if (context?.traits?.customPageId) {
customPageId = context.traits.customPageId;
}
window.clarity('identify', userId, sessionId, customPageId);

const identifyPromise = window.clarity('identify', userId, sessionId, customPageId);
if (typeof identifyPromise?.then === 'function') { // Clarity SDK is ready
identifyPromise.catch(error => {
logger.error('The "identify" promise was rejected', error);
});
}
if (context?.traits) {
const { traits } = context;
const keys = Object.keys(traits);
Expand Down

0 comments on commit 11e890e

Please sign in to comment.