/* 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) { 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 ---------------- */