var SignalsSDK;(()=>{"use strict";var e={};e.g=(()=>{if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}})(),(()=>{let r;var a="object",s=function(){},l="undefined"!=typeof process?process:{},d=(l.env&&l.env.NODE_ENV,"undefined"!=typeof document);function f(e,r){return r.charAt(0)[e]()+r.slice(1)}d&&window.location.hostname,null!=l.versions&&l.versions.node,"undefined"!=typeof Deno&&Deno.core,"object"==typeof self&&self.constructor&&self.constructor.name,d&&"nodejs"===window.name||"undefined"!=typeof navigator&&void 0!==navigator.userAgent&&(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom"));var h=f.bind(null,"toUpperCase"),p=f.bind(null,"toLowerCase");function v(e,r){void 0===r&&(r=!0);var a,s=function(e){return null===e}(e)?h("null"):"object"==typeof e?g((a=e).constructor)?a.constructor.name:null:Object.prototype.toString.call(e).slice(8,-1);return r?p(s):s}function m(e,r){return typeof r===e}var g=m.bind(null,"function"),w=m.bind(null,"string"),y=m.bind(null,"undefined");function b(e){return null===e}m.bind(null,"boolean"),m.bind(null,"symbol");function I(e,r){if("object"!=typeof r||null===r)return!1;if(r instanceof e)return!0;var a,s,l=v(new e(""));if((s=r)instanceof Error||w(s.message)&&s.constructor&&"number"===v(a=s.constructor.stackTraceLimit)&&!isNaN(a))for(;r;){if(v(r)===l)return!0;r=Object.getPrototypeOf(r)}return!1}function S(e,r){var a,s,l=e instanceof Element||e instanceof HTMLDocument;return l&&r?(a=e,void 0===(s=r)&&(s=""),a&&a.nodeName===s.toUpperCase()):l}function E(e){var r=[].slice.call(arguments,1);return function(){return e.apply(void 0,[].slice.call(arguments).concat(r))}}I.bind(null,TypeError),I.bind(null,SyntaxError),E(S,"form"),E(S,"button"),E(S,"input"),E(S,"select");var T="__global__",U=typeof self===a&&self.self===self&&self||typeof e.g===a&&e.g.global===e.g&&e.g||void 0;U[T]||(U[T]={});var k=function(){if(void 0!==k)return k;var e="cookiecookie";try{D(e,e),k=-1!==document.cookie.indexOf(e),k?D(e,"",-1):delete U[T][e]}catch(e){k=!1}return k}();function D(e,r,a,s,l,d){if("undefined"!=typeof window){var f=arguments.length>1;return!1===k&&(f?U[T][e]=r:U[T][e]),f?document.cookie=e+"="+encodeURIComponent(r)+(a?"; expires="+new Date(+new Date+1e3*a).toUTCString()+(s?"; path="+s:"")+(l?"; domain="+l:"")+(d?"; secure":""):""):decodeURIComponent((("; "+document.cookie).split("; "+e+"=")[1]||"").split(";")[0])}}function A(e){for(var r=[],a=e.length>>>0;a--;)r[a]=e[a];return r}function _(e,r){return e.reduce(function(e,a){var s=function(e){if(o(e))return[e];if(!u(e))throw Error("Selector must be string");return A(document.querySelectorAll(e))}(a);if(!s.length)return r&&console.log(a+" not found"),e;var l=s.filter(function(e){return!(!e||!n(e,t)&&!n(e,i))||(console.log("Selector passed in not a valid "+t),!1)});return e.concat(l)},[])}function F(e){return!o(e)&&typeof e===c}var L={"[object HTMLCollection]":!0,"[object NodeList]":!0,"[object RadioNodeList]":!0},P={button:!0,fieldset:!0,reset:!0,submit:!0},j={checkbox:!0,radio:!0},O=/^\s+|\s+$/g,V=Array.prototype.slice,R=Object.prototype.toString,N="Invalid form";function C(e,r){var a=null,s=e.type;if("select-one"===s)return e.options.length&&(a=e.options[e.selectedIndex].value),a;if("select-multiple"===s){a=[];for(var l=0,d=e.options.length;l-1||(void 0===(r=a[2])&&(r=""),-1!==r.indexOf("localhost")||-1!==r.indexOf("127.0.0.1")))}(r)||!r?Q(r,e):r;for(var l=/([^&=]+)=?([^&]*)/g;a=l.exec(r);){var d=x(a[1]),f=x(a[2]);"[]"===d.substring(d.length-2)?(s[d=d.substring(0,d.length-2)]||(s[d]=[])).push(f):s[d]=""===f||f}for(var h in s){var p=h.split("[");p.length>1&&(function(e,r,a){for(var s=r.length-1,l=0;l"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE;function el(e){let r=(es(e)&&"ownerDocument"in e?e.ownerDocument:window.document).defaultView;return e instanceof r.HTMLFormElement}class eu{instance;constructor(e){this.instance=e;let r=(e,r,a)=>{e.querySelectorAll(r).forEach(a),new MutationObserver(e=>{for(let s of e)for(let e of s.addedNodes)es(e)&&(e.matches(r)&&a(e),e.querySelectorAll(r).forEach(a))}).observe(e.body,{childList:!0,subtree:!0})},a=e=>{(function(e=document){return new Promise(r=>{"complete"===e.readyState||"interactive"===e.readyState?r():e.addEventListener("DOMContentLoaded",()=>r())})})(e).then(()=>r(e,"form",e=>e.addEventListener("submit",this.onSubmit.bind(this)))).catch(()=>{})};a(document),r(document,"iframe",e=>{let r=e.contentDocument;r&&a(r)})}onSubmit(e){if(null!=e.target&&el(e.target)){var r;let a=ei(new FormData(r=e.target),[/^email$/i,/email/i])??eo(r,["autocomplete"],[/^email$/])??eo(r,["placeholder"],[/email/i])??function(e,r){for(let a of r)for(let r of e.querySelectorAll("input, textarea")){let e=r.value;if("string"==typeof e&&e.match(a))return e}}(r,[ea]),s=function(e){var r;let a=new FormData(e);return ei(a,[/^name$/i])??(""!==(r=[eo(e,["autocomplete"],[/^given-name$/])??ei(a,[/first.*name/i,/fname/i,/given.*name/i])??eo(e,["placeholder"],[/first.*name/i,/given.*name/i]),eo(e,["autocomplete"],[/^family-name$/])??ei(a,[/last.*name/i,/lname/i,/surname/i])??eo(e,["placeholder"],[/last.*name/i,/surname/i])].filter(e=>null!=e).join(" "))?r:null)??eo(e,["autocomplete"],[/^name$/])??eo(e,["placeholder"],[/name/i])}(e.target);this.instance.form({...null!=a?{email:a}:{},...null!=s?{name:s}:{}})}}}var ec="EventListener";function ed(e){return function(r,a,l,f){var h=l||s,p=f||!1;if(!d)return h;var v=ef(a),m=ef(r,!0);if(!m.length)throw Error("noElements");if(!v.length)throw Error("noEvent");var g=[];return function e(r){r&&(g=[]);for(var a=r?"add"+ec:"remove"+ec,s=0;s-1?",":" ").map(function(e){return e.trim()});if(NodeList.prototype.isPrototypeOf(e)){for(var a=[],s=e.length>>>0;s--;)a[s]=e[s];return a}var l=e?"array"===v(e)?e:[e]:[];return r?l.map(function(e){return w(e)?ef(e,!0):e}).flat():l}var eh=ed("Event");function ep(e,r){var a,s;return d&&g(window[e])?(a=window[e],void 0===(s=window)&&(s=null),g(a)?function(){a.apply(s,arguments),r.apply(s,arguments)}:r):window[e]=r}ed(),ep.bind(null,"onerror"),ep.bind(null,"onload");var ev="undefined"==typeof window,em="hidden",eg=["mousemove","mousedown","touchmove","touchstart","touchend","keydown"];function ew(e,r){return r?0:Math.round((new Date-e)/1e3)}class ey{currentUrl;instance;currentFocusTime;aggregateFocusTime;activityTracker;heartbeatInterval;idleTimeout;constructor(e,{heartbeatInterval:r,idleTimeout:a=15}={}){this.instance=e,this.currentUrl=null,this.currentFocusTime=0,this.aggregateFocusTime=0,this.heartbeatInterval=r,this.idleTimeout=a;let s=history.pushState;history.pushState=(...e)=>{s.apply(history,e),this.onPageChange()};let l=history.replaceState;history.replaceState=(...e)=>{l.apply(history,e),this.onReplaceState()},window.addEventListener("popstate",()=>this.onPageChange()),this.activityTracker=function(e){var r,a,s=e.onIdle,l=e.onWakeUp,d=e.onHeartbeat,f=e.timeout,h=void 0===f?1e4:f,p=e.throttle,v=!1,m=!1,g=new Date,w=function(){return clearTimeout(r)};function y(e){w(),d&&!v&&d(ew(g),e),l&&v&&(v=!1,l(ew(a),e),g=new Date),r=setTimeout(function(){v=!0,s&&(a=new Date,s(ew(g),e))},h)}var b=function(e,r){void 0===r&&(r={});var a=function(e,r){var a=this,s=!1;return function(l){s||(e.call(a,l),s=!0,setTimeout(function(){return s=!1},r))}}(e,r.throttle||1e4),s=[];function l(){return s=[function(e){if(ev)return!1;var r=function(){return ev||em in document?em:["webkit","moz","ms","o"].reduce(function(e,r){var a=r+"Hidden";return!e&&a in document?a:e},null)}(),a="".concat(r.replace(/[H|h]idden/,""),"visibilitychange"),s=function(){return e(!!document[r])},l=function(){return document.addEventListener(a,s)};return l(),function(){return document.removeEventListener(a,s),l}}(function(e){e||a({type:"tabVisible"})})].concat(eg.map(function(e){return eh(document,e,a)})).concat(eh(window,"load",a)).concat(eh(window,"scroll",a,{capture:!0,passive:!0})),d}function d(){s.map(function(e){return e()})}return l(),function(){return d(),l}}(y,{throttle:void 0===p?2e3:p});return{disable:function(){m=!0,v=!1,w();var e=b();return function(){return m=!1,g=new Date,y({type:"load"}),e()}},getStatus:function(){return{isIdle:v,isDisabled:m,active:v?0:ew(g,m),idle:v?ew(a,m):0}}}}({onIdle:e=>{this.onPageFocus(e)},onHeartbeat:null!=this.heartbeatInterval?e=>{this.onPageFocus(e)}:void 0,onWakeUp:()=>{this.aggregateFocusTime+=this.currentFocusTime,this.currentFocusTime=0},timeout:1e3*this.idleTimeout,throttle:null!=this.heartbeatInterval?1e3*this.heartbeatInterval:void 0}),window.addEventListener("beforeunload",()=>{this.onLeavingPageFocus()}),this.onPageChange()}resetActivityTracker(){this.aggregateFocusTime=0,this.currentFocusTime=0,this.activityTracker.disable()()}onPageFocus(e){e>=0&&e<=525?(this.currentFocusTime=e,this.instance.pageFocus(this.aggregateFocusTime+this.currentFocusTime)):(this.instance.pageFocus(this.aggregateFocusTime),this.resetActivityTracker())}onLeavingPageFocus(){if(this.currentUrl){let e=this.activityTracker.getStatus();e.isIdle||this.onPageFocus(e.active)}}onPageChange(){this.onLeavingPageFocus(),this.currentUrl=new URL(window.location.href),this.instance.page(),this.resetActivityTracker()}onReplaceState(){let e=new URL(window.location.href);(null==this.currentUrl||this.currentUrl.hostname!==e.hostname||this.currentUrl.pathname!==e.pathname||this.currentUrl.search!==e.search)&&this.onPageChange()}}let eb={USER_ID:"signals-sdk-user-id",SESSION_ID:"signals-sdk-session-id"},eI={EMAIL:"cr_email",EMAIL_BASE64:"cr_e",UTM_ID:"utm_id"};function eS(e){let r=document.createElement("input");if(r.type="email",r.required=!0,r.value=e,!("function"==typeof r.checkValidity?r.checkValidity():/\S+@\S+\.\S+/.test(e)))return!1;let a=e.split("@")[0];return!(null==a||/\*{3,}$/.test(a))}function eE(e,r,a=["string"]){return Object.fromEntries(Object.entries(e).filter(([e,s])=>r.includes(e)&&a.includes(typeof s)))}class eT{siteId;userId;sessionId;apiHost;pageTracker=null;formTracker=null;static version=er.i8;lastPageViewEvent=null;constructor(e,{apiHost:r="https://api.cr-relay.com",autoTracking:a=!0}={}){this.siteId=e,this.apiHost=r,this.userId=this.initializeUserId(),this.sessionId=this.initializeSessionId();try{this.identifyWithQueryParams()}catch(e){console.error("Failed to identify the visitor with query params")}a&&(this.pageTracker=new ey(this),this.formTracker=new eu(this))}initializeStoredId(e,r,a){let s=D(e),l=""!==s?s:r;return D(e,l,a,"/","."+K(window.location.href).hostname.split(".").slice(-2).join("."),!1),l}initializeSessionId(){return this.initializeStoredId(eb.SESSION_ID,en(),1800)}initializeUserId(){return this.initializeStoredId(eb.USER_ID,en(),31536e3)}identifyWithQueryParams(){let e,r=new URLSearchParams(window.location.search),a=r.get(eI.EMAIL),s=r.get(eI.EMAIL_BASE64),l=r.get(eI.UTM_ID),d=r=>{try{let a=atob(r);eS(a)&&(e=a)}catch(e){}};null!=a&&eS(a)?e=a:null!=s?d(s):null!=l&&d(l),null!=e&&this.identify({email:e})}traceApiUrl(e){return new URL(`v1/site/${e}/batch`,this.apiHost)}async sendEvent(e){let r=this.traceApiUrl(this.siteId).toString(),a=JSON.stringify([e]);try{if(navigator.sendBeacon&&"function"==typeof navigator.sendBeacon&&navigator.sendBeacon(r,a))return;await fetch(r,{method:"POST",body:a,keepalive:!0,headers:{"Content-Type":"application/json"}})}catch(e){console.warn("Failed to send web visit event:",e)}}page(e){let r={eventType:"page_view",url:"string"==typeof e?e:e?.url??window.location.href,userId:this.userId,sessionId:this.sessionId,sdkVersion:eT.version,pageViewId:en()};this.lastPageViewEvent=r,this.sendEvent(r)}pageFocus(e){if(null==this.lastPageViewEvent)return;let r={eventType:"page_focus",pageViewId:this.lastPageViewEvent.pageViewId,focusTime:e,url:this.lastPageViewEvent.url,userId:this.userId,sessionId:this.sessionId,sdkVersion:eT.version};this.sendEvent(r)}identify(e){let r={eventType:"identity",userId:this.userId,sessionId:this.sessionId,sdkVersion:eT.version,...eE(e,["email","name"])};this.sendEvent(r)}identifyWithVector(){void 0!==window.vector&&window.vector.identify(JSON.stringify({userId:this.userId}))}form(e){let r=el(e)?function(e,r){if(void 0===r&&(r={trim:!1}),!e||!e.elements)throw Error(N);for(var a,s={},l=[],d={},f=0,h=e.elements.length;f0?l:null}(e,a=l[v],r);null!=g&&(s[a]=g)}return s}(e):e,a={eventType:"form",url:window.location.href,userId:this.userId,sessionId:this.sessionId,sdkVersion:eT.version,...eE(r,["email","name"])};this.sendEvent(a)}}!function(e,r){if("string"!=typeof e||""===e)throw Error("siteId is required");if(void 0!==window.signals&&window.signals instanceof eT)throw Error("SignalsSDK already loaded");null==r&&(r={});let a=new eT(e,r);if(Array.isArray(window.signals))for(let[e,r]of window.signals)try{a[e](...r)}catch(r){console.warn(`Error calling ${e}`,r)}window.signals=a}(null!=window.signals&&"_siteId"in window.signals?window.signals._siteId:function(){let e=document.currentScript?.getAttribute("src");return null!=e?e.split("/").at(-2):""}(),null!=window.signals&&"_opts"in window.signals?window.signals._opts:void 0)})(),SignalsSDK={}})();