/* Begin GTM custom */ var events = { "page-load": function () { var query = (location.search || "").replace("?query=", ""); var obj = { page_type: window.gtmPageType, page_title: document.title, }; if (query) { obj["query_string"] = query; } return obj; }, "start-quote": function (el) { return { event: "gaCustomEvent_StartQuote", eventCategory: "StartQuote", eventAction: "Click", eventLabel: el.dataset.location || "no location specified", }; }, "click-to-call": function (el) { return { event: "gaCustomEvent_ClicktoCall", eventCategory: "Engagement", eventAction: "Phone number clicked", eventLabel: location.href, phone_number_clicked: (el.href || el.innerText).replace("tel:", ""), }; }, "newsletter-signup": function (el) { return { event: "gaCustomEvent_NewsletterSignup", eventCategory: "Lead generation", eventAction: "Newsletter submit", }; }, "newsletter-email": function (el) { return { event: "gaCustomEvent_NewsletterEmail", eventCategory: "Lead generation", eventAction: "Email submit", eventLabel: el.dataset.location || "no location specified", }; }, "banner-click": function (el) { return { event: "gaCustomEvent_BannerClick", eventCategory: "Banner", eventAction: "Click", eventLabel: el.dataset.banner || el.innerText, }; }, "banner-impression": function (el) { return { event: "gaCustomEvent_BannerImpression", eventCategory: "Banner", eventAction: "Impression", eventLabel: el.dataset.banner || el.innerText, }; }, "external-link": function (el) { return { event: "gaCustomEvent_ExternalLink", eventCategory: "Link tracking", eventAction: "External link click", eventLabel: (el.href || "") .replace("http://", "") .replace("https://", ""), }; }, "internal-link": function (el) { return { event: "gaCustomEvent_InternalLink", eventCategory: "Link tracking", eventAction: "Internal link click", eventLabel: (el.href || "") .replace("http://", "") .replace("https://", ""), }; }, }; document.querySelectorAll("[data-event]").forEach(function (el) { el.addEventListener("click", function (event) { try { var evNames = (event.currentTarget.dataset.event || "").split(","); evNames.forEach(function (evName) { window.dataLayer.push(events[evName.trim()](event.currentTarget)); }); } catch (ex) {} }); }); document.querySelectorAll("[data-banner]").forEach(function (el) { var style = window.getComputedStyle(el); if (style.display !== "none") { window.dataLayer.push(events["banner-impression"](el)); } }); /* end GTM custom */ /* Prevent mobile menus from blocking content when using 100VH */ let vh = window.innerHeight * 0.01; document.documentElement.style.setProperty("--vh", `${vh}px`); window.addEventListener("resize", () => { let vh = window.innerHeight * 0.01; document.documentElement.style.setProperty("--vh", `${vh}px`); }); /* End Prevent mobile menus from blocking content when using 100VH */ /* ----------------- UTM / C-CODE / UTM+C-CODE / COOKIED SEARCH PARAMETER ---------------- */ //////////////////////////////////////////////// cookie storage ///////////////////////////////////////////// console.log("cookie storage"); function setCookie(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000); let expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } function getCookie(cname) { let name = cname + "="; let ca = document.cookie.split(";"); for (let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) == " ") { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } function checkCookie() { if (window.location.search.indexOf("&pushingP9") < 0) return; const five = getCookie("partnerCookie"); if (five != "") return; else { let partnerParam = window.location.search; setCookie("partnerCookie", partnerParam, 1); } } checkCookie(); const cookieParam = function () { const partnerCookie = getCookie("partnerCookie"); if (!partnerCookie) { document.querySelectorAll("[data-stack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; finalUrl = `https://${domain}/mypet`; link.href = finalUrl; console.log(finalUrl); }); document.querySelectorAll("[data-cstack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const cstack = link.dataset.cstack; finalUrl = `https://${domain}/mypet?c=${cstack}`; link.href = finalUrl; console.log(finalUrl); }); document.querySelectorAll("[data-pstack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const pstack = link.dataset.pstack; finalUrl = `https://${domain}/mypet?c=${pstack}`; link.href = finalUrl; console.log(finalUrl); }); document.querySelectorAll("[data-wstack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const wstack = link.dataset.wstack; finalUrl = `https://www.walmartpetinsurance.com/mypet?c=${wstack}`; link.href = finalUrl; console.log(finalUrl); }); } else { //stack document.querySelectorAll("[data-stack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const search = getCookie("partnerCookie"); finalUrl = `https://${domain}/mypet${search}`; link.href = finalUrl; console.log(finalUrl); }); //cstack document.querySelectorAll("[data-cstack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const search = getCookie("partnerCookie"); const cstack = link.dataset.cstack; const searchStage = search.replace("?", "&"); finalUrl = `https://${domain}/mypet${search}`; link.href = finalUrl; console.log(finalUrl); }); ///// pstack document.querySelectorAll("[data-pstack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const searchStage = search.replace("?", "&"); const search = getCookie("partnerCookie"); const pstack = link.dataset.pstack; const searchfr = search.slice(1); let urlParams = new URLSearchParams(searchfr); let ccode = urlParams.get("c"); const promoCode = search.replace(ccode, pstack); finalUrl = `https://${domain}/mypet${promoCode}`; link.href = finalUrl; console.log(finalUrl); }); ///// wstack document.querySelectorAll("[data-wstack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const search = getCookie("partnerCookie"); const wstack = link.dataset.wstack; const searchStage = search.replace("?", "&"); const searchfr = search.slice(1); let urlParams = new URLSearchParams(searchfr); let ccode = urlParams.get("c"); const promoCode = search.replace(ccode, wstack); finalUrl = `https://www.walmartpetinsurance.com/mypet${promoCode}`; link.href = finalUrl; console.log(finalUrl); }); } }; //////////////////////////////////////////////// session storage ///////////////////////////////////////////// console.log("session storage"); const checkIt = function () { if (window.location.search.length > 0) { // removing duplicate email if it exist const params = new URLSearchParams(window.location.search); const allUTMMedium = params.getAll("utm_medium"); if (allUTMMedium.length > 1) { const lastUTMMedium = allUTMMedium.pop(); // Get the last 'utm_medium' params.delete("utm_medium"); params.append("utm_medium", lastUTMMedium); sessionStorage.setItem("searchData", `?${params.toString()}`); } else { sessionStorage.setItem("searchData", window.location.search); } } }; const checkSession = function () { const sesh = sessionStorage.getItem("searchData"); if (!sesh) { //testdev document.querySelectorAll("[data-stack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; finalUrl = `https://${domain}/mypet`; link.href = finalUrl; console.log(finalUrl); }); document.querySelectorAll("[data-cstack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const cstack = link.dataset.cstack; finalUrl = `https://${domain}/mypet?c=${cstack}`; link.href = finalUrl; console.log(finalUrl); }); document.querySelectorAll("[data-pstack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const pstack = link.dataset.pstack; finalUrl = `https://${domain}/mypet?c=${pstack}`; link.href = finalUrl; console.log(finalUrl); }); document.querySelectorAll("[data-wstack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const wstack = link.dataset.wstack; finalUrl = `https://www.walmartpetinsurance.com/mypet?c=${wstack}`; link.href = finalUrl; console.log(finalUrl); }); } else { // stack document.querySelectorAll("[data-stack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const search = sessionStorage.getItem("searchData"); finalUrl = `https://${domain}/mypet${search}`; link.href = finalUrl; console.log(finalUrl); }); // cstack document.querySelectorAll("[data-cstack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const search = sessionStorage.getItem("searchData"); const cstack = link.dataset.cstack; const searchStage = search.replace("?", "&"); const searchfr = search.slice(1); if (search.includes("c=")) { finalUrl = `https://${domain}/mypet${search}`; } else { finalUrl = `https://${domain}/mypet?c=${cstack}${searchStage}`; } link.href = finalUrl; console.log(finalUrl); }); // pstack document.querySelectorAll("[data-pstack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const search = sessionStorage.getItem("searchData"); const pstack = link.dataset.pstack; const searchStage = search.replace("?", "&"); const searchfr = search.slice(1); if (search.includes("c=")) { let urlParams = new URLSearchParams(searchfr); let ccode = urlParams.get("c"); const promoCode = search.replace(ccode, pstack); finalUrl = `https://${domain}/mypet${promoCode}`; } else { finalUrl = `https://${domain}/mypet?c=${pstack}${searchStage}`; } link.href = finalUrl; console.log(finalUrl); }); //wstack document.querySelectorAll("[data-wstack]").forEach(function (link) { if (!link) return; const domain = window.location.hostname; const search = sessionStorage.getItem("searchData"); const wstack = link.dataset.wstack; const searchStage = search.replace("?", "&"); const searchfr = search.slice(1); if (search.includes("c=")) { let urlParams = new URLSearchParams(searchfr); let ccode = urlParams.get("c"); const promoCode = search.replace(ccode, wstack); finalUrl = `https://www.walmartpetinsurance.com/mypet${promoCode}`; } else { finalUrl = `https://www.walmartpetinsurance.com/mypet?c=${wstack}${searchStage}`; } link.href = finalUrl; console.log(finalUrl); }); } }; cookieParam(); checkIt(); checkSession(); /* ----------------- UTM / C-CODE / UTM+C-CODE / COOKIED SEARCH PARAMETER ---------------- */ /* ----------------- Health Forecast Button Logic ---------------- */ const paramsSet = () => { const ctaParams = sessionStorage.getItem("searchData"); if (!ctaParams) { document.querySelectorAll("[data-health_cta]").forEach((element) => { let btnDomain = window.location.hostname; let sitePath = "/health/getstarted"; let btnUrl = `https://${btnDomain}${sitePath}`; element.setAttribute("href", btnUrl); }); document.querySelectorAll("[data-forecast_land_cta]").forEach((element) => { let btnDomain = window.location.hostname; let sitePath = "/health"; let btnUrl = `https://${btnDomain}${sitePath}`; element.setAttribute("href", btnUrl); }); } else { document.querySelectorAll("[data-health_cta]").forEach((element) => { let btnDomain = window.location.hostname; let sitePath = "/health/getstarted"; let btnUrl = `https://${btnDomain}${sitePath}${ctaParams}`; element.setAttribute("href", btnUrl); }); document.querySelectorAll("[data-forecast_land_cta]").forEach((element) => { let btnDomain = window.location.hostname; let sitePath = "/health"; let btnUrl = `https://${btnDomain}${sitePath}${ctaParams}`; element.setAttribute("href", btnUrl); }); } }; paramsSet(); /* ----------------- Health Forecast Button Logic ---------------- */ /* ----------------- Employee Bennefit Logic ---------------- */ function setCookie(cookieName, cookieValue, expirationDays = 30) { var date = new Date(); date.setTime(date.getTime() + expirationDays * 24 * 60 * 60 * 1000); var expires = "expires=" + date.toUTCString(); document.cookie = cookieName + "=" + cookieValue + ";" + expires + ";path=/"; } function getCookie(cookieName) { var name = cookieName + "="; var decodedCookie = decodeURIComponent(document.cookie); var cookieArray = decodedCookie.split(";"); for (var i = 0; i < cookieArray.length; i++) { var cookie = cookieArray[i]; while (cookie.charAt(0) === " ") { cookie = cookie.substring(1); } if (cookie.indexOf(name) === 0) { return cookie.substring(name.length, cookie.length); } } return ""; } const setEmpNum = () => { if ( window.location.search && window.location.search.includes("utm_medium=employeebenefits") ) setCookie("emp-benefit-visitor", "true", 60); if ( !getCookie("emp-benefit-visitor") || document .getElementById("partner-append") ?.getAttribute("employee-benefit") == "no" ) return; console.log("yes"); const phone_1 = "800"; const phone_2 = "212"; const phone_3 = "2698"; document.querySelectorAll("[data-number-nav-link]").forEach((element) => { element.setAttribute("href", `tel:${phone_1}-${phone_2}-${phone_3}`); }); document.querySelectorAll("[data-number-nav-text]").forEach((element) => { element.textContent = `${phone_1}.${phone_2}.${phone_3}`; }); document.querySelectorAll("[data-number-footer]").forEach((element) => { element.textContent = `1.${phone_1}.${phone_2}.${phone_3}`; element.setAttribute("href", `tel:${phone_1}-${phone_2}-${phone_3}`); }); }; setEmpNum(); /* ----------------- Employee Bennefit Logic ---------------- */