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

Merged
merged 6 commits into from
Dec 26, 2024
Merged
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,7 +56,13 @@
if (context?.traits?.customPageId) {
customPageId = context.traits.customPageId;
}
window.clarity('identify', userId, sessionId, customPageId);

const identifyPromise = window.clarity('identify', userId, sessionId, customPageId);

Check warning on line 60 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

Added line #L60 was not covered by tests
if (typeof identifyPromise?.then === 'function') { // Clarity SDK is ready
sanpj2292 marked this conversation as resolved.
Show resolved Hide resolved
identifyPromise.catch(error => {
logger.error('The "identify" promise was rejected', error);

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#L62-L63

Added lines #L62 - L63 were not covered by tests
});
}
if (context?.traits) {
const { traits } = context;
const keys = Object.keys(traits);
Expand Down
Loading