From 3b044cf78f5678ffaedf0731933d4f5ebcec1bb8 Mon Sep 17 00:00:00 2001 From: GaelleA Date: Tue, 23 Jan 2024 10:23:18 -0500 Subject: [PATCH] fix(usersnap): SKFP-914 catch error on load --- src/services/initUsersnap.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/services/initUsersnap.ts b/src/services/initUsersnap.ts index 4a00796ff..d677380fc 100644 --- a/src/services/initUsersnap.ts +++ b/src/services/initUsersnap.ts @@ -1,4 +1,4 @@ -import EnvVariables from "helpers/EnvVariables"; +import EnvVariables from 'helpers/EnvVariables'; declare global { interface Window { @@ -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; @@ -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); + }); };