/* 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`); }); var APP_ID = "aitg1gp7"; // Replace this with your workspace ID window.intercomSettings = { app_id: APP_ID }; /* 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 */