analytics.ready(function () { function getQueryParam(url, param) { // Expects a raw URL param = param.replace(/[[]/, "[").replace(/[]]/, "]"); var regexS = "[?&]" + param + "=([^&#]*)", regex = new RegExp(regexS), results = regex.exec(url); if ( results === null || (results && typeof results[1] !== "string" && results[1].length) ) { return "not set"; } else { return decodeURIComponent(results[1]); } } var last_activity = mixpanel.get_property("last_activity"); var session_inactivity = Math.round( (((Date.now() - last_activity) % 86400000) % 3600000) / 60000 ); if (isNaN(session_inactivity)) session_inactivity = 0; var campaign_keywords = "utm_source utm_medium utm_campaign utm_content utm_term gclid".split( " " ), kw = "", last_params = {}, first_params = {}; var index; var last_touch_utms = []; var first_touch_utms = []; if (document.referrer) { var referrer = document.referrer; var referrerHostname = new URL(referrer).hostname; var referrerPath = new URL(referrer).pathname; } else { var referrer = "not set"; var referrerHostname = "not set"; var referrerPath = "not set"; } if (!last_activity) { for (index = 0; index < campaign_keywords.length; ++index) { if (campaign_keywords[index] == "gclid") { kw = getQueryParam(document.URL, campaign_keywords[index]); } else { kw = getQueryParam( document.URL.toLowerCase(), campaign_keywords[index] ); } last_params[campaign_keywords[index] + " last touch"] = kw; first_params[campaign_keywords[index]] = kw; } mixpanel.register_once(first_params); mixpanel.register(last_params); var date = new Date(); var isoDate = date.toISOString(); mixpanel.register_once({ "initial visit date": isoDate }); mixpanel.register_once({ "initial page": window.location.href }); mixpanel.register({ referrer: referrer }); mixpanel.register({ "referrer hostname": referrerHostname }); mixpanel.register({ "referrer path": referrerPath }); mixpanel.register_once({ "initial referrer hostname": referrerHostname }); } else if (session_inactivity >= 30) { for (index = 0; index < campaign_keywords.length; ++index) { if (campaign_keywords[index] == "gclid") { kw = getQueryParam(document.URL, campaign_keywords[index]); } else { kw = getQueryParam( document.URL.toLowerCase(), campaign_keywords[index] ); } last_params[campaign_keywords[index] + " last touch"] = kw; first_params[campaign_keywords[index]] = mixpanel.get_property( campaign_keywords[index] ); mixpanel.register(last_params); mixpanel.register({ referrer: referrer }); mixpanel.register({ "referrer hostname": referrerHostname }); mixpanel.register({ "referrer path": referrerPath }); } } else { // no url params need to be set during existing open session // but they do need to be captured for Salesforce for (index = 0; index < campaign_keywords.length; ++index) { if (campaign_keywords[index] == "gclid") { kw = getQueryParam(document.URL, campaign_keywords[index]); } else { kw = getQueryParam( document.URL.toLowerCase(), campaign_keywords[index] ); } last_params[campaign_keywords[index] + " last touch"] = mixpanel.get_property(campaign_keywords[index] + " last touch"); } } mixpanel.register({ last_activity: Date.now() }); var userEmail = mixpanel.get_property("email") || ""; analytics.identify({ email: userEmail, user_id: mixpanel.get_property("user_id") || "", }); var properties = {}; properties = { title: document.title || "", url: window.location.href, path: window.location.pathname, email: userEmail, "page path level 1": window.location.pathname.split("/")[1] ? window.location.pathname.split("/")[1] : "", "page path level 2": window.location.pathname.split("/")[2] ? window.location.pathname.split("/")[2] : "", "page path level 3": window.location.pathname.split("/")[3] ? window.location.pathname.split("/")[3] : "", search: window.location.href.split("?")[1] || "", "page hash": window.location.hash || "", "page hostname": window.location.hostname, organization_name: mixpanel.get_property("organization_name") || "", organization_id: mixpanel.get_property("organization_id") || "", user_id: mixpanel.get_property("user_id") || "", }; analytics.track("page viewed", properties); /***************************************** * Replaces old cookie. * ***************************************/ var parsedUtmParams = "source=" + last_params["utm_source last touch"] + "&campaign=" + last_params["utm_campaign last touch"] + "&medium=" + last_params["utm_medium last touch"] + "&term=" + last_params["utm_term last touch"] + "&content=" + last_params["utm_content last touch"]; // replaces original cookie 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 + ";domain=.dnsfilter.com;" + expires + ";path=/"; } setCookie("dnsfilterUTMParams", String(parsedUtmParams), 365); // replaces original cookie window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: "Pageview", url: window.location.pathname, }); /***************************************** * to populate HubSpot form UTMs when present * ***************************************/ document.getElementsByName("mkt_utm_source_most_recent__c").forEach(utm_field => {utm_field.value=mixpanel.cookie.props.utm_source}) document.getElementsByName("mkt_utm_medium_most_recent__c").forEach(utm_field => {utm_field.value=mixpanel.cookie.props.utm_medium}) document.getElementsByName("mkt_utm_campaign_most_recent__c").forEach(utm_field => {utm_field.value=mixpanel.cookie.props.utm_campaign}) document.getElementsByName("mkt_utm_content_most_recent__c").forEach(utm_field => {utm_field.value=mixpanel.cookie.props.utm_content}) document.getElementsByName("mkt_utm_term_most_recent__c").forEach(utm_field => {utm_field.value=mixpanel.cookie.props.utm_term}) });