From 65dc507c6a75f0939d346ac8c117f29f5643fe65 Mon Sep 17 00:00:00 2001 From: Ian <> Date: Fri, 8 Nov 2024 12:16:54 -0600 Subject: [PATCH 1/6] Load GetFeedback script --- scripts/delayed.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/scripts/delayed.js b/scripts/delayed.js index 10feab1..e3500c3 100644 --- a/scripts/delayed.js +++ b/scripts/delayed.js @@ -6,6 +6,28 @@ sampleRUM('cwv'); // add more delayed functionality here +async function loadBodyScript(src, attrs) { + return new Promise((resolve, reject) => { + if (!document.querySelector(`body > script[src="${src}"]`)) { + const script = document.createElement('script'); + script.text = src; + if (attrs) { + // eslint-disable-next-line no-restricted-syntax, guard-for-in + for (const attr in attrs) { + script.setAttribute(attr, attrs[attr]); + } + } + script.onload = resolve; + script.onerror = reject; + document.body.append(script); + } else { + resolve(); + } + }); +} + + + async function loadAdobeLaunch() { const adobedtmSrc = 'https://assets.adobedtm.com/9273d4aedcd2/6eb97addd328/launch-1dd947b3f935.min.js'; @@ -26,9 +48,17 @@ async function loadGA() { window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', gaId); } +async function loadGetFeedback() { + const src = 'console.log("Load GetFeedback");'; + await loadBodyScript(src, { + type: 'text/javascript', + }); +} + store.emit('delayed:loaded'); loadCSS(`${window.hlx.codeBasePath}/styles/icons.css`); loadAdobeLaunch(); loadGA(); +loadGetFeedback(); From f77704cd379b54d9a5029ce82859b3cbecd55142 Mon Sep 17 00:00:00 2001 From: Ian <> Date: Fri, 8 Nov 2024 12:19:52 -0600 Subject: [PATCH 2/6] Fix lint error: multiple empty lines --- scripts/delayed.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/delayed.js b/scripts/delayed.js index e3500c3..6c9eaf8 100644 --- a/scripts/delayed.js +++ b/scripts/delayed.js @@ -26,8 +26,6 @@ async function loadBodyScript(src, attrs) { }); } - - async function loadAdobeLaunch() { const adobedtmSrc = 'https://assets.adobedtm.com/9273d4aedcd2/6eb97addd328/launch-1dd947b3f935.min.js'; From e41c9bf172b5e9e2e5e5f21080f801b87d00e70b Mon Sep 17 00:00:00 2001 From: Ian <> Date: Fri, 8 Nov 2024 12:26:34 -0600 Subject: [PATCH 3/6] Simply load code --- scripts/delayed.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/scripts/delayed.js b/scripts/delayed.js index 6c9eaf8..992d2e0 100644 --- a/scripts/delayed.js +++ b/scripts/delayed.js @@ -8,21 +8,17 @@ sampleRUM('cwv'); async function loadBodyScript(src, attrs) { return new Promise((resolve, reject) => { - if (!document.querySelector(`body > script[src="${src}"]`)) { - const script = document.createElement('script'); - script.text = src; - if (attrs) { - // eslint-disable-next-line no-restricted-syntax, guard-for-in - for (const attr in attrs) { - script.setAttribute(attr, attrs[attr]); - } + const script = document.createElement('script'); + script.text = src; + if (attrs) { + // eslint-disable-next-line no-restricted-syntax, guard-for-in + for (const attr in attrs) { + script.setAttribute(attr, attrs[attr]); } - script.onload = resolve; - script.onerror = reject; - document.body.append(script); - } else { - resolve(); } + script.onload = resolve; + script.onerror = reject; + document.body.append(script); }); } From e9d6a0cfde031ad5f5b8b544cac1f760c4e31403 Mon Sep 17 00:00:00 2001 From: Ian <> Date: Fri, 8 Nov 2024 12:29:49 -0600 Subject: [PATCH 4/6] Replace placeholder code with real code --- scripts/delayed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/delayed.js b/scripts/delayed.js index 992d2e0..2f58683 100644 --- a/scripts/delayed.js +++ b/scripts/delayed.js @@ -43,7 +43,7 @@ async function loadGA() { } async function loadGetFeedback() { - const src = 'console.log("Load GetFeedback");'; + const src = `window.lightningjs||function(n){var e="lightningjs";function t(e,t){var r,i,a,o,d,c;return t&&(t+=(/\?/.test(t)?"&":"?")+"lv=1"),n[e]||(r=window,i=document,a=e,o=i.location.protocol,d="load",c=0,function(){n[a]=function(){var t=arguments,i=this,o=++c,d=i&&i!=r&&i.id||0;function s(){return s.id=o,n[a].apply(s,arguments)}return(e.s=e.s||[]).push([o,d,t]),s.then=function(n,t,r){var i=e.fh[o]=e.fh[o]||[],a=e.eh[o]=e.eh[o]||[],d=e.ph[o]=e.ph[o]||[];return n&&i.push(n),t&&a.push(t),r&&d.push(r),s},s};var e=n[a]._={};function s(){e.P(d),e.w=1,n[a]("_load")}e.fh={},e.eh={},e.ph={},e.l=t?t.replace(/^\/\//,("https:"==o?o:"http:")+"//"):t,e.p={0:+new Date},e.P=function(n){e.p[n]=new Date-e.p[0]},e.w&&s(),r.addEventListener?r.addEventListener(d,s,!1):r.attachEvent("onload",s);var l=function(){function n(){return["<",o,"><",t,"><",r,' src="',e.l,'">"].join("")}var t="body",r="script",o="html",d=i[t];if(!d)return setTimeout(l,100);e.P(1);var c,s=i.createElement("div"),h=s.appendChild(i.createElement("div")),u=i.createElement("iframe");s.style.display="none",d.insertBefore(s,d.firstChild).id="lightningjs-"+a,u.frameBorder="0",u.id="lightningjs-frame-"+a,/MSIE[ ]+6/.test(navigator.userAgent)&&(u.src="javascript:false"),u.allowTransparency="true",h.appendChild(u);try{u.contentWindow.document.open()}catch(n){e.domain=i.domain,c="javascript:var d=document.open();d.domain='"+i.domain+"';",u.src=c+"void(0);"}try{var p=u.contentWindow.document;p.write(n()),p.close()}catch(e){u.src=c+'d.write("'+n().replace(/"/g,String.fromCharCode(92)+'"')+'");d.close();'}e.P(2)};e.l&&l()}()),n[e].lv="1",n[e]}var r=window.lightningjs=t(e);r.require=t,r.modules=n}({});window.usabilla_live = lightningjs.require("usabilla_live", "//w.usabilla.com/fc9bea86c613.js");`; await loadBodyScript(src, { type: 'text/javascript', }); From 06cbb72acf1233fb4dbf5a567a378a93487ac2a1 Mon Sep 17 00:00:00 2001 From: Ian <> Date: Tue, 12 Nov 2024 10:45:14 -0600 Subject: [PATCH 5/6] Escape backslashes in GetFeedback tag The backslash is being interpreted by the code that reads the string, rather than being passed to the regular expression parser. --- scripts/delayed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/delayed.js b/scripts/delayed.js index 2f58683..e1db89c 100644 --- a/scripts/delayed.js +++ b/scripts/delayed.js @@ -43,7 +43,7 @@ async function loadGA() { } async function loadGetFeedback() { - const src = `window.lightningjs||function(n){var e="lightningjs";function t(e,t){var r,i,a,o,d,c;return t&&(t+=(/\?/.test(t)?"&":"?")+"lv=1"),n[e]||(r=window,i=document,a=e,o=i.location.protocol,d="load",c=0,function(){n[a]=function(){var t=arguments,i=this,o=++c,d=i&&i!=r&&i.id||0;function s(){return s.id=o,n[a].apply(s,arguments)}return(e.s=e.s||[]).push([o,d,t]),s.then=function(n,t,r){var i=e.fh[o]=e.fh[o]||[],a=e.eh[o]=e.eh[o]||[],d=e.ph[o]=e.ph[o]||[];return n&&i.push(n),t&&a.push(t),r&&d.push(r),s},s};var e=n[a]._={};function s(){e.P(d),e.w=1,n[a]("_load")}e.fh={},e.eh={},e.ph={},e.l=t?t.replace(/^\/\//,("https:"==o?o:"http:")+"//"):t,e.p={0:+new Date},e.P=function(n){e.p[n]=new Date-e.p[0]},e.w&&s(),r.addEventListener?r.addEventListener(d,s,!1):r.attachEvent("onload",s);var l=function(){function n(){return["<",o,"><",t,"><",r,' src="',e.l,'">"].join("")}var t="body",r="script",o="html",d=i[t];if(!d)return setTimeout(l,100);e.P(1);var c,s=i.createElement("div"),h=s.appendChild(i.createElement("div")),u=i.createElement("iframe");s.style.display="none",d.insertBefore(s,d.firstChild).id="lightningjs-"+a,u.frameBorder="0",u.id="lightningjs-frame-"+a,/MSIE[ ]+6/.test(navigator.userAgent)&&(u.src="javascript:false"),u.allowTransparency="true",h.appendChild(u);try{u.contentWindow.document.open()}catch(n){e.domain=i.domain,c="javascript:var d=document.open();d.domain='"+i.domain+"';",u.src=c+"void(0);"}try{var p=u.contentWindow.document;p.write(n()),p.close()}catch(e){u.src=c+'d.write("'+n().replace(/"/g,String.fromCharCode(92)+'"')+'");d.close();'}e.P(2)};e.l&&l()}()),n[e].lv="1",n[e]}var r=window.lightningjs=t(e);r.require=t,r.modules=n}({});window.usabilla_live = lightningjs.require("usabilla_live", "//w.usabilla.com/fc9bea86c613.js");`; + const src = `window.lightningjs||function(n){var e="lightningjs";function t(e,t){var r,i,a,o,d,c;return t&&(t+=(/\\?/.test(t)?"&":"?")+"lv=1"),n[e]||(r=window,i=document,a=e,o=i.location.protocol,d="load",c=0,function(){n[a]=function(){var t=arguments,i=this,o=++c,d=i&&i!=r&&i.id||0;function s(){return s.id=o,n[a].apply(s,arguments)}return(e.s=e.s||[]).push([o,d,t]),s.then=function(n,t,r){var i=e.fh[o]=e.fh[o]||[],a=e.eh[o]=e.eh[o]||[],d=e.ph[o]=e.ph[o]||[];return n&&i.push(n),t&&a.push(t),r&&d.push(r),s},s};var e=n[a]._={};function s(){e.P(d),e.w=1,n[a]("_load")}e.fh={},e.eh={},e.ph={},e.l=t?t.replace(/^\\/\\//,("https:"==o?o:"http:")+"//"):t,e.p={0:+new Date},e.P=function(n){e.p[n]=new Date-e.p[0]},e.w&&s(),r.addEventListener?r.addEventListener(d,s,!1):r.attachEvent("onload",s);var l=function(){function n(){return["<",o,"><",t,"><",r,' src="',e.l,'">"].join("")}var t="body",r="script",o="html",d=i[t];if(!d)return setTimeout(l,100);e.P(1);var c,s=i.createElement("div"),h=s.appendChild(i.createElement("div")),u=i.createElement("iframe");s.style.display="none",d.insertBefore(s,d.firstChild).id="lightningjs-"+a,u.frameBorder="0",u.id="lightningjs-frame-"+a,/MSIE[ ]+6/.test(navigator.userAgent)&&(u.src="javascript:false"),u.allowTransparency="true",h.appendChild(u);try{u.contentWindow.document.open()}catch(n){e.domain=i.domain,c="javascript:var d=document.open();d.domain='"+i.domain+"';",u.src=c+"void(0);"}try{var p=u.contentWindow.document;p.write(n()),p.close()}catch(e){u.src=c+'d.write("'+n().replace(/"/g,String.fromCharCode(92)+'"')+'");d.close();'}e.P(2)};e.l&&l()}()),n[e].lv="1",n[e]}var r=window.lightningjs=t(e);r.require=t,r.modules=n}({});window.usabilla_live = lightningjs.require("usabilla_live", "//w.usabilla.com/fc9bea86c613.js");`; await loadBodyScript(src, { type: 'text/javascript', }); From 8285504845697d2add082d96f1ebce1c144650b7 Mon Sep 17 00:00:00 2001 From: Ian <> Date: Mon, 9 Dec 2024 22:22:44 -0600 Subject: [PATCH 6/6] Fix lint issue --- scripts/delayed.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/delayed.js b/scripts/delayed.js index e1db89c..6471c01 100644 --- a/scripts/delayed.js +++ b/scripts/delayed.js @@ -43,6 +43,7 @@ async function loadGA() { } async function loadGetFeedback() { + // eslint-disable-next-line const src = `window.lightningjs||function(n){var e="lightningjs";function t(e,t){var r,i,a,o,d,c;return t&&(t+=(/\\?/.test(t)?"&":"?")+"lv=1"),n[e]||(r=window,i=document,a=e,o=i.location.protocol,d="load",c=0,function(){n[a]=function(){var t=arguments,i=this,o=++c,d=i&&i!=r&&i.id||0;function s(){return s.id=o,n[a].apply(s,arguments)}return(e.s=e.s||[]).push([o,d,t]),s.then=function(n,t,r){var i=e.fh[o]=e.fh[o]||[],a=e.eh[o]=e.eh[o]||[],d=e.ph[o]=e.ph[o]||[];return n&&i.push(n),t&&a.push(t),r&&d.push(r),s},s};var e=n[a]._={};function s(){e.P(d),e.w=1,n[a]("_load")}e.fh={},e.eh={},e.ph={},e.l=t?t.replace(/^\\/\\//,("https:"==o?o:"http:")+"//"):t,e.p={0:+new Date},e.P=function(n){e.p[n]=new Date-e.p[0]},e.w&&s(),r.addEventListener?r.addEventListener(d,s,!1):r.attachEvent("onload",s);var l=function(){function n(){return["<",o,"><",t,"><",r,' src="',e.l,'">"].join("")}var t="body",r="script",o="html",d=i[t];if(!d)return setTimeout(l,100);e.P(1);var c,s=i.createElement("div"),h=s.appendChild(i.createElement("div")),u=i.createElement("iframe");s.style.display="none",d.insertBefore(s,d.firstChild).id="lightningjs-"+a,u.frameBorder="0",u.id="lightningjs-frame-"+a,/MSIE[ ]+6/.test(navigator.userAgent)&&(u.src="javascript:false"),u.allowTransparency="true",h.appendChild(u);try{u.contentWindow.document.open()}catch(n){e.domain=i.domain,c="javascript:var d=document.open();d.domain='"+i.domain+"';",u.src=c+"void(0);"}try{var p=u.contentWindow.document;p.write(n()),p.close()}catch(e){u.src=c+'d.write("'+n().replace(/"/g,String.fromCharCode(92)+'"')+'");d.close();'}e.P(2)};e.l&&l()}()),n[e].lv="1",n[e]}var r=window.lightningjs=t(e);r.require=t,r.modules=n}({});window.usabilla_live = lightningjs.require("usabilla_live", "//w.usabilla.com/fc9bea86c613.js");`; await loadBodyScript(src, { type: 'text/javascript',