UNPKG

@unifygtm/intent-client

Version:

JavaScript client for interacting with the Unify Intent API in the browser.

7 lines (5 loc) 30.5 kB
"use strict";var j=Object.defineProperty,oe=Object.defineProperties,se=Object.getOwnPropertyDescriptor,ae=Object.getOwnPropertyDescriptors,ce=Object.getOwnPropertyNames,Tt=Object.getOwnPropertySymbols;var vt=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var At=(e,t,n)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,c=(e,t)=>{for(var n in t||(t={}))vt.call(t,n)&&At(e,n,t[n]);if(Tt)for(var n of Tt(t))ue.call(t,n)&&At(e,n,t[n]);return e},g=(e,t)=>oe(e,ae(t));var pe=(e,t)=>{for(var n in t)j(e,n,{get:t[n],enumerable:!0})},le=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ce(t))!vt.call(e,i)&&i!==n&&j(e,i,{get:()=>t[i],enumerable:!(r=se(t,i))||r.enumerable});return e};var de=e=>le(j({},"__esModule",{value:!0}),e);var sn={};pe(sn,{UnifyIntentClient:()=>V});module.exports=de(sn);var I="https://api.unifyintent.com/analytics/v1",U=30,Ct={clickTrackingSelectors:[],navatticProductDemos:{["Navattic Demo Completed"]:!0,["Navattic Demo Started"]:!0,["Navattic Demo Step Viewed"]:!0},defaultForms:{["Default Form Completed"]:!0,["Default Form Page Submitted"]:!0,["Default Meeting Booked"]:!0,["Default Scheduler Closed"]:!0,["Default Scheduler Displayed"]:!0}};var Ee=/^[A-Za-z0-9._+%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+$/,ye=["identify","page"];function J(e){return!!e&&typeof e=="object"&&!Array.isArray(e)&&ye.every(t=>t in e)}function Q(e,t){var n;return((n=t==null?void 0:t.getTime())!=null?n:new Date().getTime())+e*60*1e3}var S=e=>({path:e!=null?e:window.location.pathname,query:_e(window.location.href),referrer:document.referrer,title:document.title,url:e!==void 0?ge({location:window.location,pathname:e}):window.location.href});function ge({location:e,pathname:t}){let n=new URL(e.href);return n.pathname=t,n.toString()}var K=()=>({userAgent:window.navigator.userAgent,userAgentData:typeof navigator.userAgentData!="undefined"?navigator.userAgentData:void 0}),P=e=>{if(Ee.test(e))return e},_e=e=>{let t=new URL(e).searchParams,n={};for(let[r,i]of t.entries())n[r]=i;return n};function x(e){try{return new URL(e.startsWith("http")?e:`https://${e}`).hostname}catch(t){return null}}function b(e){var t;return(t=e.split("@").at(1))!=null?t:null}var Dt=()=>{var n,r,i,o,s;let e=new URL(location.href),t={source:(n=e.searchParams.get("utm_source"))!=null?n:void 0,medium:(r=e.searchParams.get("utm_medium"))!=null?r:void 0,campaign:(i=e.searchParams.get("utm_campaign"))!=null?i:void 0,term:(o=e.searchParams.get("utm_term"))!=null?o:void 0,content:(s=e.searchParams.get("utm_content"))!=null?s:void 0};return g(c({locale:navigator.language},K()),{utm:t})};var tt=class{constructor(t){this.getBaseActivityPayload=()=>({type:this.getActivityType(),visitorId:this._intentContext.identityManager.getOrCreateVisitorId(),sessionId:this._intentContext.sessionManager.getOrCreateSession().sessionId,context:Dt(),timestamp:new Date().toISOString()});this._intentContext=t}track(){this._intentContext.apiClient.post(this.getActivityURL(),this.getTrackPayload())}getTrackPayload(){return c(c({},this.getBaseActivityPayload()),this.getActivityData())}},k=tt;var he=`${I}/page`,v=class extends k{constructor(n,r){super(n);this.getActivityData=()=>{var n;return{type:"page",properties:S((n=this._options)==null?void 0:n.pathname)}};this._options=r}getActivityType(){return"page"}getActivityURL(){return he}};var Te=`${I}/identify`,C=class extends k{constructor(n,{email:r,person:i,company:o}){super(n);this.getActivityData=()=>{var o;let n=this._company&&x((o=this._company)==null?void 0:o.domain),r=b(this._email),i=n&&n===r?this._company:void 0;return c({type:"identify",person:g(c({},this._person),{email:this._email})},i&&{company:this._company})};this._email=r,this._person=i,this._company=o}getActivityType(){return"identify"}getActivityURL(){return Te}};var Ae=`${I}/track`,d=class extends k{constructor(n,{name:r,properties:i}){super(n);this.getActivityData=()=>({type:"track",name:this._name,properties:c(c({},S()),this._properties)});this._name=r,this._properties=i}getActivityType(){return"track"}getActivityURL(){return Ae}};var Y,ve=new Uint8Array(16);function et(){if(!Y&&(Y=typeof crypto!="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Y))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Y(ve)}var f=[];for(let e=0;e<256;++e)f.push((e+256).toString(16).slice(1));function It(e,t=0){return f[e[t+0]]+f[e[t+1]]+f[e[t+2]]+f[e[t+3]]+"-"+f[e[t+4]]+f[e[t+5]]+"-"+f[e[t+6]]+f[e[t+7]]+"-"+f[e[t+8]]+f[e[t+9]]+"-"+f[e[t+10]]+f[e[t+11]]+f[e[t+12]]+f[e[t+13]]+f[e[t+14]]+f[e[t+15]]}var Ce=typeof crypto!="undefined"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),nt={randomUUID:Ce};function De(e,t,n){if(nt.randomUUID&&!t&&!e)return nt.randomUUID();e=e||{};let r=e.random||(e.rng||et)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){n=n||0;for(let i=0;i<16;++i)t[n+i]=r[i];return t}return It(r)}var R=De;function H(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}var Ie={read:function(e){return e[0]==='"'&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function rt(e,t){function n(i,o,s){if(typeof document!="undefined"){s=H({},t,s),typeof s.expires=="number"&&(s.expires=new Date(Date.now()+s.expires*864e5)),s.expires&&(s.expires=s.expires.toUTCString()),i=encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var u in s)s[u]&&(a+="; "+u,s[u]!==!0&&(a+="="+s[u].split(";")[0]));return document.cookie=i+"="+e.write(o,i)+a}}function r(i){if(!(typeof document=="undefined"||arguments.length&&!i)){for(var o=document.cookie?document.cookie.split("; "):[],s={},a=0;a<o.length;a++){var u=o[a].split("="),p=u.slice(1).join("=");try{var E=decodeURIComponent(u[0]);if(s[E]=e.read(p,E),i===E)break}catch(A){}}return i?s[i]:s}}return Object.create({set:n,get:r,remove:function(i,o){n(i,"",H({},o,{expires:-1}))},withAttributes:function(i){return rt(this.converter,H({},this.attributes,i))},withConverter:function(i){return rt(H({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(t)},converter:{value:Object.freeze(e)}})}var it=rt(Ie,{path:"/"});var L=typeof Buffer=="function",Ut=typeof TextDecoder=="function"?new TextDecoder:void 0,St=typeof TextEncoder=="function"?new TextEncoder:void 0,Ue="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",F=Array.prototype.slice.call(Ue),G=(e=>{let t={};return e.forEach((n,r)=>t[n]=r),t})(F),Se=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,m=String.fromCharCode.bind(String),xt=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):e=>new Uint8Array(Array.prototype.slice.call(e,0)),xe=e=>e.replace(/=/g,"").replace(/[+\/]/g,t=>t=="+"?"-":"_"),kt=e=>e.replace(/[^A-Za-z0-9\+\/]/g,""),be=e=>{let t,n,r,i,o="",s=e.length%3;for(let a=0;a<e.length;){if((n=e.charCodeAt(a++))>255||(r=e.charCodeAt(a++))>255||(i=e.charCodeAt(a++))>255)throw new TypeError("invalid character found");t=n<<16|r<<8|i,o+=F[t>>18&63]+F[t>>12&63]+F[t>>6&63]+F[t&63]}return s?o.slice(0,s-3)+"===".substring(s):o},Lt=typeof btoa=="function"?e=>btoa(e):L?e=>Buffer.from(e,"binary").toString("base64"):be,ke=L?e=>Buffer.from(e).toString("base64"):e=>{let n=[];for(let r=0,i=e.length;r<i;r+=4096)n.push(m.apply(null,e.subarray(r,r+4096)));return Lt(n.join(""))};var Le=e=>{if(e.length<2){var t=e.charCodeAt(0);return t<128?e:t<2048?m(192|t>>>6)+m(128|t&63):m(224|t>>>12&15)+m(128|t>>>6&63)+m(128|t&63)}else{var t=65536+(e.charCodeAt(0)-55296)*1024+(e.charCodeAt(1)-56320);return m(240|t>>>18&7)+m(128|t>>>12&63)+m(128|t>>>6&63)+m(128|t&63)}},we=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,Oe=e=>e.replace(we,Le),bt=L?e=>Buffer.from(e,"utf8").toString("base64"):St?e=>ke(St.encode(e)):e=>Lt(Oe(e)),wt=(e,t=!1)=>t?xe(bt(e)):bt(e);var Me=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,Pe=e=>{switch(e.length){case 4:var t=(7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3),n=t-65536;return m((n>>>10)+55296)+m((n&1023)+56320);case 3:return m((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return m((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},Re=e=>e.replace(Me,Pe),Fe=e=>{if(e=e.replace(/\s+/g,""),!Se.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(e.length&3));let t,n="",r,i;for(let o=0;o<e.length;)t=G[e.charAt(o++)]<<18|G[e.charAt(o++)]<<12|(r=G[e.charAt(o++)])<<6|(i=G[e.charAt(o++)]),n+=r===64?m(t>>16&255):i===64?m(t>>16&255,t>>8&255):m(t>>16&255,t>>8&255,t&255);return n},Ot=typeof atob=="function"?e=>atob(kt(e)):L?e=>Buffer.from(e,"base64").toString("binary"):Fe,Ne=L?e=>xt(Buffer.from(e,"base64")):e=>xt(Ot(e).split("").map(t=>t.charCodeAt(0)));var Ve=L?e=>Buffer.from(e,"base64").toString("utf8"):Ut?e=>Ut.decode(Ne(e)):e=>Re(Ot(e)),Be=e=>kt(e.replace(/[-_]/g,t=>t=="-"?"+":"/")),Mt=e=>Ve(Be(e));var ot="test";function st(e){try{return JSON.parse(e)}catch(t){return e}}function at(e){return wt(JSON.stringify(e))}function Pt(e){return st(Mt(e))}function Rt(){try{return localStorage.setItem(ot,ot),localStorage.removeItem(ot),!0}catch(e){return!1}}function Ft(e){return(e!=null?e:window.location.hostname).split(".").slice(-2).join(".")}var ct=class{constructor(t){this.get=t=>{let n=this.retrieveValue(t);return n?st(n):this.legacyGet(t)};this.legacyGet=t=>{let n=this.retrieveValue(this.buildKey(t));return n?Pt(n):null};this.set=(t,n)=>{this.storeValue(t,typeof n=="string"?n:JSON.stringify(n)),this.legacySet(t,n)};this.legacySet=(t,n)=>{this.storeValue(this.buildKey(t),at(n))};this.buildKey=t=>at(`${this._writeKey}_${t}`);this._writeKey=t}},$=ct;var w=class extends ${retrieveValue(t){var r;let n=(r=it.get(t))!=null?r:null;return n&&this.storeValue(t,n),n}storeValue(t,n){it.set(t,n,{domain:`.${Ft()}`,expires:400})}};var W=class extends ${constructor(n){super(n);this.retrieveValue=n=>this._localStorageAvailable?localStorage.getItem(n):null;this.storeValue=(n,r)=>{this._localStorageAvailable&&localStorage.setItem(n,r)};this._localStorageAvailable=Rt()}};var je="anonymousUserId",ut="unify_visitor_id",q=class{constructor(t){this.getOrCreateVisitorId=()=>{if(this._visitorId)return this._visitorId;let t=this.getVisitorId()||this.createVisitorId();return this._visitorId=t,t};this.getVisitorId=()=>{let t=this._storageService.get(ut);if(t)return t;let n=this._storageService.get(je);return n&&this._storageService.set(ut,n),n};this.createVisitorId=()=>{let t=R();return this._storageService.set(ut,t),t};this._storageService=new w(t),this._visitorId=null}};var Ke={durationMinutes:U},Ye="clientSession",Nt="unify_session",He="unify_session_id",z=class{constructor(t,n){this.getOrCreateSession=()=>this.getAndUpdateSession()||this.createSession();this.getAndUpdateSession=()=>{let t=this._currentSession||this.getStoredSession();if(!t)return;if(t.expiration>new Date().getTime())return this.updateSessionExpiration(t)};this.createSession=()=>{var n;let t=c({sessionId:R(),startTime:new Date,expiration:Q((n=this._options.durationMinutes)!=null?n:U),initial:S()},K());return this._currentSession=t,this.setStoredSession(t),t};this.updateSessionExpiration=t=>{var r;let n=g(c({},t),{expiration:Q((r=this._options.durationMinutes)!=null?r:U)});return this._currentSession=n,this.setStoredSession(n),n};this.getStoredSession=()=>{let t=this._storageService.get(Nt);if(t)return t;let n=this._storageService.get(Ye);return n&&this.setStoredSession(n),n};this.setStoredSession=t=>{this._storageService.set(Nt,t),this._cookieStorageService.set(He,t.sessionId)};this._writeKey=t,this._options=n!=null?n:Ke,this._storageService=new W(this._writeKey),this._cookieStorageService=new w(this._writeKey),this._currentSession=null}};var N=class{constructor(t){this.post=(t,n)=>{let r=JSON.stringify(n);if(fetch)fetch(t,{method:"POST",body:r,headers:{"Content-type":"application/json; charset=UTF-8","X-Write-Key":this._writeKey},keepalive:!0}).catch(()=>{});else{let i=new XMLHttpRequest;i.open("POST",t,!0),i.setRequestHeader("Content-type","application/json; charset=UTF-8"),i.setRequestHeader("X-Write-Key",this._writeKey),i.send(r)}};this._writeKey=t}};var Vt="1.9.5";var $e="https://api.unifyintent.com/analytics/v1/_internal/logs";function _({message:e,error:t,attrs:n,apiClient:r}){console.debug(`%c[Unify]: %c${e}${t?`: ${t.message}`:""}${n?`, data: ${JSON.stringify(n)}`:""}`,"font-weight: bold;","");let i=n&&Object.entries(n).reduce((o,[s,a])=>g(c({},o),{[s]:typeof a=="string"?a:JSON.stringify(a)}),{});r==null||r.post($e,{status:"error",message:e,attrs:i,name:t==null?void 0:t.name,stack:t==null?void 0:t.stack,version:Vt})}var Bt="data-unify-track-clicks",jt="unifyTrackClicks",Kt="data-unify-click-event-name",Yt="unifyClickEventName",Ht="unifyLabel",qe="unifyAttr",ze="unifyEventProp",Gt=[qe,ze],$t="unifyExclude",O="https://forms.default.com",X="https://scheduler.default.com",Wt={["default.form_completed"]:O,["deafult.form_page_submitted"]:O,["default.form_page_submitted"]:O,["default.meeting_booked"]:X,["default.scheduler_closed"]:O,["default.scheduler_displayed"]:X},qt="https://capture.navattic.com",zt=["default.form_completed","deafult.form_page_submitted","default.form_page_submitted"];function Xt(e){return!(!(e instanceof HTMLElement)||Xe(e)||e.matches(":disabled")||e.getAttribute("aria-disabled")==="true"||e.classList.contains("disabled")||pt(e,$t))}function Zt(e){let t=lt(e,Ht);if(t)return t;let n=Qt(e);if(n)return Z(n);let r=e.getAttribute("aria-label");if(r)return Z(r);let i=Ze(e);if(i)return Z(i);let o=Je(e);return o?Z(o):null}function Jt(e){if(!(e instanceof HTMLElement))return{};let t={};return Object.entries(e.dataset).forEach(([n,r])=>{Gt.forEach(i=>{if(n.startsWith(i)&&r){let o=n.slice(i.length);o&&(t[`${o.charAt(0).toLowerCase()}${o.slice(1)}`]=r)}})}),t}function Xe(e){if(!(e instanceof HTMLElement))return!1;if(e.hidden||e.getAttribute("aria-hidden")==="true")return!0;let t=getComputedStyle(e);return t.display==="none"||t.visibility==="hidden"}function Z(e,t=80){if(!e)return null;let n=e.replace(/\s+/g," ").trim();return n?n.length>t?n.slice(0,t-1)+"...":n:null}function Qt(e){return e.innerText||e.textContent||""}function Ze(e){let t=e.getAttribute("aria-labelledby");return t?t.split(/\s+/).map(n=>{let r=document.getElementById(n);return r?Qt(r):null}).filter(n=>!!n).join(" "):null}function Je(e){let t=e.querySelector("img[alt]");return(t==null?void 0:t.alt)||null}function pt(e,t){if(!(e instanceof HTMLElement))return!1;let{dataset:n}=e;return n[t]!==void 0}function lt(e,t){if(!(e instanceof HTMLElement))return null;let{dataset:n}=e;return n[t]!==void 0?String(n[t]):null}function te(e,t){var n,r,i,o,s;try{let a=(n=e.properties)!=null?n:[],u=y("email","END_USER",a);if(!u)return;let p=y("fullName","END_USER",a),E=p?p.split(" ")[0]:y("firstName","END_USER",a),A=p?p.split(" ")[1]:y("lastName","END_USER",a),h=y("phone","END_USER",a),l=c(c(c({email:u},E&&{first_name:E}),A&&{last_name:A}),h&&{mobile_phone:h}),T=y("domain","COMPANY_ACCOUNT",a),M=T?x(T):null,B;if(M&&M===b(u)){let ft=(r=y("name","COMPANY_ACCOUNT",a))!=null?r:void 0,mt=(i=y("description","COMPANY_ACCOUNT",a))!=null?i:void 0,Et=(o=y("linkedin","COMPANY_ACCOUNT",a))!=null?o:void 0,yt=y("industry","COMPANY_ACCOUNT",a),gt=y("foundedYear","COMPANY_ACCOUNT",a),_t=(s=y("employeeCount","COMPANY_ACCOUNT",a))!=null?s:void 0,ht=isNaN(Number(_t))?void 0:Number(_t);B=c(c(c(c(c(c({domain:M},ft&&{name:ft}),mt&&{description:mt}),Et&&{linkedin_url:Et}),yt&&{industry:yt}),gt&&{founded:gt}),ht&&{employee_count:ht})}return c({person:l},B&&{company:B})}catch(a){_({message:`Error occurred while parsing attributes from Navattic event payload: ${a}`,error:a,apiClient:t});return}}function y(e,t,n){var r,i;return(i=(r=n.find(({object:o,name:s})=>o===t&&s===e))==null?void 0:r.value)!=null?i:null}function ee({data:e,autoTrackOptions:t,intentContext:n}){var s,a,u,p;if(!t.navatticProductDemos)return;let{["Navattic Demo Started"]:r,["Navattic Demo Step Viewed"]:i,["Navattic Demo Completed"]:o}=t.navatticProductDemos===!0?{["Navattic Demo Started"]:!0,["Navattic Demo Step Viewed"]:!0,["Navattic Demo Completed"]:!0}:t.navatticProductDemos;switch(e.type){case"START_FLOW":{if(!r)return;new d(n,{name:"Navattic Demo Started",properties:{demo:(s=e.flow)==null?void 0:s.name,wasAutoTracked:!0}}).track();return}case"VIEW_STEP":{if(!i)return;new d(n,{name:"Navattic Demo Step Viewed",properties:{demo:(a=e.flow)==null?void 0:a.name,step:(u=e.step)==null?void 0:u.name,wasAutoTracked:!0}}).track();return}case"COMPLETE_FLOW":{if(!o)return;new d(n,{name:"Navattic Demo Completed",properties:{demo:(p=e.flow)==null?void 0:p.name,wasAutoTracked:!0}}).track();return}}}function dt(e){return typeof e!="string"&&zt.includes(e.event)}function ne(e,t){if(dt(e))try{let{email:n,attributes:r}=e.payload;if(!n)return;let i=c({email:n},r&&c(c(c(c({},r.first_name&&{first_name:r.first_name}),r.last_name&&{last_name:r.last_name}),r.phone&&{mobile_phone:r.phone}),r.title&&{title:r.title})),o=r!=null&&r.website?x(r.website):null,s;if(o&&o===b(n)){let a=r&&!isNaN(Number(r.head_count))?Number(r.head_count):void 0;s=c({domain:o},r&&c(c(c({},r.company&&{name:r.company}),r.industry_group&&{industry:r.industry_group}),a&&{employee_count:a}))}return c({person:i},s&&{company:s})}catch(n){_({message:`Error occurred while parsing attributes from Default event payload: ${n}`,error:n,apiClient:t});return}}function re({data:e,autoTrackOptions:t,intentContext:n}){var u,p,E,A;if(!t.defaultForms||typeof e=="string")return null;let{["Default Form Completed"]:r,["Default Form Page Submitted"]:i,["Default Meeting Booked"]:o,["Default Scheduler Closed"]:s,["Default Scheduler Displayed"]:a}=t.defaultForms===!0?{["Default Form Completed"]:!0,["Default Form Page Submitted"]:!0,["Default Meeting Booked"]:!0,["Default Scheduler Closed"]:!0,["Default Scheduler Displayed"]:!0}:t.defaultForms;switch(e.event){case"default.form_completed":return r?(new d(n,{name:"Default Form Completed",properties:{form:e.payload.formName,formId:(u=e.payload.formId)==null?void 0:u.toString(),wasAutoTracked:!0}}).track(),"Default Form Completed"):null;case"deafult.form_page_submitted":case"default.form_page_submitted":return i?(new d(n,{name:"Default Form Page Submitted",properties:{form:e.payload.formName,formId:(p=e.payload.formId)==null?void 0:p.toString(),pageNumber:(E=e.payload.pageNumber)==null?void 0:E.toString(),wasAutoTracked:!0}}).track(),"Default Form Page Submitted"):null;case"default.meeting_booked":{if(!o)return null;let{memberName:h,memberEmail:l,durationInMinutes:T,startDateTime:M}=e.payload;return new d(n,{name:"Default Meeting Booked",properties:{memberName:h,memberEmail:l,durationInMinutes:T==null?void 0:T.toString(),startDateTime:M,wasAutoTracked:!0}}).track(),"Default Meeting Booked"}case"default.scheduler_closed":return s?(new d(n,{name:"Default Scheduler Closed",properties:{wasAutoTracked:!0}}).track(),"Default Scheduler Closed"):null;case"default.scheduler_displayed":return a?(new d(n,{name:"Default Scheduler Displayed",properties:{formId:(A=e.payload.formId)==null?void 0:A.toString(),wasAutoTracked:!0}}).track(),"Default Scheduler Displayed"):null}return null}var D=class{constructor(t){this._monitoredInputs=new Set;this._submittedEmails=new Set;this._historyMonitored=!1;this._isTrackingClicks=!1;this._isSubscribedToThirdPartyMessages=!1;this._justTrackedDefaultEventType=null;this.unmount=()=>{this.stopAutoIdentify(),this.stopAutoPage(),this.stopAutoTrack(),this.unsubscribeFromThirdPartyMessages()};this.startAutoPage=()=>{this._historyMonitored||this.monitorHistory(),this._autoPage=!0};this.stopAutoPage=()=>{this._historyMonitored&&window.removeEventListener("popstate",this.maybeTrackPage),this._autoPage=!1};this.startAutoIdentify=()=>{this._autoIdentify=!0,this.refreshMonitoredInputs(),setInterval(this.refreshMonitoredInputs,2e3)};this.stopAutoIdentify=()=>{this._monitoredInputs.forEach(t=>{t.isConnected&&(t.removeEventListener("blur",this.handleInputBlur),t.removeEventListener("keydown",this.handleInputKeydown))}),this._monitoredInputs.clear(),this._autoIdentify=!1};this.startAutoTrack=t=>{t&&(this._autoTrackOptions=t),this.startTrackingClicks()};this.stopAutoTrack=()=>{this.stopTrackingClicks()};this.monitorHistory=()=>{try{let t=history.pushState;history.pushState=(...r)=>{t.apply(history,r),this.maybeTrackPage()};let n=history.replaceState;history.replaceState=(...r)=>{n.apply(history,r),this.maybeTrackPage()},window.addEventListener("popstate",this.maybeTrackPage),this._historyMonitored=!0}catch(t){this.logError("Error occurred in monitorHistory",t)}};this.maybeTrackPage=()=>{if(this._autoPage)try{(!this._lastLocation||en(this._lastLocation,window.location))&&(new v(this._intentContext).track(),this._lastLocation=c({},window.location))}catch(t){this.logError("Error occurred in maybeTrackPage",t)}};this.startTrackingClicks=()=>{this._isTrackingClicks||(document.addEventListener("click",this.handleDocumentClick),this._isTrackingClicks=!0)};this.stopTrackingClicks=()=>{this._isTrackingClicks&&(document.removeEventListener("click",this.handleDocumentClick),this._isTrackingClicks=!1)};this.handleDocumentClick=t=>{var n;try{let r=t.target;if(!r||typeof r.closest!="function")return;let i=`[${Bt}]`,o=`[${Kt}]`,s=(n=this._autoTrackOptions.clickTrackingSelectors)!=null?n:[],a=[i,o,...s.map(l=>typeof l=="string"?l:l.selector)],u=r.closest(a.join(", "));if(!u||!(u instanceof HTMLElement)||!Xt(u))return;let p=pt(u,jt)?"Element Clicked":null,E=lt(u,Yt),A=s.map(l=>{var T;return typeof l=="string"?p||E?null:u.matches(l)?"Element Clicked":null:u.matches(l.selector)?(p||E)&&!l.eventName?null:(T=l.eventName)!=null?T:"Element Clicked":null});[E,...A].filter(l=>!!l).forEach(l=>{this.maybeTrackClick({element:u,eventName:l})}),p&&this.maybeTrackClick({element:u,eventName:p,isLegacy:!0})}catch(r){this.logError("Error occurred in handleDocumentClick",r)}};this.refreshMonitoredInputs=()=>{if(this._autoIdentify)try{this._monitoredInputs.forEach(n=>{n.isConnected||this._monitoredInputs.delete(n)}),Array.from(document.getElementsByTagName("input")).filter(n=>!this._monitoredInputs.has(n)&&nn(n)).forEach(n=>{n.addEventListener("blur",this.handleInputBlur),n.addEventListener("keydown",this.handleInputKeydown),this._monitoredInputs.add(n)})}catch(t){this.logError("Error occurred in refreshMonitoredInputs",t)}};this.subscribeToThirdPartyMessages=()=>{this._isSubscribedToThirdPartyMessages||window.addEventListener("message",this.handleThirdPartyMessage),this._isSubscribedToThirdPartyMessages=!0};this.unsubscribeFromThirdPartyMessages=()=>{this._isSubscribedToThirdPartyMessages&&window.removeEventListener("message",this.handleThirdPartyMessage),this._isSubscribedToThirdPartyMessages=!1};this.handleThirdPartyMessage=t=>{let n;try{switch(t.origin){case O:case X:{n="Default",this.handleDefaultFormMessage(t);break}case qt:{n="Navattic",this.handleNavatticDemoMessage(t);break}}}catch(r){this.logError(`Error occurred in handleThirdPartyMessage for third-party ${n}`,r)}};this.handleDefaultFormMessage=t=>{try{if(typeof t.data=="string"||t.origin!==Wt[t.data.event])return;if(this._autoIdentify&&dt(t.data)){let n=t.data.payload.email;n&&this.maybeIdentifyInputEmail(n,ne(t.data,this._intentContext.apiClient))}if(this._autoTrackOptions.defaultForms){if(t.data.event===this._justTrackedDefaultEventType)return;re({data:t.data,autoTrackOptions:this._autoTrackOptions,intentContext:this._intentContext})&&(this._justTrackedDefaultEventType=t.data.event,setTimeout(()=>{this._justTrackedDefaultEventType=null},500))}}catch(n){this.logError("Error occurred in handleDefaultFormMessage",n)}};this.handleNavatticDemoMessage=t=>{var n,r;try{if(this._autoIdentify){let o=((r=(n=t.data)==null?void 0:n.properties)!=null?r:[]).find(({object:s,name:a})=>s==="END_USER"&&a==="email");o!=null&&o.value&&this.maybeIdentifyInputEmail(o.value,te(t.data,this._intentContext.apiClient))}this._autoTrackOptions.navatticProductDemos&&ee({data:t.data,autoTrackOptions:this._autoTrackOptions,intentContext:this._intentContext})}catch(i){this.logError("Error occurred in handleNavatticDemoMessage",i)}};this.handleInputBlur=t=>{if(this._autoIdentify)try{t.target instanceof HTMLInputElement&&this.maybeIdentifyInputEmail(t.target.value)}catch(n){this.logError("Error occurred in handleInputBlur",n)}};this.handleInputKeydown=t=>{if(this._autoIdentify)try{t.key==="Enter"&&t.target instanceof HTMLInputElement&&this.maybeIdentifyInputEmail(t.target.value)}catch(n){this.logError("Error occurred in handleInputKeyDown",n)}};this.maybeIdentifyInputEmail=(t,n)=>{if(this._autoIdentify)try{if(t){if(!P(t)||this._submittedEmails.has(t))return;new C(this._intentContext,{email:t,person:n==null?void 0:n.person,company:n==null?void 0:n.company}).track(),this._submittedEmails.add(t)}}catch(r){this.logError("Error occurred in maybeIdentifyInputEmail",r)}};this.maybeTrackClick=({element:t,eventName:n,isLegacy:r=!1})=>{try{let i=Zt(t);if(!i)return;let o=Jt(t);new d(this._intentContext,{name:n,properties:g(c(g(c({},o),{label:i}),r&&{elementName:i}),{wasAutoTracked:!0})}).track()}catch(i){this.logError("Error occurred in maybeTrackClick",i)}};this.logError=(t,n)=>{_({message:`UnifyIntentAgent: ${t}`,error:n,apiClient:this._intentContext.apiClient})};this.__getMonitoredInputs=()=>this._monitoredInputs;this.__getSubmittedEmails=()=>this._submittedEmails;var n,r;this._intentContext=t,this._autoPage=(n=t.clientConfig.autoPage)!=null?n:!1,this._autoIdentify=(r=t.clientConfig.autoIdentify)!=null?r:!1,this._autoTrackOptions=c({},t.clientConfig.autoTrackOptions),this._autoPage&&(this.startAutoPage(),this.maybeTrackPage()),this._autoIdentify&&this.startAutoIdentify(),this.startAutoTrack(),this.subscribeToThirdPartyMessages()}};function en(e,t){return e.hostname!==t.hostname||e.pathname!==t.pathname}function nn(e){return e.type==="email"||e.type==="text"}var rn={autoPage:!1,autoIdentify:!1,sessionDurationMinutes:U,autoTrackOptions:Ct};function ie(){return{identify:[],page:[],track:[]}}var V=class{constructor(t,n=rn){this._mounted=!1;this._eventBuffers=ie();this.isMounted=()=>this._mounted;this.mount=()=>{if(typeof window!="undefined")try{if(J(window.unify)||J(window.unifyBrowser)){_({message:"UnifyIntentClient already exists on window, a new one will not be created."});return}let t=new N(this._writeKey),n=new z(this._writeKey,{durationMinutes:this._config.sessionDurationMinutes});n.getOrCreateSession();let r=new q(this._writeKey);r.getOrCreateVisitorId(),this._context={writeKey:this._writeKey,clientConfig:this._config,apiClient:t,sessionManager:n,identityManager:r},this._intentAgent=new D(this._context),this._mounted=!0,on(this,t),this._eventBuffers.identify.forEach(i=>this.identify(...i)),this._eventBuffers.page.forEach(i=>this.page(...i)),this._eventBuffers.track.forEach(i=>this.track(...i)),this._eventBuffers=ie(),window.unify=this,window.unifyBrowser=this}catch(t){this.logError("Error occurred in mount",t)}};this.unmount=()=>{var t;if(typeof window!="undefined")try{this._config.autoPage&&this.stopAutoPage(),this._config.autoIdentify&&this.stopAutoIdentify(),this.stopAutoTrack(),(t=this._intentAgent)==null||t.unmount(),this._mounted=!1,window.unify=void 0,window.unifyBrowser=void 0}catch(n){this.logError("Error occurred in unmount",n)}};this.page=t=>{if(!this._mounted){this._eventBuffers.page.push([t]);return}try{new v(this._context,t).track()}catch(n){this.logError("Error occurred in page",n)}};this.getPagePayload=t=>{if(this._mounted)try{return new v(this._context,t).getTrackPayload()}catch(n){this.logError("Error occurred in getPagePayload",n)}};this.identify=(t,n)=>{try{let r=P(t);if(r)return this._mounted?(new C(this._context,{email:r,person:n==null?void 0:n.person,company:n==null?void 0:n.company}).track(),!0):(this._eventBuffers.identify.push([t,n]),!0)}catch(r){this.logError("Error occurred in identify",r)}return!1};this.getIdentifyPayload=(t,n)=>{if(!this._mounted)return!1;try{let r=P(t);if(r)return new C(this._context,{email:r,person:n==null?void 0:n.person,company:n==null?void 0:n.company}).getTrackPayload()}catch(r){this.logError("Error occurred in getIdentifyPayload",r)}};this.track=(t,n)=>{if(!this._mounted){this._eventBuffers.track.push([t,n]);return}try{new d(this._context,{name:t,properties:n}).track()}catch(r){this.logError("Error occurred in track",r)}};this.getTrackPayload=(t,n)=>{if(this._mounted)try{return new d(this._context,{name:t,properties:n}).getTrackPayload()}catch(r){this.logError("Error occurred in getTrackPayload",r)}};this.startAutoPage=()=>{if(this._mounted)try{this._intentAgent||(this._intentAgent=new D(this._context)),this._intentAgent.startAutoPage()}catch(t){this.logError("Error occurred in startAutoPage",t)}};this.stopAutoPage=()=>{var t;if(this._mounted)try{(t=this._intentAgent)==null||t.stopAutoPage()}catch(n){this.logError("Error occurred in stopAutoPage",n)}};this.startAutoIdentify=()=>{if(this._mounted)try{this._intentAgent||(this._intentAgent=new D(this._context)),this._intentAgent.startAutoIdentify()}catch(t){this.logError("Error occurred in startAutoIdentify",t)}};this.stopAutoIdentify=()=>{var t;if(this._mounted)try{(t=this._intentAgent)==null||t.stopAutoIdentify()}catch(n){this.logError("Error occurred in stopAutoIdentify",n)}};this.startAutoTrack=t=>{if(this._mounted)try{t&&(this._config.autoTrackOptions=t),this._intentAgent||(this._intentAgent=new D(this._context)),this._intentAgent.startAutoTrack(t)}catch(n){this.logError("Error occurred in startAutoTrack",n)}};this.stopAutoTrack=()=>{var t;if(this._mounted)try{(t=this._intentAgent)==null||t.stopAutoTrack()}catch(n){this.logError("Error occurred in stopAutoTrack",n)}};this.logError=(t,n)=>{_({message:`UnifyIntentClient: ${t}`,error:n,apiClient:this._context.apiClient})};this.__getEventBuffers=()=>this._eventBuffers;this._writeKey=t,this._config=n}};function on(e,t){(Array.isArray(window.unify)?[...window.unify]:Array.isArray(window.unifyBrowser)?[...window.unifyBrowser]:[]).forEach(([r,i])=>{if(typeof e[r]=="function")try{Array.isArray(i)?e[r].call(e,...i):e[r].call(e)}catch(o){_({message:`Error occurred while flushing queue: ${o==null?void 0:o.message}`,error:o,apiClient:t})}})} /*! Bundled license information: js-cookie/dist/js.cookie.mjs: (*! js-cookie v3.0.5 | MIT *) */