/* 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 */ /* Start localization/Geotargetly custom code by default, all elements with [data-country] are hidden */ window.initLocalizedContent = function (countryCode) { console.log("Setting country to: ", countryCode); clearTimeout(localizationTimeout); var localizedContent = document.querySelectorAll('[data-country]'); localizedContent.forEach(function (el) { var codes = (el.dataset.country || "").split("|"); var matched = false; codes.forEach(function (code) { if (code.trim() === countryCode) { matched = true; delete el.dataset.country; } }); if (!matched) { // remove nodes that do not match the current locale el.parentNode.removeChild(el); } }); } var localizationTimeout = setTimeout(function () { console.log("Forcing localization to the default non-CA"); window.initLocalizedContent("default"); }, 2000); var host = window.location.host; var domainSuffix = host.substring(host.length - 2); if (host === "www.fetchpet.ca") { console.log("Domain is CA."); window.initLocalizedContent("CA"); var counter = 0; var mapLinks = function () { var changeHref = function(link) { if (link.href && link.href.indexOf("gopetplan.com") >= 0) { if (link.href.indexOf("my.fetchpet") < 0) { link.href = link.href.replace("fetchpet.com", "fetchpet.ca"); } } } document.querySelectorAll("a").forEach(function (l) { changeHref(l); }); document.querySelectorAll('link[rel="canonical"]').forEach(function (l) { changeHref(l); }); counter++; if (counter < 5) { setTimeout(mapLinks, 1000); } } setTimeout(mapLinks, 100); } /* End Geotargetly custom code */ /* 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`); }); var APP_ID = "aitg1gp7"; // Replace this with your workspace ID window.intercomSettings = { app_id: APP_ID }; /* 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('?utm') < 0) return; 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) { 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 ---------------- */