Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: microsoft clarity load and handle promise for identify #1964

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
}

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

isReady() {
Expand All @@ -55,14 +56,17 @@
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 59 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#L59

Added line #L59 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 64 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#L61-L64

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

Check warning on line 68 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#L68

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

Expand Down
Loading