Skip to content

Commit

Permalink
fix(usersnap): SKFP-914 catch error on load
Browse files Browse the repository at this point in the history
  • Loading branch information
GaelleA committed Jan 23, 2024
1 parent d2a142b commit 3b044cf
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/services/initUsersnap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EnvVariables from "helpers/EnvVariables";
import EnvVariables from 'helpers/EnvVariables';

declare global {
interface Window {
Expand All @@ -7,7 +7,7 @@ declare global {
}

export const initUserSnap = () => {
const apiKey = EnvVariables.configFor("USER_SNAP_API_KEY");
const apiKey = EnvVariables.configFor('USER_SNAP_API_KEY');

if (!apiKey) {
return;
Expand All @@ -17,8 +17,19 @@ export const initUserSnap = () => {
api.init();
};

const script = document.createElement("script");
script.async = true;
script.src = `https://widget.usersnap.com/load/${apiKey}?onload=onUsersnapCXLoad`;
document.head.append(script);
fetch(`https://widget.usersnap.com/load/${apiKey}?onload=onUsersnapCXLoad`, {
body: null,
method: 'GET',
mode: 'cors',
credentials: 'omit',
})
.then(() => {
const script = document.createElement('script');
script.async = true;
script.src = `https://widget.usersnap.com/load/${apiKey}?onload=onUsersnapCXLoad`;
document.head.append(script);
})
.catch((error: any) => {
console.log(error.message);
});
};

0 comments on commit 3b044cf

Please sign in to comment.