From 9b97d9e0e51bb95d8df48d0808d9599bb565cb2a Mon Sep 17 00:00:00 2001 From: npy11 Date: Thu, 12 Dec 2024 16:39:43 +0530 Subject: [PATCH] moengage js added in delayed file --- blocks/header/header.js | 14 --------- scripts/delayed.js | 63 +++++++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/blocks/header/header.js b/blocks/header/header.js index 57f18a5..7ef7f9b 100644 --- a/blocks/header/header.js +++ b/blocks/header/header.js @@ -365,18 +365,4 @@ export default async function decorate(block) { mobileLogo.classList.add('mobile-logo'); mobileSections?.prepend(mobileLogo); - try { - let moengageContainer = document.getElementById("moengage-container"); - let heightMoengage = moengageContainer.clientHeight; - navWrapper.style.marginTop = `${heightMoengage}px`; - window.addEventListener('scroll', function (event) { - if (window.scrollY > 50) { - navWrapper.style.marginTop = "0px" - } else { - navWrapper.style.marginTop = `${heightMoengage}px`; - } - }) - } catch (error) { - console.warn("Moengage Error :: ", error); - } } diff --git a/scripts/delayed.js b/scripts/delayed.js index c7cc2fd..33d3c20 100644 --- a/scripts/delayed.js +++ b/scripts/delayed.js @@ -7,18 +7,18 @@ import { fetchPlaceholders, sampleRUM } from './aem.js'; sampleRUM('cwv'); -function loadServiceWorker(){ - if ('serviceWorker' in navigator) { - // window.addEventListener('load', () => { - navigator.serviceWorker.register('../scripts/serviceworker.js').then((reg) => { - console.log('Service Worker registered.', reg); - }).catch((err) => { - console.log('Service Worker **not** registered', err); - }) - // }); - } else { - console.log('Service workers are not supported in this browser.'); - } +function loadServiceWorker() { + if ('serviceWorker' in navigator) { + // window.addEventListener('load', () => { + navigator.serviceWorker.register('../scripts/serviceworker.js').then((reg) => { + console.log('Service Worker registered.', reg); + }).catch((err) => { + console.log('Service Worker **not** registered', err); + }) + // }); + } else { + console.log('Service workers are not supported in this browser.'); + } } // add more delayed functionality here @@ -49,28 +49,43 @@ function loadBodyGTM() { document.body.prepend(noScriptTag); } -async function loadMoengage(){ +async function loadMoengage() { const placeholders = await fetchPlaceholders(); const scriptTag = document.createElement('script'); scriptTag.type = 'text/javascript'; - - var moeDataCenter = placeholders.monenageDc; // Replace "DC" with the actual Data center value from the above table - var moeAppID = placeholders.monenageAppid; // Replace "WorkspaceID" available in the settings page of MoEngage Dashboard. + + var moeDataCenter = placeholders.monenageDc; // Replace "DC" with the actual Data center value from the above table + var moeAppID = placeholders.monenageAppid; // Replace "WorkspaceID" available in the settings page of MoEngage Dashboard. var debug_logs = placeholders.monegageDebuglog; // MoEngage Web SDK uses a parameter debug_logs: 1 to detect that you are integrating in TEST environment. When you decide to take your website LIVE, just pass the parameter debug_logs: 0 and all data about your actual users would start appearing in LIVE environment - var sdkVersion = placeholders.monegageSdkversion; // Replace this value with the version of Web SDK that you intend to use. It is recommended to use the format x (major); - + var sdkVersion = placeholders.monegageSdkversion; // Replace this value with the version of Web SDK that you intend to use. It is recommended to use the format x (major); + scriptTag.innerHTML = ` console.log('MoEngage Web SDK'); !function(e,n,i,t,a,r,o,d){if(!"${moeDataCenter}"||!"${moeDataCenter}".match(/^dc_[0-9]+$/gm))return console.error("Data center has not been passed correctly. Please follow the SDK installation instruction carefully.");var s=e[a]=e[a]||[];if(s.invoked=0,s.initialised>0||s.invoked>0)return console.error("MoEngage Web SDK initialised multiple times. Please integrate the Web SDK only once!"),!1;e.moengage_object=a;var l={},g=function n(i){return function(){for(var n=arguments.length,t=Array(n),a=0;a1)?(console.error("MoEngage Web SDK initialised multiple times. Please integrate the Web SDK only once!"),!1):(d=arguments.length<=0?void 0:arguments[0],l)},r.addEventListener("load",function(){if(d)return e[a]=e.moe(d),e[a].initialised=e[a].initialised+1||1,!0}),r.addEventListener("error",function(){return console.error("Moengage Web SDK loading failed."),!1})}(window,document,"script","https://cdn.moengage.com/release/${moeDataCenter}/versions/${sdkVersion}/moe_webSdk.min.latest.js","Moengage");`; document.head.append(scriptTag); - - Moengage = moe({ - app_id: moeAppID, - debug_logs: debug_logs - }); - + + Moengage = moe({ + app_id: moeAppID, + debug_logs: debug_logs + }); + + try { + let moengageContainer = document.getElementById("moengage-container"); + let navWrapper = document.querySelector(".nav-wrapper"); + let heightMoengage = moengageContainer.clientHeight; + window.addEventListener('scroll', function (event) { + navWrapper.style.marginTop = `${heightMoengage}px`; + if (window.scrollY > 50) { + navWrapper.style.marginTop = "0px" + } else { + navWrapper.style.marginTop = `${heightMoengage}px`; + } + }) + } catch (error) { + console.warn("Moengage Error :: ", error); + } } if (!window.location.hostname.includes('localhost') && !window.location.hostname.includes('author')) {