@mrrocket/sdk 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +47 -3
- package/dist/api-client.d.ts +12 -5
- package/dist/api-client.js +12 -8
- package/dist/api-client.js.map +1 -1
- package/dist/api.d.ts +4 -1
- package/dist/api.js +2 -1
- package/dist/api.js.map +1 -1
- package/dist/batch.d.ts +6 -4
- package/dist/batch.js +3 -3
- package/dist/batch.js.map +1 -1
- package/dist/browser/mrrocket-flows.js +9 -2
- package/dist/browser/mrrocket-forms.js +1 -1
- package/dist/browser/mrrocket-messenger.js +42 -43
- package/dist/browser/mrrocket-push.js +1 -1
- package/dist/browser/mrrocket-replay.js +3 -3
- package/dist/browser/mrrocket.js +1 -1
- package/dist/client.d.ts +10 -2
- package/dist/client.js +36 -15
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +5 -1
- package/dist/context.js.map +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/errors.d.ts +5 -1
- package/dist/errors.js +8 -2
- package/dist/errors.js.map +1 -1
- package/dist/flows-ui.d.ts +1 -1
- package/dist/flows-ui.js +64 -14
- package/dist/flows-ui.js.map +1 -1
- package/dist/flows-web.d.ts +2 -0
- package/dist/flows-web.js +4 -1
- package/dist/flows-web.js.map +1 -1
- package/dist/flows.d.ts +59 -3
- package/dist/flows.js +88 -7
- package/dist/flows.js.map +1 -1
- package/dist/forms.d.ts +4 -0
- package/dist/forms.js +4 -1
- package/dist/forms.js.map +1 -1
- package/dist/identity.d.ts +42 -0
- package/dist/identity.js +24 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/messenger-ui.d.ts +12 -2
- package/dist/messenger-ui.js +58 -47
- package/dist/messenger-ui.js.map +1 -1
- package/dist/messenger.js +3 -2
- package/dist/messenger.js.map +1 -1
- package/dist/push-web.d.ts +2 -13
- package/dist/push-web.js +4 -2
- package/dist/push-web.js.map +1 -1
- package/dist/react-native/index.d.cts +105 -14
- package/dist/react-native/index.d.ts +105 -14
- package/dist/react-native/index.js +238 -55
- package/dist/react-native/index.js.map +1 -1
- package/dist/replay.d.ts +4 -1
- package/dist/replay.js +8 -2
- package/dist/replay.js.map +1 -1
- package/dist/server.d.ts +2 -0
- package/dist/server.js +2 -0
- package/dist/server.js.map +1 -1
- package/dist/styles-css.d.ts +1 -1
- package/dist/styles-css.js +40 -41
- package/dist/styles-css.js.map +1 -1
- package/dist/user-hash.d.ts +27 -0
- package/dist/user-hash.js +24 -0
- package/dist/user-hash.js.map +1 -0
- package/package.json +5 -1
package/dist/browser/mrrocket.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(){'use strict';var an=Object.defineProperty;var cn=(e,n,r)=>n in e?an(e,n,{enumerable:true,configurable:true,writable:true,value:r}):e[n]=r;var be=(e,n,r)=>cn(e,typeof n!="symbol"?n+"":n,r);var Et=e=>{let n=0;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);s<128?n+=1:s<2048?n+=2:s>=55296&&s<=56319&&r+1<e.length&&(e.charCodeAt(r+1)&64512)===56320?(n+=4,r++):n+=3;}return n},ln=(e,n,r)=>{let s=`{"key":${JSON.stringify(e)},"sdk":${JSON.stringify(r)},"events":[`,l=Et(s)+2,c=[],p=[],R=[],E=l,h=()=>{p.length&&c.push({body:`${s}${p.join(",")}]}`,events:R}),p=[],R=[],E=l;};for(let S of n){let m=JSON.stringify(S),w=Et(m)+1;l+w>6e4||((p.length===100||E+w>6e4)&&h(),p.push(m),R.push(S),E+=w);}return h(),c},_t=(e,n,r)=>ln(e,n,r).map(s=>s.body);var ve=class{constructor(n=1e3,r=30,s=3){be(this,"windowMs",n);be(this,"radius",r);be(this,"count",s);be(this,"clicks",[]);be(this,"fired",false);}push(n,r,s){let l=this.clicks.filter(c=>s-c.t<=this.windowMs&&Math.hypot(c.x-n,c.y-r)<=this.radius);return l.length!==this.clicks.length&&(this.fired=false),this.clicks=[...l,{x:n,y:r,t:s}],this.clicks.length>=this.count&&!this.fired?(this.fired=true,true):false}};var dn='a[href],button,input,select,textarea,label,summary,[role="button"],[role="link"],[role="tab"],[role="menuitem"],[role="checkbox"],[role="switch"],[onclick],[data-ck-goal]',un="[data-ck-mask]",fn="[data-ck-block]",St=/\d{4,}|^[a-z]{1,3}-[a-z0-9]{5,}$|^_|__|css-|^sc-|^jsx-/i,pn=e=>{let n=e.tagName.toLowerCase();if(e.id&&!St.test(e.id)&&e.id.length<=40)return `${n}#${e.id}`;let r=typeof e.className=="string"?e.className.split(/\s+/).filter(c=>c&&!St.test(c)&&c.length<=30&&!c.includes(":")):[],s=r.length?`${n}.${r.slice(0,2).join(".")}`:n,l=e.parentElement?[...e.parentElement.children].filter(c=>c.tagName===e.tagName):[];return l.length>1?`${s}:nth-of-type(${l.indexOf(e)+1})`:s},gn=e=>{let n=[],r=e;for(;r&&n.length<3&&r.tagName&&r.tagName!=="BODY"&&r.tagName!=="HTML";){let s=pn(r);if(n.unshift(s),s.includes("#"))break;r=r.parentElement;}return n.join(" > ").slice(0,160)},$e=e=>(e!=null?e:"").replace(/\s+/g," ").trim().slice(0,40),mn=e=>{var r,s,l,c,p;if(e.closest(`${un},${fn}`))return "";let n=e.tagName.toLowerCase();if(n==="input"){let R=((r=e.getAttribute("type"))!=null?r:"text").toLowerCase();return $e(R==="submit"||R==="button"?(s=e.getAttribute("aria-label"))!=null?s:e.value:e.getAttribute("aria-label"))}return $e(n==="select"||n==="textarea"?e.getAttribute("aria-label"):(p=(c=(l=e.getAttribute("aria-label"))!=null?l:e.getAttribute("title"))!=null?c:e.innerText)!=null?p:e.textContent)},Ot=e=>{var c,p;let n=e.target instanceof Element?e.target:null;if(!n)return null;let r=n.closest(dn),s=r!=null?r:n,l=document.documentElement;return {x:Math.round(e.clientX),y:Math.round(e.clientY+window.scrollY),vw:window.innerWidth,vh:window.innerHeight,docH:Math.max(l.scrollHeight,(p=(c=document.body)==null?void 0:c.scrollHeight)!=null?p:0),selector:gn(s),label:r?mn(r):"",interactive:!!r}},It=()=>{var r,s;let e=document.documentElement,n=Math.max(e.scrollHeight,(s=(r=document.body)==null?void 0:r.scrollHeight)!=null?s:0);return n?Math.min(100,Math.round((window.scrollY+window.innerHeight)/n*100)):0};var Ne="0.15.0",wn=(e,n)=>{let r=n.trim().toLowerCase();for(let[s,l]of Object.entries(e))if(s.toLowerCase()===r)return l},hn=(e,n)=>{let r=e.trim().toLowerCase(),s=n.trim().toLowerCase();return s.startsWith("@")?r.endsWith(s):r===s},kn=(e,n)=>{if(e.op==="in cohort")return false;let r=wn(n,e.property),s=r==null?"":String(r);if(e.op==="\u2265"){let c=Number(s),p=Number(e.values[0]);return s!==""&&Number.isFinite(c)&&Number.isFinite(p)&&c>=p}let l=s!==""&&e.values.some(c=>hn(s,c));return e.op==="is"||e.op==="in"?l:!l},yn=(e,n,r={})=>{var R;if(!e.on)return false;let s={id:n,...r},l=e.sets.length?e.sets.find(E=>E.conditions.every(h=>kn(h,s))):{rollout:100};if(!l||Ft(`${e.key}:rollout:${n}`)*100>=l.rollout)return false;if(!((R=e.variants)!=null&&R.length))return true;let c=Ft(`${e.key}:variant:${n}`)*100,p=0;for(let E of e.variants)if(p+=E.split,c<p)return E.key;return e.variants[e.variants.length-1].key},tt=(e,n,r,s={})=>{var c;let l=(c=n==null?void 0:n.flags)==null?void 0:c.find(p=>p.key===e);return l?yn(l,r,s):false},bn=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],Pt="ck_preview",Mt="ck_embed",ue="ck_id",Ce="ck_sid";var Cn=e=>{var r;let n={};for(let s of bn){let l=(r=e(s))==null?void 0:r.trim();l&&(n[s]=l.slice(0,150));}return n},$t=e=>{let n=new URLSearchParams(e);return Cn(r=>n.get(r))};var xn=e=>{let n=2166136261;for(let r=0;r<e.length;r++)n^=e.charCodeAt(r),n=Math.imul(n,16777619);return (n>>>0)/4294967296},Ft=e=>{let n=2166136261;for(let r=0;r<e.length;r++)n^=e.charCodeAt(r),n=Math.imul(n,16777619);return n^=n>>>16,n=Math.imul(n,2246822507),n^=n>>>13,n=Math.imul(n,3266489909),n^=n>>>16,(n>>>0)/4294967296},Rn=(e,n)=>{var c,p,R,E;let r=(p=(c=e.variants[0])==null?void 0:c.id)!=null?p:"control";if(e.winner)return e.winner;if(e.status!=="running")return r;let s=xn(`${e.key}:${n}`),l=0;for(let h of e.variants)if(l+=h.weight,s<l)return h.id;return (E=(R=e.variants[e.variants.length-1])==null?void 0:R.id)!=null?E:r},At=e=>{let n=Array.isArray(e)?e[0]:e;if(!n)return {};let r={};for(let s of n.split(",")){let[l,c]=s.split(":");l&&c&&(r[l.trim()]=c.trim());}return r};var _e=(e,n,r,s)=>{if(s[e])return s[e];let l=n==null?void 0:n.experiments.find(c=>c.key===e);return l?Rn(l,r):"control"},Nt=(e,n,r)=>{var l,c,p,R,E,h;let s={...(l=e==null?void 0:e.texts)!=null?l:{}};for(let S of (c=e==null?void 0:e.experiments)!=null?c:[]){let m=_e(S.key,e,n,r);m!==((R=(p=S.variants[0])==null?void 0:p.id)!=null?R:"control")&&Object.assign(s,(h=(E=S.variants.find(w=>w.id===m))==null?void 0:E.changes)!=null?h:{});}return s},Ee="ck_x",Ae=e=>e.replace(/\/+$/,"")||"/",Lt=(e,n,r,s={})=>{var R,E;if(!e)return null;let l;try{l=new URL(n);}catch(h){return null}if(l.searchParams.has(Ee))return null;let c=Ae(l.pathname),p=(h,S)=>{let m;try{m=new URL(h,l);}catch(w){return}if(!(!/^https?:$/.test(m.protocol)||m.origin===l.origin&&Ae(m.pathname)===c))return l.searchParams.forEach((w,O)=>{m.searchParams.has(O)||m.searchParams.set(O,w);}),S&&m.searchParams.set(Ee,S),m.hash||(m.hash=l.hash),m.href};for(let h of (R=e.redirects)!=null?R:[]){let S=h.from&&Ae(h.from)===c?p(h.to):void 0;if(S)return {to:S}}for(let h of e.experiments){if(!h.path||Ae(h.path)!==c)continue;let S=h.status==="running"&&!h.winner;if(S&&r===null&&!s[h.key])return null;let m=_e(h.key,e,r!=null?r:"",s),w=(E=h.variants.find(M=>M.id===m))==null?void 0:E.url,O=w?p(w,S?`${h.key}:${m}`:void 0):void 0;return S?{to:O,experiment:h.key,variant:m}:O?{to:O}:null}return null},Tt=(e,n)=>{let[r,s]=(n!=null?n:"").split(":"),l=e==null?void 0:e.experiments.find(c=>c.key===r);return l&&l.variants.some(c=>c.id===s)?{experiment:r,variant:s}:null};var nt=()=>typeof crypto!="undefined"&&"randomUUID"in crypto?crypto.randomUUID():`ck_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;var Se=(e,n)=>e.length>n?`${e.slice(0,n-1)}\u2026`:e,vn=e=>{var n;if(e instanceof Error)return {type:e.name||"Error",message:Se(e.message||String(e),1e3),stack:e.stack?Se(e.stack,8192):void 0};if(typeof e=="string")return {type:"Error",message:Se(e,1e3)};try{return {type:"Error",message:Se((n=JSON.stringify(e))!=null?n:String(e),1e3)}}catch(r){return {type:"Error",message:String(e)}}},Ut=e=>{let n=[],r=[],s=new Set,l=0,c=`${e.host}/api/sdk/errors`,p=(w=false)=>{for(;n.length;){let O=JSON.stringify({key:e.apiKey,errors:n.splice(0,4)});w&&typeof navigator!="undefined"&&"sendBeacon"in navigator&&navigator.sendBeacon(c,O)||fetch(c,{method:"POST",headers:{"content-type":"application/json"},body:O,keepalive:true}).then(L=>{!L.ok&&L.status!==429&&e.warn(`Error reports were rejected with ${L.status}. Check the public key and NEXT_PUBLIC_MRROCKET_HOST.`);}).catch(()=>{});}},R=(w,O="manual")=>{let M=e.context();if(!M.send||l>=20)return;let L=vn(w);if(/\/api\/sdk\/errors/.test(L.message))return;let N=`${L.type}:${L.message}`;s.has(N)||(s.add(N),l++,n.push({...L,mechanism:O,handled:O==="manual",url:window.location.href,ts:Date.now(),crumbs:r.slice(),...e.release?{release:e.release}:{},...M.distinctId?{distinctId:M.distinctId}:{},...M.sessionId?{sessionId:M.sessionId}:{}}));},E=w=>{var O;!w.error&&(!w.message||w.message==="Script error.")||R((O=w.error)!=null?O:new Error(w.message),"onerror");},h=w=>{var O;return R((O=w.reason)!=null?O:new Error("Unhandled promise rejection"),"onunhandledrejection")},S=()=>p(true);window.addEventListener("error",E),window.addEventListener("unhandledrejection",h),window.addEventListener("pagehide",S);let m=window.setInterval(()=>p(),2e3);return {capture:R,crumb:(w,O)=>{r.push({ts:Date.now(),type:w,message:Se(O,120)}),r.length>20&&r.shift();},stop:()=>{window.removeEventListener("error",E),window.removeEventListener("unhandledrejection",h),window.removeEventListener("pagehide",S),window.clearInterval(m),p(true);}}};var Oe="$cancel_flow",ie="$onboarding",rt="$inapp",En={version:0,question:"",reasons:[],offers:{},confirm:{title:"Cancel your subscription?",body:"You keep access until the end of the billing period.",button:"Cancel subscription"},offersFor:"business"},_n="Something went wrong. Please try again.",Dt="mrrocket:onboarding",Te=e=>e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),jt=new Set(["signed_up","signup","sign_up","registered","account_created","user_signed_up"]),ot=(e,n)=>{let r=Te(e),s=Te(n);return !r||!s?false:r===s||jt.has(r)&&jt.has(s)},Sn=e=>/^(first (launch|visit|open|session|login|sign ?in|app open)|app (opened|launched)|on load|every visit|always)?$/i.test(e.trim()),On=()=>`cf_${Math.random().toString(36).slice(2,10)}${Date.now().toString(36)}`;var In=e=>{let n=(e!=null?e:"").trim();return /^https?:\/\//i.test(n)||/^\/(?!\/)/.test(n)?n:void 0},fe=e=>{var n;return (n=e.nodes)!=null?n:e.steps},Fn=e=>Math.max(0,e.amount)*(e.unit==="hours"?36e5:864e5),Pn=(e,n)=>{let r=e.trim(),s=(n.split(/[?#]/)[0]||"/").replace(/\/+$/,"")||"/";if(!r)return false;if(r.endsWith("*")){let l=r.slice(0,-1).replace(/\/+$/,"");return !l||s===l||s.startsWith(`${l}/`)}return s===(r.replace(/\/+$/,"")||"/")},st=e=>e.flatMap(n=>n.kind==="condition"?[...st(n.yes),...st(n.no)]:n.kind==="wait"?[]:[n]),Mn=(e,n=Date.now())=>e==null||e===""?NaN:Math.floor((n-new Date(e).getTime())/2630016e3),Le=e=>e==null?void 0:e.trim().toLowerCase(),$n=({when:e={}},n)=>(e.answer==null||Le(e.answer)===Le(n.answer))&&(e.plan==null||[e.plan].flat().some(r=>Le(r)===Le(n.plan)))&&!(n.months>=e.tenureUnder)&&!(n.months<e.tenureOver)&&(e.tenureUnder==null||n.months>=0)&&(e.tenureOver==null||n.months>=0),Ht=e=>{let n=null,r=null,s=null,l=[],c=false,p=null,R,E=null,h=new Map,S=new Set,m=new Set,w=new Set,O=e.auto!==false,M=new Set,L=()=>{var t,i;return (i=(t=e.now)==null?void 0:t.call(e))!=null?i:Date.now()},N=null,J=()=>{var t;return (t=n==null?void 0:n.onboarding)!=null?t:[]},Q=t=>t?J().find(i=>i.id===t):void 0,K=t=>{let i=h.get(t);return i||h.set(t,i={done:new Set,dismissed:false,answers:new Map,at:new Map,reached:new Map}),i},Z=false,B=t=>{e.track(ie,t),Z=true;},ae=(t,i)=>{t.done.add(i),t.at.set(i,L());},Xe=t=>{var i,a,g;if((i=t.page)!=null&&i.trim()){let d=(a=e.path)==null?void 0:a.call(e);return d===void 0?false:Pn(t.page,d)}if((g=t.event)!=null&&g.trim()){if(!c)return;for(let d of M)if(ot(t.event,d))return true;return false}return false},pe=(t,i,a,g,d=0,C)=>{var _,k;for(let b=0;b<i.length;b++){let x=i[b];if(x.kind==="wait"){if(a.done.has(x.id)){C=(_=a.at.get(x.id))!=null?_:C;continue}let I=a.reached.get(x.id);if(I===void 0){if(!g)return {at:"pending"};I=C!=null?C:L(),a.reached.set(x.id,I),B({flow:t.id,step:x.id,kind:"wait",action:"shown"});}let V=I+Fn(x);if(L()<V)return {at:"wait",until:V};if(!g)return {at:"pending"};ae(a,x.id),B({flow:t.id,step:x.id,kind:"wait",action:"completed"}),C=V;continue}if(x.kind==="condition"){let I=a.answers.get(x.id);if(I===void 0){if(!g)return {at:"pending"};if(I=Xe(x),I===void 0)return {at:"pending"};a.answers.set(x.id,I),B({flow:t.id,step:x.id,kind:"condition",action:"answered",answer:I?"yes":"no"});}return pe(t,I?x.yes:x.no,a,g,d,C)}if(!a.done.has(x.id))return {at:"step",step:x,line:i,index:b,before:d};C=(k=a.at.get(x.id))!=null?k:C,d++;}return {at:"end"}},ce=t=>{let i=h.get(t.id);return !!i&&(i.dismissed||pe(t,fe(t),i,false).at==="end")},ge=t=>`${Dt}:${t!=null?t:"visitor"}`,H=t=>`${Dt}:events:${t!=null?t:"visitor"}`,q=()=>{var a;Z=false;let t=(a=e.storage)==null?void 0:a.call(e);if(!t)return;let i={};for(let[g,d]of h)i[g]={done:[...d.done],...d.dismissed?{dismissed:true}:{},...d.answers.size?{answers:Object.fromEntries([...d.answers].map(([C,_])=>[C,_?"yes":"no"]))}:{},...d.at.size?{at:Object.fromEntries(d.at)}:{},...d.reached.size?{reached:Object.fromEntries(d.reached)}:{}};try{t.set(ge(e.personId()),JSON.stringify(i)),M.size&&t.set(H(e.personId()),JSON.stringify([...M].slice(-200)));}catch(g){}},P=t=>{var i,a,g,d;for(let[C,_]of Object.entries(t!=null?t:{})){let k=K(C);for(let b of (i=_.done)!=null?i:[])k.done.add(b);_.dismissed&&(k.dismissed=true);for(let[b,x]of Object.entries((a=_.answers)!=null?a:{}))k.answers.has(b)||k.answers.set(b,x==="yes");for(let[b,x]of Object.entries((g=_.at)!=null?g:{}))typeof x=="number"&&!k.at.has(b)&&k.at.set(b,x);for(let[b,x]of Object.entries((d=_.reached)!=null?d:{}))typeof x=="number"&&(!k.reached.has(b)||x<k.reached.get(b))&&k.reached.set(b,x);}},ee=t=>{var a;N&&clearTimeout(N),N=null;let i=t-L();i>0&&i<=864e5&&(N=setTimeout(()=>(N=null,$()),i+50),(a=N.unref)==null||a.call(N));},me=false,le=()=>{me=false;let t=Q(s);if(!t)return null;let i=K(t.id);if(i.dismissed)return null;let a=pe(t,fe(t),i,true);if(Z&&q(),a.at==="wait"&&ee(a.until),me=a.at==="wait"||a.at==="pending",a.at!=="step")return null;let{step:g,line:d,index:C}=a,_=I=>!!I&&I.kind!=="wait"&&I.kind!=="condition";if(g.kind==="checklist"){let I=C;for(;I>0&&_(d[I-1])&&d[I-1].kind==="checklist";)I--;let V=C;for(;V+1<d.length&&_(d[V+1])&&d[V+1].kind==="checklist";)V++;let he=d.slice(I,V+1).filter(_);for(let te of he)!i.done.has(te.id)&&!m.has(`s:${te.id}`)&&(m.add(`s:${te.id}`),e.track(ie,{flow:t.id,step:te.id,kind:"checklist",action:"shown"}));return {type:"checklist",flow:t,items:he.map(te=>({step:te,done:i.done.has(te.id)}))}}m.has(`s:${g.id}`)||(m.add(`s:${g.id}`),e.track(ie,{flow:t.id,step:g.id,kind:g.kind,action:"shown"}));let k=d.slice(C+1),b=k.findIndex(I=>I.kind==="condition"),x=(b<0?k:k.slice(0,b)).filter(_).length;return {type:"step",flow:t,step:g,index:a.before,total:a.before+1+x,last:!x&&b<0}},de=()=>{var a,g;if(r){let d=r,C=(a=d.flow.followUps)==null?void 0:a[d.reason],_=C?1:0,k=d.plain?1:3+_+((g=d.flow.second)!=null&&g[d.reason]?1:0);return {type:"cancel",screen:d.screen,flow:d.flow,reason:d.reason,...d.screen==="followup"&&C?{followUp:C,answer:d.answer}:{},offer:d.screen==="offer"?d.offer:void 0,...d.screen==="offer"?{round:d.round}:{},price:d.options.price,busy:d.busy,error:d.error,step:d.screen==="survey"?1:d.screen==="followup"?2:d.screen==="offer"?1+_+d.round:k,steps:k}}let t=le();if(t)return t;s&&!me&&(s=null);let i=l.find(d=>!S.has(d.id));return i?{type:"message",message:i}:null},$=()=>{let t=de();(t==null?void 0:t.type)==="message"&&!m.has(`m:${t.message.id}`)&&(m.add(`m:${t.message.id}`),e.track(rt,{message:t.message.id,journey:t.message.journey,action:"shown"}));for(let i of [...w])try{i();}catch(a){}},G=t=>s===t.id?true:s&&Q(s)&&!ce(Q(s))?false:(s=t.id,e.track(ie,{flow:t.id,action:"started"}),$(),true),xe=()=>{var i;if(!O||s||!c||!e.personId()&&!((i=e.storage)!=null&&i.call(e)))return;let t=J().find(a=>Sn(a.trigger)&&fe(a).length&&!ce(a));t&&G(t);},Pe=()=>{let t=e.personId();E!==null&&E!==t&&(h.clear(),M.clear(),S.clear(),s=null,R=void 0),E=t;let i=(async()=>{var d,C,_;let a=(d=e.storage)==null?void 0:d.call(e);if(a)try{let k=await a.get(ge(t));k&&P(JSON.parse(k));let b=await a.get(H(t));if(b)for(let x of JSON.parse(b))typeof x=="string"&&M.add(x);}catch(k){}let g=J().length>0||!!(n!=null&&n.messages);if(t&&g&&R!==t){R=t;let k=await e.fetchInApp(t).catch(()=>null);if(k&&e.personId()===t){P(k.onboarding);for(let b of (C=k.events)!=null?C:[])typeof b=="string"&&M.add(Te(b));l=((_=k.messages)!=null?_:[]).filter(b=>b&&b.id&&b.title);}}t||(l=[]),c=true,xe(),$();})();return p=i.finally(()=>{p===i&&(p=null);}),p},U=t=>t.round>1?{round:2}:t.rule>=0?{rule:t.rule}:{},j=t=>{var g,d,C,_;let i={answer:t.answer,plan:t.options.plan,months:Mn(t.options.customerSince,(g=e.now)==null?void 0:g.call(e))},a=(C=(d=t.flow.rules)==null?void 0:d[t.reason])!=null?C:[];t.rule=a.findIndex(k=>$n(k,i)),t.offer=t.rule<0?t.flow.offers[t.reason]:(_=a[t.rule].offer)!=null?_:void 0,t.round=1,t.screen=t.offer?"offer":"confirm";},W=(t,i,a)=>{var d;let g=t.screen==="offer"?t.offer:void 0;return {outcome:i,run:t.run,...t.reason?{reason:t.reason,reasonLabel:(d=t.flow.reasons.find(C=>C.id===t.reason))==null?void 0:d.label}:{},...t.answer?{answer:t.answer}:{},...i==="saved"&&g?{offer:g}:{},...a!=null&&a.trim()?{comment:a.trim().slice(0,500)}:{}}},ne=(t,i)=>{var a;e.track(Oe,{action:"finished",run:t.run,version:t.flow.version,outcome:i.outcome,customer:(a=t.options.customer)!=null?a:"consumer",...i.reason?{reason:i.reason}:{},...i.answer?{answer:i.answer}:{},...i.offer?{offer:i.offer.kind,...U(t)}:{},...i.comment?{comment:i.comment}:{}}),r===t&&(r=null),t.resolve(i),$();},we=(t,i,a)=>{if(t.busy)return;let g=W(t,i,a),d=i==="saved"?t.options.onSave:t.options.onCancel;t.busy=true,t.error=void 0,$(),Promise.resolve().then(()=>d==null?void 0:d(g)).then(()=>ne(t,g),()=>{t.busy=false,t.error=_n,$();});};return {setConfig:t=>{n=t,s&&!Q(s)&&(s=null),$();},refresh:Pe,onEvent:t=>{var _;if(!t||t.startsWith("$"))return;let i=Te(t),a=!!i&&!M.has(i);a&&M.add(i);let g=Q(s),d=false;if(g){let k=K(g.id);for(let b of st(fe(g)))b.kind==="checklist"&&b.event&&!k.done.has(b.id)&&ot(b.event,t)&&(ae(k,b.id),d=true,e.track(ie,{flow:g.id,step:b.id,kind:b.kind,action:"completed"}));}if(d||a&&g?(q(),$()):a&&q(),!O||!e.personId()&&!((_=e.storage)!=null&&_.call(e)))return;let C=J().find(k=>fe(k).length&&ot(k.trigger,t)&&!ce(k));C&&G(C);},openCancelFlow:(t={})=>{var _,k;if(r)return r.promise;let i=(_=n==null?void 0:n.cancelFlow)!=null?_:En,a=t.customer!=="business"||i.reasons.length<2,g=()=>{},d=new Promise(b=>g=b),C={flow:i,options:t,plain:a,screen:a?"confirm":"survey",round:1,run:On(),busy:false,resolve:g,promise:d};return r=C,e.track(Oe,{action:"shown",run:C.run,version:i.version,customer:(k=t.customer)!=null?k:"consumer",plain:a}),$(),d},startOnboarding:t=>{let i=t?Q(t):J().find(g=>fe(g).length&&!ce(g));if(!i||!fe(i).length)return false;let a=K(i.id);return a.dismissed=false,G(i)},view:de,subscribe:t=>(w.add(t),()=>w.delete(t)),cancel:{pick:t=>{!r||r.busy||r.screen!=="survey"||!r.flow.reasons.some(i=>i.id===t)||(r.reason!==t&&(r.answer=void 0),r.reason=t,r.error=void 0,$());},answer:t=>{let i=r;if(!i||i.busy||i.screen!=="followup")return;let a=t.slice(0,500);i.answer=a.trim()?a:void 0,$();},next:()=>{var i,a;let t=r;if(!(!t||!t.reason)){if(t.screen==="survey")e.track(Oe,{action:"answered",run:t.run,version:t.flow.version,reason:t.reason}),(i=t.flow.followUps)!=null&&i[t.reason]?t.screen="followup":j(t);else if(t.screen==="followup")t.answer=(a=t.answer)==null?void 0:a.trim(),j(t);else return;$();}},accept:t=>{var a;let i=r;!i||i.screen!=="offer"||!i.reason||(i.busy||e.track(Oe,{action:"offer",run:i.run,version:i.flow.version,reason:i.reason,offer:(a=i.offer)==null?void 0:a.kind,...U(i),outcome:"accepted"}),we(i,"saved",t));},decline:()=>{var a,g;let t=r;if(!t||t.screen!=="offer"||t.busy)return;e.track(Oe,{action:"offer",run:t.run,version:t.flow.version,reason:t.reason,offer:(a=t.offer)==null?void 0:a.kind,...U(t),outcome:"declined"});let i=t.round===1&&t.reason?(g=t.flow.second)==null?void 0:g[t.reason]:void 0;i?(t.offer=i,t.rule=void 0,t.round=2):t.screen="confirm",t.error=void 0,$();},confirm:t=>{let i=r;!i||i.screen!=="confirm"||we(i,"cancelled",t);},close:()=>{var a,g;let t=r;if(!t||t.busy)return;let i=W(t,"kept");(g=(a=t.options).onClose)==null||g.call(a,i),ne(t,i);}},onboarding:{next:()=>{let t=le();(t==null?void 0:t.type)==="step"&&(ae(K(t.flow.id),t.step.id),e.track(ie,{flow:t.flow.id,step:t.step.id,kind:t.step.kind,action:"completed"}),q(),$());},check:t=>{let i=le();if((i==null?void 0:i.type)!=="checklist")return;let a=i.items.find(g=>g.step.id===t);!a||a.done||(ae(K(i.flow.id),t),e.track(ie,{flow:i.flow.id,step:t,kind:"checklist",action:"completed"}),q(),$());},dismiss:()=>{let t=le();!t||t.type!=="step"&&t.type!=="checklist"||(K(t.flow.id).dismissed=true,e.track(ie,{flow:t.flow.id,...t.type==="step"?{step:t.step.id}:{},action:"dismissed"}),s=null,q(),$());}},message:{click:()=>{var a;let t=de();if((t==null?void 0:t.type)!=="message")return;S.add(t.message.id),e.track(rt,{message:t.message.id,journey:t.message.journey,action:"clicked"});let i=In(t.message.url);$(),i&&((a=e.openUrl)==null||a.call(e,i));},dismiss:()=>{let t=de();(t==null?void 0:t.type)==="message"&&(S.add(t.message.id),e.track(rt,{message:t.message.id,journey:t.message.journey,action:"dismissed"}),$());}}}};var An="ck_pick",Nn="ck_origin",Ue=e=>typeof CSS!="undefined"&&CSS.escape?CSS.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,n=>`\\${n}`),Ln=e=>[...e.classList].filter(n=>n.length<30&&!/\d{2,}|[_-][a-z0-9]{5,}$|^(is|has)-|hover|active|focus|open|selected|:|\[/.test(n)).slice(0,2),Kt=e=>{let n=e.ownerDocument,r=p=>{try{return n.querySelectorAll(p).length===1}catch(R){return false}},s=e.getAttribute("data-ck-target");if(s)return `[data-ck-target="${s.replace(/"/g,'\\"')}"]`;if(e.id&&!/\d{3,}/.test(e.id)&&r(`#${Ue(e.id)}`))return `#${Ue(e.id)}`;let l=[],c=e;for(;c&&c!==n.documentElement&&l.length<6;){if(c!==e&&c.id&&!/\d{3,}/.test(c.id)){l.unshift(`#${Ue(c.id)}`);break}let p=c.tagName.toLowerCase(),R=Ln(c).map(w=>`.${Ue(w)}`).join(""),E=c.parentElement,h=E?[...E.children].filter(w=>w.tagName===c.tagName):[],S=h.length>1?`:nth-of-type(${h.indexOf(c)+1})`:"";l.unshift(`${p}${R}${S}`);let m=l.join(" > ");if(r(m))return m;c=E;}return l.join(" > ")},Wt=()=>{var S;if(typeof window=="undefined"||window.top===window)return null;let e=new URLSearchParams(window.location.search);if(e.get(An)!=="1")return null;let n;try{n=new URL((S=e.get(Nn))!=null?S:"").origin;}catch(m){return null}if(!/^https?:\/\//.test(n))return null;let r=m=>window.parent.postMessage(m,n),s=document.createElement("div");s.setAttribute("aria-hidden","true"),Object.assign(s.style,{position:"fixed",zIndex:"2147483647",pointerEvents:"none",border:"2px solid #0ea5e9",background:"rgba(14,165,233,.12)",borderRadius:"6px",transition:"all 60ms linear",display:"none"});let l=document.createElement("div");Object.assign(l.style,{position:"absolute",left:"-2px",bottom:"calc(100% + 4px)",font:"600 11px/1.4 system-ui, sans-serif",color:"#fff",background:"#0c4a6e",padding:"2px 6px",borderRadius:"4px",whiteSpace:"nowrap",maxWidth:"360px",overflow:"hidden",textOverflow:"ellipsis"}),s.appendChild(l),document.body.appendChild(s);let c=null,p=m=>{if(c=m&&m!==s&&!s.contains(m)?m:null,!c){s.style.display="none";return}let w=c.getBoundingClientRect();Object.assign(s.style,{display:"block",left:`${w.left-2}px`,top:`${w.top-2}px`,width:`${w.width+4}px`,height:`${w.height+4}px`}),l.textContent=Kt(c);},R=m=>p(document.elementFromPoint(m.clientX,m.clientY)),E=m=>{var O,M;m.preventDefault(),m.stopPropagation();let w=(O=document.elementFromPoint(m.clientX,m.clientY))!=null?O:c;!w||w===s||r({type:"mrrocket:picked",selector:Kt(w),text:((M=w.textContent)!=null?M:"").trim().replace(/\s+/g," ").slice(0,80)});},h=m=>{m.key==="Escape"&&r({type:"mrrocket:pick-cancel"});};return window.addEventListener("mousemove",R,true),window.addEventListener("click",E,true),window.addEventListener("keydown",h,true),r({type:"mrrocket:pick-ready"}),()=>{window.removeEventListener("mousemove",R,true),window.removeEventListener("click",E,true),window.removeEventListener("keydown",h,true),s.remove();}};var Tn={get:e=>{try{return window.localStorage.getItem(e)}catch(n){return null}},set:(e,n)=>{try{window.localStorage.setItem(e,n);}catch(r){}}},Vt=()=>{try{for(let e=window.localStorage.length-1;e>=0;e--){let n=window.localStorage.key(e);n!=null&&n.startsWith("mrrocket:onboarding")&&window.localStorage.removeItem(n);}}catch(e){}},Bt=e=>({track:e.track,personId:e.personId,auto:e.auto,storage:()=>e.canStore()?Tn:null,openUrl:n=>window.location.assign(n),path:()=>window.location.pathname,fetchInApp:async n=>{if(!e.apiKey)return null;let r=await fetch(`${e.host}/api/sdk/inapp?key=${encodeURIComponent(e.apiKey)}&distinctId=${encodeURIComponent(n)}`);return r.ok?await r.json():null}});var He="mrr_ref",Ke="mrr_ref",Un="mrr_ref",Dn="mrr_click";var Ie=/^[A-Za-z0-9_-]{1,64}$/;var jn=(e,n="ref")=>{let r=new URLSearchParams(e);return Hn(s=>r.get(s),n)},Hn=(e,n="ref")=>{let r=e(Un);if(r&&Ie.test(r)){let l=e(Dn);return {code:r,clickId:l&&Ie.test(l)?l:null,direct:false}}let s=e(n);return s&&Ie.test(s)?{code:s,clickId:null,direct:true}:null},qt=e=>{var n;return `${e.code}.${(n=e.clickId)!=null?n:""}.${e.at}`},De=(e,n=60,r=Date.now())=>{if(!e)return null;let[s,l,c]=e.split("."),p=Number(c);return !s||!Ie.test(s)||!Number.isFinite(p)||l&&!Ie.test(l)||r-p>n*864e5||p>r+864e5?null:{code:s,clickId:l||null,at:p}};var D=null,We=()=>typeof document!="undefined",Yt=e=>{var r;if(!We())return;let n=(r=document.cookie.split("; ").find(s=>s.startsWith(`${e}=`)))==null?void 0:r.slice(e.length+1);try{return n?decodeURIComponent(n):void 0}catch(s){return n}},Ve=()=>{try{return typeof localStorage=="undefined"?null:localStorage}catch(e){return null}},it=()=>{var e,n;return D||(We()?(n=De(Yt(He),3650))!=null?n:De((e=Ve())==null?void 0:e.getItem(Ke),3650):null)};var je=(e,n)=>{var l;if(!We())return;let r=Math.max(1,Math.round(n))*86400,s=typeof location!="undefined"&&location.protocol==="https:"?"; secure":"";document.cookie=`${He}=${encodeURIComponent(qt(e))}; path=/; max-age=${r}; samesite=lax${s}`;try{(l=Ve())==null||l.setItem(Ke,qt(e));}catch(c){}},Be=()=>{var e;if(We()){document.cookie=`${He}=; path=/; max-age=0; samesite=lax`;try{(e=Ve())==null||e.removeItem(Ke);}catch(n){}}},Xt=()=>{D=null;},zt=async e=>{var s,l,c;let n=jn(e.search,e.param),r=(s=e.now)!=null?s:Date.now();if(!n)return !D&&e.store&&(D=(c=De(Yt(He),e.days,r))!=null?c:De((l=Ve())==null?void 0:l.getItem(Ke),e.days,r),D||Be()),D;if(D={code:n.code,clickId:n.clickId,at:r},e.store&&je(D,e.days),e.beacon)try{let p=await e.beacon({code:n.code,clickId:n.clickId});p&&D&&D.code===n.code&&!D.clickId&&(D={...D,clickId:p},e.store&&je(D,e.days));}catch(p){}return D},Jt=e=>e==="$identify"||!e.startsWith("$");var at=3600*24*365,Zt=e=>{var r;if(typeof document=="undefined")return;let n=(r=document.cookie.split("; ").find(s=>s.startsWith(`${e}=`)))==null?void 0:r.slice(e.length+1);if(n)try{return decodeURIComponent(n)}catch(s){return n}},qe=(e,n,r)=>{let s=window.location.protocol==="https:"?"; secure":"";document.cookie=`${e}=${encodeURIComponent(n)}; path=/; max-age=${r}; samesite=lax${s}`;},Fe=e=>{document.cookie=`${e}=; path=/; max-age=0; samesite=lax`;},A={utm:{}},Qt=()=>{var e;return (e=A.id)!=null?e:A.id=nt()},ct=(e,n)=>{if(e!=="cookies")return Qt();let r=Zt(ue);if(r)return A.id=r;let s=Qt();return qe(ue,s,at),s},lt=e=>{var l;let n=Date.now(),r=A.session,s=(l=e?Zt(Ce):void 0)!=null?l:r&&n-r.last<18e5?r.id:nt();return A.session={id:s,last:n},e&&qe(Ce,s,18e5/1e3),s},dt=()=>{var r;let e=window.location.href;if(A.url===e)return;A.referrer=(r=A.url)!=null?r:document.referrer||void 0,A.url=e;let n=$t(window.location.search);Object.keys(n).length&&(A.utm=n);},en=()=>{let e=navigator,n=window;return e.doNotTrack==="1"||n.doNotTrack==="1"||e.globalPrivacyControl===true};var Ye=window,Wn=()=>{var e,n;return (n=(e=document.currentScript)!=null?e:document.querySelector('script[data-key][src*="sdk"]'))!=null?n:document.querySelector("script[data-key][src*='mrrocket']")},tn=new Set,z=e=>{tn.has(e)||(tn.add(e),console.warn(`[MRRocket] ${e}`));},Vn=()=>{var bt,Ct,xt,Rt;let e=Wn(),n=o=>{var u;return (u=e==null?void 0:e.getAttribute(`data-${o}`))!=null?u:void 0},r=(o,u)=>{let f=n(o);return f===void 0?u:!["false","0","off","no"].includes(f.trim().toLowerCase())},s=(bt=e==null?void 0:e.src)!=null?bt:"",l="";try{l=s?new URL(s,window.location.href).origin:"";}catch(o){l="";}let c=((Ct=n("key"))!=null?Ct:"").trim(),p=((xt=n("api-host"))!=null?xt:l).trim().replace(/\/+$/,""),R=n("consent"),E=r("respect-dnt",false),h=r("heatmaps",true),S=r("errors",true),m=n("release"),w=n("attribution"),O=w==="always"||w==="off"?w:"consent",M=n("referral-param")||"ref",L={},N=(o,u)=>{var f;return (f=L[o])!=null?f:L[o]=new Promise((y,v)=>{var vt;let F=()=>Ye[u];if(F())return y(F());let X=(vt=n(`${o}-src`))!=null?vt:s?s.replace(/(\.min)?\.js(\?[^#]*)?(#.*)?$/,`-${o}$1.js?v=${Ne}`):"";if(!X)return v(new Error(o));let se=document.createElement("script");se.async=true,se.src=X,se.onload=()=>F()?y(F()):v(new Error(o)),se.onerror=()=>v(new Error(o)),document.head.appendChild(se);}).catch(y=>{throw L[o]=void 0,y})},J=n("theme"),Q={theme:J==="light"||J==="dark"?J:"auto",accent:n("accent")},K=new URLSearchParams(window.location.search),Z=At(K.get(Pt)),B=K.get(Mt)==="1";B&&Wt();let ae=K.get(Ee);if(ae!==null){K.delete(Ee);let o=K.toString();history.replaceState(history.state,"",`${window.location.pathname}${o?`?${o}`:""}${window.location.hash}`);}let Xe=en(),pe=R==="cookies"||R==="off"?R:"cookieless",ce=r("replay",false),ge="",H,q,P=null,ee=false,me=false,le=null,de=null,$=window.location.pathname,G=[],xe=new Set,Pe=[],U=()=>E&&Xe?"off":pe,j=()=>!B&&U()!=="off",W=()=>H!=null?H:ge,ne=()=>U()==="cookies"?W():H;c||z('No public key. Add data-key="mrr_pub_\u2026" to the script tag; nothing is tracked until then.');let we=(o=false)=>{if(!G.length)return;if(!c){G.length=0;return}let u=`${p}/api/sdk/events`;for(let f of _t(c,G.splice(0),{v:Ne,errors:S,platform:"web"}))o&&"sendBeacon"in navigator&&navigator.sendBeacon(u,f)||fetch(u,{method:"POST",headers:{"content-type":"application/json"},body:f,keepalive:true}).then(v=>{v.ok||z(`Events were rejected with ${v.status}. Check data-key (MRRocket \u203A Settings \u203A Products).`);}).catch(()=>z(`Could not reach ${p||"this origin"} to send events. Check data-api-host.`));},T=null,Y=null,t=(o,u,f=Date.now(),y)=>{if(!j())return;let v=Jt(o)?it():null;G.push({event:o,props:v?{...u,$referral:{code:v.code,clickId:v.clickId}}:u,distinctId:ne(),sessionId:lt(U()==="cookies"),ts:f,url:y!=null?y:window.location.href,referrer:A.referrer,...A.utm,screen:{w:window.screen.width,h:window.screen.height}});},i=(o,u)=>{typeof o!="string"||!o||(t(o,u),j()&&(T==null||T.event(o)),a.onEvent(o));},a=Ht(Bt({host:p,apiKey:c,track:t,personId:()=>j()?H:void 0,canStore:()=>U()==="cookies",auto:r("onboarding",true)})),g=false,d;a.subscribe(()=>{g||!a.view()||B||(g=true,N("flows","__mrrocketFlows").then(o=>o.mountFlows(a,Q)).catch(()=>{g=false,z("The cancel flow and onboarding dialogs did not load. Check that sdk-flows.js is served next to sdk.js.");}));});let C=(o,u)=>{if(!j())return;let f=`${window.location.pathname}|${o}`;xe.has(f)||(xe.add(f),i("$exposure",{experiment:o,variant:u}));},_=()=>{let o=Lt(P,window.location.href,W(),Z);return o!=null&&o.to?(we(true),window.location.replace(o.to),true):(o!=null&&o.experiment&&C(o.experiment,o.variant),false)},k=()=>{if(!P)return;let o=document.querySelectorAll("[data-ck-text]");if(!o.length)return;let u=Nt(P,W(),Z),f=new Set;o.forEach(y=>{var X,se;let v=y.dataset.ckText;if(!v)return;f.add(v),y.dataset.ckDefault===void 0&&(y.dataset.ckDefault=(X=y.textContent)!=null?X:"");let F=(se=u[v])!=null?se:y.dataset.ckDefault;y.textContent!==F&&(y.textContent=F);});for(let y of P.experiments)y.variants.some(v=>{var F;return Object.keys((F=v.changes)!=null?F:{}).some(X=>f.has(X))})&&C(y.key,_e(y.key,P,W(),Z));},b=()=>{var o,u;return (u=(o=P==null?void 0:P.referral)==null?void 0:o.cookieDays)!=null?u:60},x=()=>O==="always"?U()!=="off":O==="consent"&&U()==="cookies",I=null,V=false,he=()=>{if(!ee||B)return;if(O==="off"||U()==="off"){Xt(),(O==="off"||V)&&Be();return}let o=window.location.href;I!==o&&(I=o,zt({search:window.location.search,param:M,store:x(),days:b(),beacon:c?({code:u,clickId:f})=>fetch(`${p}/api/sdk/affiliate/click`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({key:c,code:u,clickId:f,url:o,referrer:document.referrer||void 0}),keepalive:true}).then(y=>y.ok?y.json():null).then(y=>{var v;return (v=y==null?void 0:y.clickId)!=null?v:null}):void 0}));},te=()=>{let o=x(),u=it();o&&u?je(u,b()):!o&&V&&Be(),V=o;},ut=0,ft=false,pt=()=>{var y,v;let o=j()&&ce&&!!(P!=null&&P.replay)&&!!c;if(o===ft)return;ft=o;let u=++ut;if(!o){T==null||T.stop(true),T=null;return}let f=(v=(y=P==null?void 0:P.replay)==null?void 0:y.sampleRate)!=null?v:.1;N("replay","__mrrocketReplay").then(F=>F.startReplay({host:p,apiKey:c,sessionId:lt(U()==="cookies"),distinctId:ne(),identified:!!H,sampleRate:f,warn:z})).then(F=>{u!==ut?F==null||F.stop(true):T=F;}).catch(()=>z("Session recording could not start (the recorder did not load)."));},gt=r("messenger",false),re=null,ke=o=>{B||c&&(re!=null||(re=N("messenger","__mrrocketMessenger").then(u=>{var F;let f=X=>n(`messenger-${X}`)===void 0?void 0:r(`messenger-${X}`,true),y=n("messenger-position"),v=(F=n("messenger-theme"))!=null?F:J;return u.mountMessenger({host:p,apiKey:c,distinctId:W,user:()=>q,launcher:gt,position:y,corners:n("messenger-corners"),header:n("messenger-header"),font:n("messenger-font"),title:n("messenger-title"),greeting:n("messenger-greeting"),label:n("messenger-label"),askEmail:f("ask-email"),help:f("help"),sound:f("sound"),preview:f("preview"),theme:v==="light"||v==="dark"||v==="auto"?v:void 0,accent:n("accent")})})),re.then(o).catch(()=>{re=null,z("sdk-messenger.js did not load.");}));},mt=n("forms")==="auto",ze=false,Je=()=>{ze||!c||B||!document.querySelector(mt?"form":"form[data-mrrocket-form]")||(ze=true,N("forms","__mrrocketForms").then(o=>o.watchForms({host:p,apiKey:c,auto:mt,distinctId:()=>j()?ne():void 0,identified:()=>!!H,identify:yt,tracking:j,referrer:()=>A.referrer,utm:()=>A.utm})).catch(()=>ze=false));},Ge=()=>{!me||!j()||de===window.location.pathname||(de=window.location.pathname,i("$pageview",{path:window.location.pathname}));},oe=null,wt=()=>{let o=oe;h&&o&&o.max>0&&t("$scroll",{depth:o.max,docH:o.docH,vw:window.innerWidth,vh:window.innerHeight},Date.now(),o.url),oe=null;},Re=()=>{var v,F;if(!h||!j()||B)return;let o=document.documentElement,u=Math.max(o.scrollHeight,(F=(v=document.body)==null?void 0:v.scrollHeight)!=null?F:0),f=It(),y=window.location.href;(oe==null?void 0:oe.url)!==y?oe={url:y,max:f,docH:u}:f>oe.max&&(oe={url:y,max:f,docH:u});},ht=()=>{let o=window.location.pathname;o!==$&&($=o,!(ee&&_())&&(wt(),dt(),T==null||T.page(o),Y==null||Y.crumb("navigation",o),Ge(),he(),window.setTimeout(()=>{Re(),k(),Je();},0)));},kt=()=>{let o=U(),u=le;le=o,u==="cookies"&&o!=="cookies"&&(Fe(ue),Fe(Ce)),o==="off"&&(G.length=0,A.session=void 0),u==="cookies"&&o!=="cookies"&&Vt(),ge=ct(o),te(),he(),pt(),Ge(),Re();},rn=o=>{let{analytics:u,replay:f}=typeof o=="string"?{analytics:o,replay:void 0}:o!=null?o:{};if(u!==void 0&&u!=="cookieless"&&u!=="cookies"&&u!=="off"){z(`setConsent: "${String(u)}" is not a consent mode. Use "cookieless", "cookies" or "off".`);return}u==="off"&&(G.length=0),u&&(pe=u),typeof f=="boolean"&&(ce=f),kt(),ee&&a.refresh();},yt=(o,u)=>{if(typeof o!="string"||!o)return;let f=ne();H=o,t("$identify",{...u,id:o,...f&&f!==o?{previousId:f}:{}}),T==null||T.identify(o),U()==="cookies"&&qe(ue,o,at),q={...u,id:o},k(),ee&&a.refresh();},Me={track:i,identify:yt,reset:()=>{H=void 0,q=void 0,xe.clear(),U()==="cookies"&&(Fe(ue),Fe(Ce)),A.id=void 0,A.session=void 0,ge=ct(U()),k(),ee&&a.refresh();},captureError:o=>Y==null?void 0:Y.capture(o,"manual"),setConsent:rn,getFlag:o=>tt(o,P,W(),{...q})!==false,getFlagVariant:o=>{let u=tt(o,P,W(),{...q});return typeof u=="string"?u:null},getVariant:o=>{let u=_e(o,P,W(),Z);return (P||Z[o])&&C(o,u),u},ready:o=>{typeof o=="function"&&(ee?window.setTimeout(()=>o(Me),0):Pe.push(o));},getDistinctId:W,cancelFlow:{open:o=>a.openCancelFlow(o)},onboarding:{start:o=>a.startOnboarding(o)},openCancelFlow:o=>a.openCancelFlow(o),startOnboarding:o=>a.startOnboarding(o),paywall:{open:(o,u)=>(d!=null?d:d=N("flows","__mrrocketFlows").then(f=>f.paywallHost({config:()=>P,distinctId:W,track:t},Q))).then(f=>f.open(o,u))},push:{subscribe:o=>{let u=j()?H:void 0;if(!u)return Promise.resolve({status:"not-signed-in"});let f=window.Notification,y=Promise.resolve(f&&f.permission==="default"&&(o==null?void 0:o.ask)!==false?f.requestPermission():f==null?void 0:f.permission);return N("push","__mrrocketPush").then(v=>v.subscribeWebPush({host:p,apiKey:c,distinctId:u,permission:y},o))},unsubscribe:()=>N("push","__mrrocketPush").then(o=>o.unsubscribeWebPush({host:p,apiKey:c,distinctId:H}))},messenger:{open:o=>ke(u=>u.open(o)),close:()=>{re==null?void 0:re.then(o=>o.close()).catch(()=>{});},toggle:()=>ke(o=>o.toggle())},openMessenger:()=>ke(o=>o.open()),version:Ne};dt(),kt();let ye=Ye.mrrocket,on=(Rt=ye==null?void 0:ye.q)!=null?Rt:[],Qe=ye&&typeof ye=="object"?ye:{};Object.assign(Qe,Me,{__loaded:true}),delete Qe.q,Ye.mrrocket=Qe;for(let[o,u]of on){let f=Me[o];if(typeof f=="function")try{f(...Array.from(u!=null?u:[]));}catch(y){console.error(y);}}me=true,Ge(),S&&c&&!B&&(Y=Ut({host:p,apiKey:c,release:m,context:()=>{var o;return {send:j(),distinctId:ne(),sessionId:(o=A.session)==null?void 0:o.id}},warn:z}),Y.crumb("navigation",window.location.pathname));for(let o of ["pushState","replaceState"]){let u=history[o];history[o]=function(...f){let y=u.apply(this,f);return ht(),y};}window.addEventListener("popstate",ht);let sn=new ve;document.addEventListener("click",o=>{var F;o.target instanceof Element&&o.target.closest("[data-ck-messenger]")&&(o.preventDefault(),ke(X=>X.open()));let u=o.target instanceof Element?o.target.closest("[data-ck-goal]"):null;if(u!=null&&u.dataset.ckGoal&&i(u.dataset.ckGoal,{text:(F=u.textContent)==null?void 0:F.trim().slice(0,80)}),!j())return;let f=Ot(o);if(!f)return;let y=sn.push(f.x,f.y,Date.now());if((f.label||f.selector)&&(Y==null||Y.crumb("click",f.label||f.selector)),T==null||T.click(f,y),!h)return;let v={x:f.x,y:f.y,vw:f.vw,vh:f.vh,docH:f.docH,selector:f.selector,label:f.label,dead:!f.interactive};t("$click",v),y&&t("$rageclick",v);});let Ze=0;window.addEventListener("scroll",()=>{Ze||(Ze=window.requestAnimationFrame(()=>{Ze=0,Re();}));},{passive:true}),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>Re()):Re(),window.setInterval(()=>we(),2e3),window.addEventListener("pagehide",()=>{wt(),we(true);});let et=()=>{if(ee=true,_())return;let o=Tt(P,ae);o&&C(o.experiment,o.variant),document.documentElement.classList.remove("ck-hide"),he(),pt(),a.setConfig(P),a.refresh(),gt&&(document.body?ke():document.addEventListener("DOMContentLoaded",()=>ke())),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{k(),Je();}):(k(),Je());for(let u of Pe.splice(0))try{u(Me);}catch(f){console.error(f);}};c?fetch(`${p}/api/sdk/config?key=${encodeURIComponent(c)}`).then(o=>(o.ok||z(`Config request to ${p||"this origin"} answered ${o.status}. Check data-key and data-api-host.`),o.ok?o.json():null)).then(o=>{o&&Array.isArray(o.experiments)&&(P=o),et();}).catch(()=>{z(`Could not reach ${p||"this origin"}. Check data-api-host. The page keeps its own texts and flags stay off.`),et();}):et();},nn;typeof window!="undefined"&&typeof document!="undefined"&&!((nn=Ye.mrrocket)!=null&&nn.__loaded)&&Vn();
|
|
1
|
+
(function(){'use strict';var wn=Object.defineProperty;var hn=(e,n,r)=>n in e?wn(e,n,{enumerable:true,configurable:true,writable:true,value:r}):e[n]=r;var _e=(e,n,r)=>hn(e,typeof n!="symbol"?n+"":n,r);var It=e=>{let n=0;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);s<128?n+=1:s<2048?n+=2:s>=55296&&s<=56319&&r+1<e.length&&(e.charCodeAt(r+1)&64512)===56320?(n+=4,r++):n+=3;}return n},kn=(e,n,r,s)=>{let c=`{"key":${JSON.stringify(e)},${s?`"userHash":${JSON.stringify(s)},`:""}"sdk":${JSON.stringify(r)},"events":[`,l=It(c)+2,g=[],v=[],S=[],b=l,O=()=>{v.length&&g.push({body:`${c}${v.join(",")}]}`,events:S}),v=[],S=[],b=l;};for(let w of n){let C=JSON.stringify(w),_=It(C)+1;l+_>6e4||((v.length===100||b+_>6e4)&&O(),v.push(C),S.push(w),b+=_);}return O(),g},Ft=(e,n,r,s)=>kn(e,n,r,s).map(c=>c.body);var Fe=class{constructor(n=1e3,r=30,s=3){_e(this,"windowMs",n);_e(this,"radius",r);_e(this,"count",s);_e(this,"clicks",[]);_e(this,"fired",false);}push(n,r,s){let c=this.clicks.filter(l=>s-l.t<=this.windowMs&&Math.hypot(l.x-n,l.y-r)<=this.radius);return c.length!==this.clicks.length&&(this.fired=false),this.clicks=[...c,{x:n,y:r,t:s}],this.clicks.length>=this.count&&!this.fired?(this.fired=true,true):false}};var yn='a[href],button,input,select,textarea,label,summary,[role="button"],[role="link"],[role="tab"],[role="menuitem"],[role="checkbox"],[role="switch"],[onclick],[data-ck-goal]',bn="[data-ck-mask]",xn="[data-ck-block]",$t=/\d{4,}|^[a-z]{1,3}-[a-z0-9]{5,}$|^_|__|css-|^sc-|^jsx-/i,Cn=e=>{let n=e.tagName.toLowerCase();if(e.id&&!$t.test(e.id)&&e.id.length<=40)return `${n}#${e.id}`;let r=typeof e.className=="string"?e.className.split(/\s+/).filter(l=>l&&!$t.test(l)&&l.length<=30&&!l.includes(":")):[],s=r.length?`${n}.${r.slice(0,2).join(".")}`:n,c=e.parentElement?[...e.parentElement.children].filter(l=>l.tagName===e.tagName):[];return c.length>1?`${s}:nth-of-type(${c.indexOf(e)+1})`:s},Rn=e=>{let n=[],r=e;for(;r&&n.length<3&&r.tagName&&r.tagName!=="BODY"&&r.tagName!=="HTML";){let s=Cn(r);if(n.unshift(s),s.includes("#"))break;r=r.parentElement;}return n.join(" > ").slice(0,160)},He=e=>(e!=null?e:"").replace(/\s+/g," ").trim().slice(0,40),vn=e=>{var r,s,c,l,g;if(e.closest(`${bn},${xn}`))return "";let n=e.tagName.toLowerCase();if(n==="input"){let v=((r=e.getAttribute("type"))!=null?r:"text").toLowerCase();return He(v==="submit"||v==="button"?(s=e.getAttribute("aria-label"))!=null?s:e.value:e.getAttribute("aria-label"))}return He(n==="select"||n==="textarea"?e.getAttribute("aria-label"):(g=(l=(c=e.getAttribute("aria-label"))!=null?c:e.getAttribute("title"))!=null?l:e.innerText)!=null?g:e.textContent)},Pt=e=>{var l,g;let n=e.target instanceof Element?e.target:null;if(!n)return null;let r=n.closest(yn),s=r!=null?r:n,c=document.documentElement;return {x:Math.round(e.clientX),y:Math.round(e.clientY+window.scrollY),vw:window.innerWidth,vh:window.innerHeight,docH:Math.max(c.scrollHeight,(g=(l=document.body)==null?void 0:l.scrollHeight)!=null?g:0),selector:Rn(s),label:r?vn(r):"",interactive:!!r}},Mt=()=>{var r,s;let e=document.documentElement,n=Math.max(e.scrollHeight,(s=(r=document.body)==null?void 0:r.scrollHeight)!=null?s:0);return n?Math.min(100,Math.round((window.scrollY+window.innerHeight)/n*100)):0};var je="0.17.0",En=(e,n)=>{let r=n.trim().toLowerCase();for(let[s,c]of Object.entries(e))if(s.toLowerCase()===r)return c},_n=(e,n)=>{let r=e.trim().toLowerCase(),s=n.trim().toLowerCase();return s.startsWith("@")?r.endsWith(s):r===s},Sn=(e,n)=>{if(e.op==="in cohort")return false;let r=En(n,e.property),s=r==null?"":String(r);if(e.op==="\u2265"){let l=Number(s),g=Number(e.values[0]);return s!==""&&Number.isFinite(l)&&Number.isFinite(g)&&l>=g}let c=s!==""&&e.values.some(l=>_n(s,l));return e.op==="is"||e.op==="in"?c:!c},On=(e,n,r={})=>{var v;if(!e.on)return false;let s={id:n,...r},c=e.sets.length?e.sets.find(S=>S.conditions.every(b=>Sn(b,s))):{rollout:100};if(!c||At(`${e.key}:rollout:${n}`)*100>=c.rollout)return false;if(!((v=e.variants)!=null&&v.length))return true;let l=At(`${e.key}:variant:${n}`)*100,g=0;for(let S of e.variants)if(g+=S.split,l<g)return S.key;return e.variants[e.variants.length-1].key},it=(e,n,r,s={})=>{var l;let c=(l=n==null?void 0:n.flags)==null?void 0:l.find(g=>g.key===e);return c?On(c,r,s):false},In=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],Nt="ck_preview",Lt="ck_embed",ke="ck_id",Se="ck_sid";var Fn=e=>{var r;let n={};for(let s of In){let c=(r=e(s))==null?void 0:r.trim();c&&(n[s]=c.slice(0,150));}return n},Tt=e=>{let n=new URLSearchParams(e);return Fn(r=>n.get(r))};var $n=e=>{let n=2166136261;for(let r=0;r<e.length;r++)n^=e.charCodeAt(r),n=Math.imul(n,16777619);return (n>>>0)/4294967296},At=e=>{let n=2166136261;for(let r=0;r<e.length;r++)n^=e.charCodeAt(r),n=Math.imul(n,16777619);return n^=n>>>16,n=Math.imul(n,2246822507),n^=n>>>13,n=Math.imul(n,3266489909),n^=n>>>16,(n>>>0)/4294967296},Pn=(e,n)=>{var l,g,v,S;let r=(g=(l=e.variants[0])==null?void 0:l.id)!=null?g:"control";if(e.winner)return e.winner;if(e.status!=="running")return r;let s=$n(`${e.key}:${n}`),c=0;for(let b of e.variants)if(c+=b.weight,s<c)return b.id;return (S=(v=e.variants[e.variants.length-1])==null?void 0:v.id)!=null?S:r},Ut=e=>{let n=Array.isArray(e)?e[0]:e;if(!n)return {};let r={};for(let s of n.split(",")){let[c,l]=s.split(":");c&&l&&(r[c.trim()]=l.trim());}return r};var Pe=(e,n,r,s)=>{if(s[e])return s[e];let c=n==null?void 0:n.experiments.find(l=>l.key===e);return c?Pn(c,r):"control"},Ht=(e,n,r)=>{var c,l,g,v,S,b;let s={...(c=e==null?void 0:e.texts)!=null?c:{}};for(let O of (l=e==null?void 0:e.experiments)!=null?l:[]){let w=Pe(O.key,e,n,r);w!==((v=(g=O.variants[0])==null?void 0:g.id)!=null?v:"control")&&Object.assign(s,(b=(S=O.variants.find(C=>C.id===w))==null?void 0:S.changes)!=null?b:{});}return s},$e="ck_x",De=e=>e.replace(/\/+$/,"")||"/",Dt=(e,n,r,s={})=>{var v,S;if(!e)return null;let c;try{c=new URL(n);}catch(b){return null}if(c.searchParams.has($e))return null;let l=De(c.pathname),g=(b,O)=>{let w;try{w=new URL(b,c);}catch(C){return}if(!(!/^https?:$/.test(w.protocol)||w.origin===c.origin&&De(w.pathname)===l))return c.searchParams.forEach((C,_)=>{w.searchParams.has(_)||w.searchParams.set(_,C);}),O&&w.searchParams.set($e,O),w.hash||(w.hash=c.hash),w.href};for(let b of (v=e.redirects)!=null?v:[]){let O=b.from&&De(b.from)===l?g(b.to):void 0;if(O)return {to:O}}for(let b of e.experiments){if(!b.path||De(b.path)!==l)continue;let O=b.status==="running"&&!b.winner;if(O&&r===null&&!s[b.key])return null;let w=Pe(b.key,e,r!=null?r:"",s),C=(S=b.variants.find(F=>F.id===w))==null?void 0:S.url,_=C?g(C,O?`${b.key}:${w}`:void 0):void 0;return O?{to:_,experiment:b.key,variant:w}:_?{to:_}:null}return null},jt=(e,n)=>{let[r,s]=(n!=null?n:"").split(":"),c=e==null?void 0:e.experiments.find(l=>l.key===r);return c&&c.variants.some(l=>l.id===s)?{experiment:r,variant:s}:null};var at=()=>typeof crypto!="undefined"&&"randomUUID"in crypto?crypto.randomUUID():`ck_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;var Mn="401: sign the user id on your server with userHash(id) from @mrrocket/sdk/next/server and pass identify(id, props, { hash }).",Oe=(e,n=r=>console.warn(r))=>{let r=globalThis;e!==401||r.__mrrocketUnsigned||(r.__mrrocketUnsigned=true,n(`[MRRocket] ${Mn}`));},Wt=(e,n,r,s=c=>console.warn(c))=>{let c=typeof r=="string"?r.trim().toLowerCase():"";return /^[0-9a-f]{64}$/.test(c)?{id:n,hash:c}:(c&&s("[MRRocket] identify: that hash is no userHash(id); not sent."),e&&e.id===n?e:null)},Kt=(e,n)=>e&&n&&e.id===n?e.hash:void 0,Vt=(e,n)=>e&&n.some(r=>r===e.id)&&n.every(r=>!r||r===e.id)?e.hash:void 0;var An=8*1024,Nn=20,Ln=20,Tn=2e3,Me=(e,n)=>e.length>n?`${e.slice(0,n-1)}\u2026`:e,Un=e=>{var n;if(e instanceof Error)return {type:e.name||"Error",message:Me(e.message||String(e),1e3),stack:e.stack?Me(e.stack,An):void 0};if(typeof e=="string")return {type:"Error",message:Me(e,1e3)};try{return {type:"Error",message:Me((n=JSON.stringify(e))!=null?n:String(e),1e3)}}catch(r){return {type:"Error",message:String(e)}}},Bt=e=>{let n=[],r=[],s=new Set,c=0,l=`${e.host}/api/sdk/errors`,g=(C=false)=>{for(;n.length;){let _=n.splice(0,4),F=e.context(),H=F.distinctId&&F.userHash?{id:F.distinctId,hash:F.userHash}:null,A=Vt(H,_.map(M=>M.distinctId)),U=JSON.stringify({key:e.apiKey,...A?{userHash:A}:{},errors:_});C&&typeof navigator!="undefined"&&"sendBeacon"in navigator&&navigator.sendBeacon(l,U)||fetch(l,{method:"POST",headers:{"content-type":"application/json"},body:U,keepalive:true}).then(M=>{M.status===401?Oe(401):!M.ok&&M.status!==429&&e.warn(`Error reports were rejected with ${M.status}. Check the public key and NEXT_PUBLIC_MRROCKET_HOST.`);}).catch(()=>{});}},v=(C,_="manual")=>{let F=e.context();if(!F.send||c>=Nn)return;let H=Un(C);if(/\/api\/sdk\/errors/.test(H.message))return;let A=`${H.type}:${H.message}`;s.has(A)||(s.add(A),c++,n.push({...H,mechanism:_,handled:_==="manual",url:window.location.href,ts:Date.now(),crumbs:r.slice(),...e.release?{release:e.release}:{},...F.distinctId?{distinctId:F.distinctId}:{},...F.sessionId?{sessionId:F.sessionId}:{}}));},S=C=>{var _;!C.error&&(!C.message||C.message==="Script error.")||v((_=C.error)!=null?_:new Error(C.message),"onerror");},b=C=>{var _;return v((_=C.reason)!=null?_:new Error("Unhandled promise rejection"),"onunhandledrejection")},O=()=>g(true);window.addEventListener("error",S),window.addEventListener("unhandledrejection",b),window.addEventListener("pagehide",O);let w=window.setInterval(()=>g(),Tn);return {capture:v,crumb:(C,_)=>{r.push({ts:Date.now(),type:C,message:Me(_,120)}),r.length>Ln&&r.shift();},stop:()=>{window.removeEventListener("error",S),window.removeEventListener("unhandledrejection",b),window.removeEventListener("pagehide",O),window.clearInterval(w),g(true);}}};var Ae="$cancel_flow",se="$onboarding",ct="$inapp";var Hn={version:0,question:"",reasons:[],offers:{},confirm:{title:"Cancel your subscription?",body:"You keep access until the end of the billing period.",button:"Cancel subscription"},offersFor:"business"},Dn="Something went wrong. Please try again.",qt="mrrocket:onboarding",ye=e=>e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),Yt=new Set(["signed_up","signup","sign_up","registered","account_created","user_signed_up"]),lt=(e,n)=>{let r=ye(e),s=ye(n);return !r||!s?false:r===s||Yt.has(r)&&Yt.has(s)},jn=e=>/^(first (launch|visit|open|session|login|sign ?in|app open)|app (opened|launched)|on load|every visit|always)?$/i.test(e.trim());var Wn=e=>e.trim().startsWith("/"),dt=e=>ye(e)==="from_a_checklist";var Kn=()=>`cf_${Math.random().toString(36).slice(2,10)}${Date.now().toString(36)}`;var Xt=e=>{let n=(e!=null?e:"").trim();return /^https?:\/\//i.test(n)||/^\/(?!\/)/.test(n)?n:void 0},ie=e=>{var n;return (n=e.nodes)!=null?n:e.steps},Vn=e=>Math.max(0,e.amount)*(e.unit==="hours"?36e5:864e5),zt=(e,n)=>{let r=e.trim(),s=(n.split(/[?#]/)[0]||"/").replace(/\/+$/,"")||"/";if(!r)return false;if(r.endsWith("*")){let c=r.slice(0,-1).replace(/\/+$/,"");return !c||s===c||s.startsWith(`${c}/`)}return s===(r.replace(/\/+$/,"")||"/")},Ke=e=>e.flatMap(n=>n.kind==="condition"?[...Ke(n.yes),...Ke(n.no)]:n.kind==="wait"?[]:[n]),Bn=(e,n=Date.now())=>e==null||e===""?NaN:Math.floor((n-new Date(e).getTime())/2630016e3),We=e=>e==null?void 0:e.trim().toLowerCase(),qn=({when:e={}},n)=>(e.answer==null||We(e.answer)===We(n.answer))&&(e.plan==null||[e.plan].flat().some(r=>We(r)===We(n.plan)))&&!(n.months>=e.tenureUnder)&&!(n.months<e.tenureOver)&&(e.tenureUnder==null||n.months>=0)&&(e.tenureOver==null||n.months>=0),Jt=e=>{let n=null,r=null,s=null,c=[],l=false,g=null,v,S=null,b=new Map,O=new Set,w=new Set,C=new Set,_=e.auto!==false,F=new Set,H=()=>{var t,i;return (i=(t=e.now)==null?void 0:t.call(e))!=null?i:Date.now()},A=null,U=null,ne=()=>{var t;return (t=n==null?void 0:n.onboarding)!=null?t:[]},M=t=>t?ne().find(i=>i.id===t):void 0,K=t=>{let i=b.get(t);return i||b.set(t,i={done:new Set,dismissed:false,answers:new Map,at:new Map,reached:new Map}),i},X=false,fe=t=>{e.track(se,t),X=true;},pe=(t,i)=>{t.done.add(i),t.at.set(i,H());},Te=t=>{var i,a,p;if((i=t.page)!=null&&i.trim()){let m=(a=e.path)==null?void 0:a.call(e);return m===void 0?false:zt(t.page,m)}if((p=t.event)!=null&&p.trim()){if(!l)return;for(let m of F)if(lt(t.event,m))return true;return false}return false},be=(t,i,a,p,m=0,R)=>{var f,h;for(let k=0;k<i.length;k++){let x=i[k];if(x.kind==="wait"){if(a.done.has(x.id)){R=(f=a.at.get(x.id))!=null?f:R;continue}let I=a.reached.get(x.id);if(I===void 0){if(!p)return {at:"pending"};I=R!=null?R:H(),a.reached.set(x.id,I),fe({flow:t.id,step:x.id,kind:"wait",action:"shown"});}let j=I+Vn(x);if(H()<j)return {at:"wait",until:j};if(!p)return {at:"pending"};pe(a,x.id),fe({flow:t.id,step:x.id,kind:"wait",action:"completed"}),R=j;continue}if(x.kind==="condition"){let I=a.answers.get(x.id);if(I===void 0){if(!p)return {at:"pending"};if(I=Te(x),I===void 0)return {at:"pending"};a.answers.set(x.id,I),fe({flow:t.id,step:x.id,kind:"condition",action:"answered",answer:I?"yes":"no"});}return be(t,I?x.yes:x.no,a,p,m,R)}if(!a.done.has(x.id))return {at:"step",step:x,line:i,index:k,before:m};R=(h=a.at.get(x.id))!=null?h:R,m++;}return {at:"end"}},ae=t=>{let i=b.get(t.id);return !!i&&(i.dismissed||be(t,ie(t),i,false).at==="end")},V=t=>`${qt}:${t!=null?t:"visitor"}`,ge=t=>`${qt}:events:${t!=null?t:"visitor"}`,Y=()=>{var a;X=false;let t=(a=e.storage)==null?void 0:a.call(e);if(!t)return;let i={};for(let[p,m]of b)i[p]={done:[...m.done],...m.dismissed?{dismissed:true}:{},...m.answers.size?{answers:Object.fromEntries([...m.answers].map(([R,f])=>[R,f?"yes":"no"]))}:{},...m.at.size?{at:Object.fromEntries(m.at)}:{},...m.reached.size?{reached:Object.fromEntries(m.reached)}:{}};try{t.set(V(e.personId()),JSON.stringify(i)),F.size&&t.set(ge(e.personId()),JSON.stringify([...F].slice(-200)));}catch(p){}},P=t=>{var i,a,p,m;for(let[R,f]of Object.entries(t!=null?t:{})){let h=K(R);for(let k of (i=f.done)!=null?i:[])h.done.add(k);f.dismissed&&(h.dismissed=true);for(let[k,x]of Object.entries((a=f.answers)!=null?a:{}))h.answers.has(k)||h.answers.set(k,x==="yes");for(let[k,x]of Object.entries((p=f.at)!=null?p:{}))typeof x=="number"&&!h.at.has(k)&&h.at.set(k,x);for(let[k,x]of Object.entries((m=f.reached)!=null?m:{}))typeof x=="number"&&(!h.reached.has(k)||x<h.reached.get(k))&&h.reached.set(k,x);}},re=t=>{var a;A&&clearTimeout(A),A=null;let i=t-H();i>0&&i<=864e5&&(A=setTimeout(()=>(A=null,N()),i+50),(a=A.unref)==null||a.call(A));},me=false,oe=()=>{me=false;let t=M(s);if(!t)return null;let i=K(t.id);if(i.dismissed)return null;let a=be(t,ie(t),i,true);if(X&&Y(),a.at==="wait"&&re(a.until),me=a.at==="wait"||a.at==="pending",a.at!=="step")return null;let{step:p,line:m,index:R}=a,f=I=>!!I&&I.kind!=="wait"&&I.kind!=="condition";if(p.kind==="checklist"){let I=R;for(;I>0&&f(m[I-1])&&m[I-1].kind==="checklist";)I--;let j=R;for(;j+1<m.length&&f(m[j+1])&&m[j+1].kind==="checklist";)j++;let ce=m.slice(I,j+1).filter(f);for(let G of ce)!i.done.has(G.id)&&!w.has(`s:${G.id}`)&&(w.add(`s:${G.id}`),e.track(se,{flow:t.id,step:G.id,kind:"checklist",action:"shown"}));return {type:"checklist",flow:t,items:ce.map(G=>{let Re=G.startsTour&&G.startsTour!==t.id?M(G.startsTour):void 0;return {step:G,done:i.done.has(G.id),...Re&&ie(Re).length?{tour:Re}:{}}})}}w.has(`s:${p.id}`)||(w.add(`s:${p.id}`),e.track(se,{flow:t.id,step:p.id,kind:p.kind,action:"shown"}));let h=m.slice(R+1),k=h.findIndex(I=>I.kind==="condition"),x=(k<0?h:h.slice(0,k)).filter(f).length;return {type:"step",flow:t,step:p,index:a.before,total:a.before+1+x,last:!x&&k<0}},we=()=>{var a,p,m,R;if(r){let f=r,h=(a=f.flow.followUps)==null?void 0:a[f.reason],k=h?1:0,x=f.plain?1:3+k+((p=f.flow.second)!=null&&p[f.reason]?1:0);return {type:"cancel",screen:f.screen,flow:f.flow,reason:f.reason,...f.screen==="followup"&&h?{followUp:h,answer:f.answer}:{},offer:f.screen==="offer"?f.offer:void 0,...f.screen==="offer"?{round:f.round}:{},price:f.options.price,busy:f.busy,error:f.error,step:f.screen==="survey"?1:f.screen==="followup"?2:f.screen==="offer"?1+k+f.round:x,steps:x}}let t=oe();if(t)return t;if(s&&!me){let f=U,h=s;U=null,s=null;let k=f?M(f.flow):void 0;if(f&&k){let x=Ke(ie(k)).find(ce=>ce.id===f.step),I=K(k.id);x&&!x.event&&!((m=b.get(h))!=null&&m.dismissed)&&!I.done.has(x.id)&&(pe(I,x.id),fe({flow:k.id,step:x.id,kind:"checklist",action:"completed"})),s=k.id;let j=oe();if(j)return j;me||(s=null);}else if(l){let x=(R=M(h))==null?void 0:R.trigger;Promise.resolve().then(()=>Ce(x));}}let i=c.find(f=>!O.has(f.id));return i?{type:"message",message:i}:null},N=()=>{let t=we();(t==null?void 0:t.type)==="message"&&!w.has(`m:${t.message.id}`)&&(w.add(`m:${t.message.id}`),e.track(ct,{message:t.message.id,journey:t.message.journey,action:"shown"}));for(let i of [...C])try{i();}catch(a){}},te=t=>s===t.id?true:s&&M(s)&&!ae(M(s))?false:(s=t.id,e.track(se,{flow:t.id,action:"started"}),N(),true),xe=t=>t.audience!=="signed_in"||!!e.personId(),Ce=t=>{var m,R;if(!_||s||!l||!e.personId()&&!((m=e.storage)!=null&&m.call(e)))return;let i=(R=e.path)==null?void 0:R.call(e),a=t&&!dt(t)?ye(t):"",p=ne().find(f=>(Wn(f.trigger)?i!==void 0&&zt(f.trigger,i):jn(f.trigger)||!!a&&ye(f.trigger)===a)&&xe(f)&&ie(f).length&&!ae(f));p&&te(p);},B=()=>{let t=e.personId();S!==null&&S!==t&&(b.clear(),F.clear(),O.clear(),s=null,U=null,v=void 0),S=t;let i=(async()=>{var m,R,f;let a=(m=e.storage)==null?void 0:m.call(e);if(a)try{let h=await a.get(V(t));h&&P(JSON.parse(h));let k=await a.get(ge(t));if(k)for(let x of JSON.parse(k))typeof x=="string"&&F.add(x);}catch(h){}let p=ne().length>0||!!(n!=null&&n.messages);if(t&&p&&v!==t){v=t;let h=await e.fetchInApp(t).catch(()=>null);if(h&&e.personId()===t){P(h.onboarding);for(let k of (R=h.events)!=null?R:[])typeof k=="string"&&F.add(ye(k));c=((f=h.messages)!=null?f:[]).filter(k=>k&&k.id&&k.title);}}t||(c=[]),l=true,Ce(),N();})();return g=i.finally(()=>{g===i&&(g=null);}),g},D=t=>t.round>1?{round:2}:t.rule>=0?{rule:t.rule}:{},q=t=>{var p,m,R,f;let i={answer:t.answer,plan:t.options.plan,months:Bn(t.options.customerSince,(p=e.now)==null?void 0:p.call(e))},a=(R=(m=t.flow.rules)==null?void 0:m[t.reason])!=null?R:[];t.rule=a.findIndex(h=>qn(h,i)),t.offer=t.rule<0?t.flow.offers[t.reason]:(f=a[t.rule].offer)!=null?f:void 0,t.round=1,t.screen=t.offer?"offer":"confirm";},Z=(t,i,a)=>{var m;let p=t.screen==="offer"?t.offer:void 0;return {outcome:i,run:t.run,...t.reason?{reason:t.reason,reasonLabel:(m=t.flow.reasons.find(R=>R.id===t.reason))==null?void 0:m.label}:{},...t.answer?{answer:t.answer}:{},...i==="saved"&&p?{offer:p}:{},...a!=null&&a.trim()?{comment:a.trim().slice(0,500)}:{}}},z=(t,i)=>{var a;e.track(Ae,{action:"finished",run:t.run,version:t.flow.version,outcome:i.outcome,customer:(a=t.options.customer)!=null?a:"consumer",...i.reason?{reason:i.reason}:{},...i.answer?{answer:i.answer}:{},...i.offer?{offer:i.offer.kind,...D(t)}:{},...i.comment?{comment:i.comment}:{}}),r===t&&(r=null),t.resolve(i),N();},he=(t,i,a)=>{if(t.busy)return;let p=Z(t,i,a),m=i==="saved"?t.options.onSave:t.options.onCancel;t.busy=true,t.error=void 0,N(),Promise.resolve().then(()=>m==null?void 0:m(p)).then(()=>z(t,p),()=>{t.busy=false,t.error=Dn,N();});};return {setConfig:t=>{n=t,s&&!M(s)&&(s=null),N();},refresh:B,onEvent:t=>{var f;if(t==="$pageview"&&Ce(),!t||t.startsWith("$"))return;let i=ye(t),a=!!i&&!F.has(i);a&&F.add(i);let p=M(s),m=false;if(p){let h=K(p.id);for(let k of Ke(ie(p)))k.kind==="checklist"&&k.event&&!h.done.has(k.id)&<(k.event,t)&&(pe(h,k.id),m=true,e.track(se,{flow:p.id,step:k.id,kind:k.kind,action:"completed"}));}if(m||a&&p?(Y(),N()):a&&Y(),!_||!e.personId()&&!((f=e.storage)!=null&&f.call(e)))return;let R=ne().find(h=>ie(h).length&&!dt(h.trigger)&<(h.trigger,t)&&xe(h)&&!ae(h));R&&te(R);},openCancelFlow:(t={})=>{var f,h;if(r)return r.promise;let i=(f=n==null?void 0:n.cancelFlow)!=null?f:Hn,a=t.customer!=="business"||i.reasons.length<2,p=()=>{},m=new Promise(k=>p=k),R={flow:i,options:t,plain:a,screen:a?"confirm":"survey",round:1,run:Kn(),busy:false,resolve:p,promise:m};return r=R,e.track(Ae,{action:"shown",run:R.run,version:i.version,customer:(h=t.customer)!=null?h:"consumer",plain:a}),N(),m},startOnboarding:t=>{let i=t?M(t):ne().find(p=>ie(p).length&&!dt(p.trigger)&&!ae(p));if(!i||!ie(i).length)return false;let a=K(i.id);return a.dismissed=false,te(i)},view:we,subscribe:t=>(C.add(t),()=>C.delete(t)),cancel:{pick:t=>{!r||r.busy||r.screen!=="survey"||!r.flow.reasons.some(i=>i.id===t)||(r.reason!==t&&(r.answer=void 0),r.reason=t,r.error=void 0,N());},answer:t=>{let i=r;if(!i||i.busy||i.screen!=="followup")return;let a=t.slice(0,500);i.answer=a.trim()?a:void 0,N();},next:()=>{var i,a;let t=r;if(!(!t||!t.reason)){if(t.screen==="survey")e.track(Ae,{action:"answered",run:t.run,version:t.flow.version,reason:t.reason}),(i=t.flow.followUps)!=null&&i[t.reason]?t.screen="followup":q(t);else if(t.screen==="followup")t.answer=(a=t.answer)==null?void 0:a.trim(),q(t);else return;N();}},accept:t=>{var a;let i=r;!i||i.screen!=="offer"||!i.reason||(i.busy||e.track(Ae,{action:"offer",run:i.run,version:i.flow.version,reason:i.reason,offer:(a=i.offer)==null?void 0:a.kind,...D(i),outcome:"accepted"}),he(i,"saved",t));},decline:()=>{var a,p;let t=r;if(!t||t.screen!=="offer"||t.busy)return;e.track(Ae,{action:"offer",run:t.run,version:t.flow.version,reason:t.reason,offer:(a=t.offer)==null?void 0:a.kind,...D(t),outcome:"declined"});let i=t.round===1&&t.reason?(p=t.flow.second)==null?void 0:p[t.reason]:void 0;i?(t.offer=i,t.rule=void 0,t.round=2):t.screen="confirm",t.error=void 0,N();},confirm:t=>{let i=r;!i||i.screen!=="confirm"||he(i,"cancelled",t);},close:()=>{var a,p;let t=r;if(!t||t.busy)return;let i=Z(t,"kept");(p=(a=t.options).onClose)==null||p.call(a,i),z(t,i);}},onboarding:{next:()=>{var a;let t=oe();if((t==null?void 0:t.type)!=="step")return;pe(K(t.flow.id),t.step.id),e.track(se,{flow:t.flow.id,step:t.step.id,kind:t.step.kind,action:"completed"}),Y(),N();let i=t.step.kind==="modal"?Xt(t.step.url):void 0;i&&((a=e.openUrl)==null||a.call(e,i));},check:t=>{let i=oe();if((i==null?void 0:i.type)!=="checklist")return;let a=i.items.find(p=>p.step.id===t);!a||a.done||(pe(K(i.flow.id),t),e.track(se,{flow:i.flow.id,step:t,kind:"checklist",action:"completed"}),Y(),N());},dismiss:()=>{let t=oe();!t||t.type!=="step"&&t.type!=="checklist"||(K(t.flow.id).dismissed=true,e.track(se,{flow:t.flow.id,...t.type==="step"?{step:t.step.id}:{},action:"dismissed"}),s=U&&U.flow!==t.flow.id&&M(U.flow)?U.flow:null,U=null,Y(),N());},startTour:t=>{var m;let i=oe();if((i==null?void 0:i.type)!=="checklist")return false;let a=(m=i.items.find(R=>R.step.id===t))==null?void 0:m.tour;if(!a)return false;let p=K(a.id);return p.done.clear(),p.at.clear(),p.dismissed=false,U={flow:i.flow.id,step:t},s=a.id,e.track(se,{flow:a.id,action:"started",from:i.flow.id}),Y(),N(),true}},message:{click:()=>{var a;let t=we();if((t==null?void 0:t.type)!=="message")return;O.add(t.message.id),e.track(ct,{message:t.message.id,journey:t.message.journey,action:"clicked"});let i=Xt(t.message.url);N(),i&&((a=e.openUrl)==null||a.call(e,i));},dismiss:()=>{let t=we();(t==null?void 0:t.type)==="message"&&(O.add(t.message.id),e.track(ct,{message:t.message.id,journey:t.message.journey,action:"dismissed"}),N());}}}};var Yn="ck_pick",Xn="ck_origin",Ve=e=>typeof CSS!="undefined"&&CSS.escape?CSS.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,n=>`\\${n}`),zn=e=>[...e.classList].filter(n=>n.length<30&&!/\d{2,}|[_-][a-z0-9]{5,}$|^(is|has)-|hover|active|focus|open|selected|:|\[/.test(n)).slice(0,2),Gt=e=>{let n=e.ownerDocument,r=g=>{try{return n.querySelectorAll(g).length===1}catch(v){return false}},s=e.getAttribute("data-ck-target");if(s)return `[data-ck-target="${s.replace(/"/g,'\\"')}"]`;if(e.id&&!/\d{3,}/.test(e.id)&&r(`#${Ve(e.id)}`))return `#${Ve(e.id)}`;let c=[],l=e;for(;l&&l!==n.documentElement&&c.length<6;){if(l!==e&&l.id&&!/\d{3,}/.test(l.id)){c.unshift(`#${Ve(l.id)}`);break}let g=l.tagName.toLowerCase(),v=zn(l).map(C=>`.${Ve(C)}`).join(""),S=l.parentElement,b=S?[...S.children].filter(C=>C.tagName===l.tagName):[],O=b.length>1?`:nth-of-type(${b.indexOf(l)+1})`:"";c.unshift(`${g}${v}${O}`);let w=c.join(" > ");if(r(w))return w;l=S;}return c.join(" > ")},Qt=()=>{var O;if(typeof window=="undefined"||window.top===window)return null;let e=new URLSearchParams(window.location.search);if(e.get(Yn)!=="1")return null;let n;try{n=new URL((O=e.get(Xn))!=null?O:"").origin;}catch(w){return null}if(!/^https?:\/\//.test(n))return null;let r=w=>window.parent.postMessage(w,n),s=document.createElement("div");s.setAttribute("aria-hidden","true"),Object.assign(s.style,{position:"fixed",zIndex:"2147483647",pointerEvents:"none",border:"2px solid #0ea5e9",background:"rgba(14,165,233,.12)",borderRadius:"6px",transition:"all 60ms linear",display:"none"});let c=document.createElement("div");Object.assign(c.style,{position:"absolute",left:"-2px",bottom:"calc(100% + 4px)",font:"600 11px/1.4 system-ui, sans-serif",color:"#fff",background:"#0c4a6e",padding:"2px 6px",borderRadius:"4px",whiteSpace:"nowrap",maxWidth:"360px",overflow:"hidden",textOverflow:"ellipsis"}),s.appendChild(c),document.body.appendChild(s);let l=null,g=w=>{if(l=w&&w!==s&&!s.contains(w)?w:null,!l){s.style.display="none";return}let C=l.getBoundingClientRect();Object.assign(s.style,{display:"block",left:`${C.left-2}px`,top:`${C.top-2}px`,width:`${C.width+4}px`,height:`${C.height+4}px`}),c.textContent=Gt(l);},v=w=>g(document.elementFromPoint(w.clientX,w.clientY)),S=w=>{var _,F;w.preventDefault(),w.stopPropagation();let C=(_=document.elementFromPoint(w.clientX,w.clientY))!=null?_:l;!C||C===s||r({type:"mrrocket:picked",selector:Gt(C),text:((F=C.textContent)!=null?F:"").trim().replace(/\s+/g," ").slice(0,80)});},b=w=>{w.key==="Escape"&&r({type:"mrrocket:pick-cancel"});};return window.addEventListener("mousemove",v,true),window.addEventListener("click",S,true),window.addEventListener("keydown",b,true),r({type:"mrrocket:pick-ready"}),()=>{window.removeEventListener("mousemove",v,true),window.removeEventListener("click",S,true),window.removeEventListener("keydown",b,true),s.remove();}};var Jn={get:e=>{try{return window.localStorage.getItem(e)}catch(n){return null}},set:(e,n)=>{try{window.localStorage.setItem(e,n);}catch(r){}}},Zt=()=>{try{for(let e=window.localStorage.length-1;e>=0;e--){let n=window.localStorage.key(e);n!=null&&n.startsWith("mrrocket:onboarding")&&window.localStorage.removeItem(n);}}catch(e){}},en=e=>({track:e.track,personId:e.personId,auto:e.auto,storage:()=>e.canStore()?Jn:null,openUrl:n=>window.location.assign(n),path:()=>window.location.pathname,fetchInApp:async n=>{var c;if(!e.apiKey)return null;let r=(c=e.userHash)==null?void 0:c.call(e,n),s=await fetch(`${e.host}/api/sdk/inapp?key=${encodeURIComponent(e.apiKey)}&distinctId=${encodeURIComponent(n)}${r?`&userHash=${r}`:""}`);return Oe(s.status),s.ok?await s.json():null}});var Ye="mrr_ref",Xe="mrr_ref",Gn="mrr_ref",Qn="mrr_click";var Ne=/^[A-Za-z0-9_-]{1,64}$/;var Zn=(e,n="ref")=>{let r=new URLSearchParams(e);return er(s=>r.get(s),n)},er=(e,n="ref")=>{let r=e(Gn);if(r&&Ne.test(r)){let c=e(Qn);return {code:r,clickId:c&&Ne.test(c)?c:null,direct:false}}let s=e(n);return s&&Ne.test(s)?{code:s,clickId:null,direct:true}:null},tn=e=>{var n;return `${e.code}.${(n=e.clickId)!=null?n:""}.${e.at}`},Be=(e,n=60,r=Date.now())=>{if(!e)return null;let[s,c,l]=e.split("."),g=Number(l);return !s||!Ne.test(s)||!Number.isFinite(g)||c&&!Ne.test(c)||r-g>n*864e5||g>r+864e5?null:{code:s,clickId:c||null,at:g}};var W=null,ze=()=>typeof document!="undefined",nn=e=>{var r;if(!ze())return;let n=(r=document.cookie.split("; ").find(s=>s.startsWith(`${e}=`)))==null?void 0:r.slice(e.length+1);try{return n?decodeURIComponent(n):void 0}catch(s){return n}},Je=()=>{try{return typeof localStorage=="undefined"?null:localStorage}catch(e){return null}},ut=()=>{var e,n;return W||(ze()?(n=Be(nn(Ye),3650))!=null?n:Be((e=Je())==null?void 0:e.getItem(Xe),3650):null)};var qe=(e,n)=>{var c;if(!ze())return;let r=Math.max(1,Math.round(n))*86400,s=typeof location!="undefined"&&location.protocol==="https:"?"; secure":"";document.cookie=`${Ye}=${encodeURIComponent(tn(e))}; path=/; max-age=${r}; samesite=lax${s}`;try{(c=Je())==null||c.setItem(Xe,tn(e));}catch(l){}},Ge=()=>{var e;if(ze()){document.cookie=`${Ye}=; path=/; max-age=0; samesite=lax`;try{(e=Je())==null||e.removeItem(Xe);}catch(n){}}},rn=()=>{W=null;},on=async e=>{var s,c,l;let n=Zn(e.search,e.param),r=(s=e.now)!=null?s:Date.now();if(!n)return !W&&e.store&&(W=(l=Be(nn(Ye),e.days,r))!=null?l:Be((c=Je())==null?void 0:c.getItem(Xe),e.days,r),W||Ge()),W;if(W={code:n.code,clickId:n.clickId,at:r},e.store&&qe(W,e.days),e.beacon)try{let g=await e.beacon({code:n.code,clickId:n.clickId});g&&W&&W.code===n.code&&!W.clickId&&(W={...W,clickId:g},e.store&&qe(W,e.days));}catch(g){}return W},sn=e=>e==="$identify"||!e.startsWith("$");var ft=3600*24*365,ln=e=>{var r;if(typeof document=="undefined")return;let n=(r=document.cookie.split("; ").find(s=>s.startsWith(`${e}=`)))==null?void 0:r.slice(e.length+1);if(n)try{return decodeURIComponent(n)}catch(s){return n}},Qe=(e,n,r)=>{let s=window.location.protocol==="https:"?"; secure":"";document.cookie=`${e}=${encodeURIComponent(n)}; path=/; max-age=${r}; samesite=lax${s}`;},Le=e=>{document.cookie=`${e}=; path=/; max-age=0; samesite=lax`;},L={utm:{}},cn=()=>{var e;return (e=L.id)!=null?e:L.id=at()},pt=(e,n)=>{if(e!=="cookies")return cn();let r=ln(ke);if(r)return L.id=r;let s=cn();return Qe(ke,s,ft),s},gt=e=>{var c;let n=Date.now(),r=L.session,s=(c=e?ln(Se):void 0)!=null?c:r&&n-r.last<18e5?r.id:at();return L.session={id:s,last:n},e&&Qe(Se,s,18e5/1e3),s},mt=()=>{var r;let e=window.location.href;if(L.url===e)return;L.referrer=(r=L.url)!=null?r:document.referrer||void 0,L.url=e;let n=Tt(window.location.search);Object.keys(n).length&&(L.utm=n);},dn=()=>{let e=navigator,n=window;return e.doNotTrack==="1"||n.doNotTrack==="1"||e.globalPrivacyControl===true};var Ze=window,nr=()=>{var e,n;return (n=(e=document.currentScript)!=null?e:document.querySelector('script[data-key][src*="sdk"]'))!=null?n:document.querySelector("script[data-key][src*='mrrocket']")},un=new Set,ee=e=>{un.has(e)||(un.add(e),console.warn(`[MRRocket] ${e}`));},rr=()=>{var vt,Et,_t,St;let e=nr(),n=o=>{var d;return (d=e==null?void 0:e.getAttribute(`data-${o}`))!=null?d:void 0},r=(o,d)=>{let u=n(o);return u===void 0?d:!["false","0","off","no"].includes(u.trim().toLowerCase())},s=(vt=e==null?void 0:e.src)!=null?vt:"",c="";try{c=s?new URL(s,window.location.href).origin:"";}catch(o){c="";}let l=((Et=n("key"))!=null?Et:"").trim(),g=((_t=n("api-host"))!=null?_t:c).trim().replace(/\/+$/,""),v=n("consent"),S=r("respect-dnt",false),b=r("heatmaps",true),O=r("errors",true),w=n("release"),C=n("attribution"),_=C==="always"||C==="off"?C:"consent",F=n("referral-param")||"ref",H={},A=(o,d)=>{var u;return (u=H[o])!=null?u:H[o]=new Promise((y,E)=>{var Ot;let $=()=>Ze[d];if($())return y($());let Q=(Ot=n(`${o}-src`))!=null?Ot:s?s.replace(/(\.min)?\.js(\?[^#]*)?(#.*)?$/,`-${o}$1.js?v=${je}`):"";if(!Q)return E(new Error(o));let ue=document.createElement("script");ue.async=true,ue.src=Q,ue.onload=()=>$()?y($()):E(new Error(o)),ue.onerror=()=>E(new Error(o)),document.head.appendChild(ue);}).catch(y=>{throw H[o]=void 0,y})},U=n("theme"),ne={theme:U==="light"||U==="dark"?U:"auto",accent:n("accent")},M=new URLSearchParams(window.location.search),K=Ut(M.get(Nt)),X=M.get(Lt)==="1";X&&Qt();let fe=M.get($e);if(fe!==null){M.delete($e);let o=M.toString();history.replaceState(history.state,"",`${window.location.pathname}${o?`?${o}`:""}${window.location.hash}`);}let pe=dn(),Te=v==="cookies"||v==="off"?v:"cookieless",be=r("replay",false),ae="",V,ge=null,Y,P=null,re=false,me=false,oe=null,we=null,N=window.location.pathname,te=[],xe=new Set,Ce=[],B=()=>S&&pe?"off":Te,D=()=>!X&&B()!=="off",q=()=>V!=null?V:ae,Z=()=>B()==="cookies"?q():V,z=o=>Kt(ge,o);l||ee('No public key. Add data-key="mrr_pub_\u2026" to the script tag; nothing is tracked until then.');let he=(o=false)=>{if(!te.length)return;if(!l){te.length=0;return}let d=`${g}/api/sdk/events`;for(let u of Ft(l,te.splice(0),{v:je,errors:O,platform:"web"},z(Z())))o&&"sendBeacon"in navigator&&navigator.sendBeacon(d,u)||fetch(d,{method:"POST",headers:{"content-type":"application/json"},body:u,keepalive:true}).then(E=>{E.status===401?Oe(401):E.ok||ee(`Events were rejected with ${E.status}. Check data-key (MRRocket \u203A Settings \u203A Products).`);}).catch(()=>ee(`Could not reach ${g||"this origin"} to send events. Check data-api-host.`));},T=null,J=null,t=(o,d,u=Date.now(),y)=>{if(!D())return;let E=sn(o)?ut():null;te.push({event:o,props:E?{...d,$referral:{code:E.code,clickId:E.clickId}}:d,distinctId:Z(),sessionId:gt(B()==="cookies"),ts:u,url:y!=null?y:window.location.href,referrer:L.referrer,...L.utm,screen:{w:window.screen.width,h:window.screen.height}});},i=(o,d)=>{typeof o!="string"||!o||(t(o,d),D()&&(T==null||T.event(o)),a.onEvent(o));},a=Jt(en({host:g,apiKey:l,track:t,personId:()=>D()?V:void 0,userHash:z,canStore:()=>B()==="cookies",auto:r("onboarding",true)})),p=false,m;a.subscribe(()=>{p||!a.view()||X||(p=true,A("flows","__mrrocketFlows").then(o=>o.mountFlows(a,ne)).catch(()=>{p=false,ee("The cancel flow and onboarding dialogs did not load. Check that sdk-flows.js is served next to sdk.js.");}));});let R=(o,d)=>{if(!D())return;let u=`${window.location.pathname}|${o}`;xe.has(u)||(xe.add(u),i("$exposure",{experiment:o,variant:d}));},f=()=>{let o=Dt(P,window.location.href,q(),K);return o!=null&&o.to?(he(true),window.location.replace(o.to),true):(o!=null&&o.experiment&&R(o.experiment,o.variant),false)},h=()=>{if(!P)return;let o=document.querySelectorAll("[data-ck-text]");if(!o.length)return;let d=Ht(P,q(),K),u=new Set;o.forEach(y=>{var Q,ue;let E=y.dataset.ckText;if(!E)return;u.add(E),y.dataset.ckDefault===void 0&&(y.dataset.ckDefault=(Q=y.textContent)!=null?Q:"");let $=(ue=d[E])!=null?ue:y.dataset.ckDefault;y.textContent!==$&&(y.textContent=$);});for(let y of P.experiments)y.variants.some(E=>{var $;return Object.keys(($=E.changes)!=null?$:{}).some(Q=>u.has(Q))})&&R(y.key,Pe(y.key,P,q(),K));},k=()=>{var o,d;return (d=(o=P==null?void 0:P.referral)==null?void 0:o.cookieDays)!=null?d:60},x=()=>_==="always"?B()!=="off":_==="consent"&&B()==="cookies",I=null,j=false,ce=()=>{if(!re||X)return;if(_==="off"||B()==="off"){rn(),(_==="off"||j)&&Ge();return}let o=window.location.href;I!==o&&(I=o,on({search:window.location.search,param:F,store:x(),days:k(),beacon:l?({code:d,clickId:u})=>fetch(`${g}/api/sdk/affiliate/click`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({key:l,code:d,clickId:u,url:o,referrer:document.referrer||void 0}),keepalive:true}).then(y=>y.ok?y.json():null).then(y=>{var E;return (E=y==null?void 0:y.clickId)!=null?E:null}):void 0}));},G=()=>{let o=x(),d=ut();o&&d?qe(d,k()):!o&&j&&Ge(),j=o;},Re=0,wt=false,ht=()=>{var y,E;let o=D()&&be&&!!(P!=null&&P.replay)&&!!l;if(o===wt)return;wt=o;let d=++Re;if(!o){T==null||T.stop(true),T=null;return}let u=(E=(y=P==null?void 0:P.replay)==null?void 0:y.sampleRate)!=null?E:.1;A("replay","__mrrocketReplay").then($=>$.startReplay({host:g,apiKey:l,sessionId:gt(B()==="cookies"),distinctId:Z(),identified:!!V,userHash:z(Z()),sampleRate:u,warn:ee})).then($=>{d!==Re?$==null||$.stop(true):T=$;}).catch(()=>ee("Session recording could not start (the recorder did not load)."));},kt=r("messenger",false),le=null,ve=o=>{X||l&&(le!=null||(le=A("messenger","__mrrocketMessenger").then(d=>{var $;let u=Q=>n(`messenger-${Q}`)===void 0?void 0:r(`messenger-${Q}`,true),y=n("messenger-position"),E=($=n("messenger-theme"))!=null?$:U;return d.mountMessenger({host:g,apiKey:l,distinctId:q,user:()=>Y,userHash:()=>z(q()),launcher:kt,position:y,corners:n("messenger-corners"),header:n("messenger-header"),font:n("messenger-font"),title:n("messenger-title"),greeting:n("messenger-greeting"),label:n("messenger-label"),askEmail:u("ask-email"),help:u("help"),sound:u("sound"),preview:u("preview"),theme:E==="light"||E==="dark"||E==="auto"?E:void 0,accent:n("accent")})})),le.then(o).catch(()=>{le=null,ee("sdk-messenger.js did not load.");}));},yt=n("forms")==="auto",et=false,tt=()=>{et||!l||X||!document.querySelector(yt?"form":"form[data-mrrocket-form]")||(et=true,A("forms","__mrrocketForms").then(o=>o.watchForms({host:g,apiKey:l,auto:yt,distinctId:()=>D()?Z():void 0,userHash:z,identified:()=>!!V,identify:Rt,tracking:D,referrer:()=>L.referrer,utm:()=>L.utm})).catch(()=>et=false));},nt=()=>{!me||!D()||we===window.location.pathname||(we=window.location.pathname,i("$pageview",{path:window.location.pathname}));},de=null,bt=()=>{let o=de;b&&o&&o.max>0&&t("$scroll",{depth:o.max,docH:o.docH,vw:window.innerWidth,vh:window.innerHeight},Date.now(),o.url),de=null;},Ie=()=>{var E,$;if(!b||!D()||X)return;let o=document.documentElement,d=Math.max(o.scrollHeight,($=(E=document.body)==null?void 0:E.scrollHeight)!=null?$:0),u=Mt(),y=window.location.href;(de==null?void 0:de.url)!==y?de={url:y,max:u,docH:d}:u>de.max&&(de={url:y,max:u,docH:d});},xt=()=>{let o=window.location.pathname;o!==N&&(N=o,!(re&&f())&&(bt(),mt(),T==null||T.page(o),J==null||J.crumb("navigation",o),nt(),ce(),window.setTimeout(()=>{Ie(),h(),tt();},0)));},Ct=()=>{let o=B(),d=oe;oe=o,d==="cookies"&&o!=="cookies"&&(Le(ke),Le(Se)),o==="off"&&(te.length=0,L.session=void 0),d==="cookies"&&o!=="cookies"&&Zt(),ae=pt(o),G(),ce(),ht(),nt(),Ie();},pn=o=>{let{analytics:d,replay:u}=typeof o=="string"?{analytics:o,replay:void 0}:o!=null?o:{};if(d!==void 0&&d!=="cookieless"&&d!=="cookies"&&d!=="off"){ee(`setConsent: "${String(d)}" is not a consent mode. Use "cookieless", "cookies" or "off".`);return}d==="off"&&(te.length=0),d&&(Te=d),typeof u=="boolean"&&(be=u),Ct(),re&&a.refresh();},Rt=(o,d,u)=>{if(typeof o!="string"||!o)return;let y=Z();ge=Wt(ge,o,u==null?void 0:u.hash),V=o,t("$identify",{...d,id:o,...y&&y!==o?{previousId:y}:{}}),T==null||T.identify(o,z(o)),B()==="cookies"&&Qe(ke,o,ft),Y={...d,id:o},h(),re&&a.refresh();},Ue={track:i,identify:Rt,reset:()=>{he(),V=void 0,ge=null,Y=void 0,xe.clear(),B()==="cookies"&&(Le(ke),Le(Se)),L.id=void 0,L.session=void 0,ae=pt(B()),h(),re&&a.refresh();},captureError:o=>J==null?void 0:J.capture(o,"manual"),setConsent:pn,getFlag:o=>it(o,P,q(),{...Y})!==false,getFlagVariant:o=>{let d=it(o,P,q(),{...Y});return typeof d=="string"?d:null},getVariant:o=>{let d=Pe(o,P,q(),K);return (P||K[o])&&R(o,d),d},ready:o=>{typeof o=="function"&&(re?window.setTimeout(()=>o(Ue),0):Ce.push(o));},getDistinctId:q,cancelFlow:{open:o=>a.openCancelFlow(o)},onboarding:{start:o=>a.startOnboarding(o)},openCancelFlow:o=>a.openCancelFlow(o),startOnboarding:o=>a.startOnboarding(o),paywall:{open:(o,d)=>(m!=null?m:m=A("flows","__mrrocketFlows").then(u=>u.paywallHost({config:()=>P,distinctId:q,track:t},ne))).then(u=>u.open(o,d))},push:{subscribe:o=>{let d=D()?V:void 0;if(!d)return Promise.resolve({status:"not-signed-in"});let u=window.Notification,y=Promise.resolve(u&&u.permission==="default"&&(o==null?void 0:o.ask)!==false?u.requestPermission():u==null?void 0:u.permission);return A("push","__mrrocketPush").then(E=>E.subscribeWebPush({host:g,apiKey:l,distinctId:d,userHash:z(d),permission:y},o))},unsubscribe:()=>A("push","__mrrocketPush").then(o=>o.unsubscribeWebPush({host:g,apiKey:l,distinctId:V,userHash:z(V)}))},messenger:{open:o=>ve(d=>d.open(o)),close:()=>{le==null?void 0:le.then(o=>o.close()).catch(()=>{});},toggle:()=>ve(o=>o.toggle())},openMessenger:()=>ve(o=>o.open()),version:je};mt(),Ct();let Ee=Ze.mrrocket,gn=(St=Ee==null?void 0:Ee.q)!=null?St:[],rt=Ee&&typeof Ee=="object"?Ee:{};Object.assign(rt,Ue,{__loaded:true}),delete rt.q,Ze.mrrocket=rt;for(let[o,d]of gn){let u=Ue[o];if(typeof u=="function")try{u(...Array.from(d!=null?d:[]));}catch(y){console.error(y);}}me=true,nt(),O&&l&&!X&&(J=Bt({host:g,apiKey:l,release:w,context:()=>{var o;return {send:D(),distinctId:Z(),sessionId:(o=L.session)==null?void 0:o.id,userHash:z(Z())}},warn:ee}),J.crumb("navigation",window.location.pathname));for(let o of ["pushState","replaceState"]){let d=history[o];history[o]=function(...u){let y=d.apply(this,u);return xt(),y};}window.addEventListener("popstate",xt);let mn=new Fe;document.addEventListener("click",o=>{var $;o.target instanceof Element&&o.target.closest("[data-ck-messenger]")&&(o.preventDefault(),ve(Q=>Q.open()));let d=o.target instanceof Element?o.target.closest("[data-ck-goal]"):null;if(d!=null&&d.dataset.ckGoal&&i(d.dataset.ckGoal,{text:($=d.textContent)==null?void 0:$.trim().slice(0,80)}),!D())return;let u=Pt(o);if(!u)return;let y=mn.push(u.x,u.y,Date.now());if((u.label||u.selector)&&(J==null||J.crumb("click",u.label||u.selector)),T==null||T.click(u,y),!b)return;let E={x:u.x,y:u.y,vw:u.vw,vh:u.vh,docH:u.docH,selector:u.selector,label:u.label,dead:!u.interactive};t("$click",E),y&&t("$rageclick",E);});let ot=0;window.addEventListener("scroll",()=>{ot||(ot=window.requestAnimationFrame(()=>{ot=0,Ie();}));},{passive:true}),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>Ie()):Ie(),window.setInterval(()=>he(),2e3),window.addEventListener("pagehide",()=>{bt(),he(true);});let st=()=>{if(re=true,f())return;let o=jt(P,fe);o&&R(o.experiment,o.variant),document.documentElement.classList.remove("ck-hide"),ce(),ht(),a.setConfig(P),a.refresh(),kt&&(document.body?ve():document.addEventListener("DOMContentLoaded",()=>ve())),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{h(),tt();}):(h(),tt());for(let d of Ce.splice(0))try{d(Ue);}catch(u){console.error(u);}};l?fetch(`${g}/api/sdk/config?key=${encodeURIComponent(l)}`).then(o=>(o.ok||ee(`Config request to ${g||"this origin"} answered ${o.status}. Check data-key and data-api-host.`),o.ok?o.json():null)).then(o=>{o&&Array.isArray(o.experiments)&&(P=o),st();}).catch(()=>{ee(`Could not reach ${g||"this origin"}. Check data-api-host. The page keeps its own texts and flags stay off.`),st();}):st();},fn;typeof window!="undefined"&&typeof document!="undefined"&&!((fn=Ze.mrrocket)!=null&&fn.__loaded)&&rr();
|
|
2
2
|
})();
|
package/dist/client.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { PushResult, WebPushOptions } from "./push-web.js";
|
|
|
5
5
|
import { type CancelFlowOptions, type CancelFlowResult } from "./flows.js";
|
|
6
6
|
import type { FlowsTheme } from "./flows-ui.js";
|
|
7
7
|
import { type PaywallOptions, type PaywallResult } from "./paywall.js";
|
|
8
|
+
import { type IdentifyOptions } from "./identity.js";
|
|
8
9
|
export interface CockpitProviderProps {
|
|
9
10
|
/** The product's public key from Cockpit › Settings › SDK. Safe in the browser. Default: `NEXT_PUBLIC_MRROCKET_KEY`. */
|
|
10
11
|
apiKey?: string;
|
|
@@ -16,6 +17,13 @@ export interface CockpitProviderProps {
|
|
|
16
17
|
config?: CockpitConfig;
|
|
17
18
|
/** Your own id for this visitor, for example a signed-in user id. Keeps variants stable without cookies. */
|
|
18
19
|
distinctId?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The identity hash of `distinctId` (0.16.0): `await userHash(user.id)` from `@mrrocket/sdk/next/server`, made in
|
|
22
|
+
* the server layout that knows the user. Sent with every request for that id, so MRRocket knows it is really them
|
|
23
|
+
* (needed with MRRocket › Settings › Products › Sign-in › "Only signed users"). In the browser pass it to
|
|
24
|
+
* `identify(id, props, { hash })` instead.
|
|
25
|
+
*/
|
|
26
|
+
userHash?: string;
|
|
19
27
|
/**
|
|
20
28
|
* "cookieless" (default) stores nothing in the browser, "cookies" keeps a visitor cookie for a year, "off" sends
|
|
21
29
|
* nothing. The SDK does not remember the choice: set it on every page load, from the prop or setConsent().
|
|
@@ -74,7 +82,7 @@ export interface CockpitProviderProps {
|
|
|
74
82
|
* `preview` forces variants for this render, for example from the `ck_preview` search param on the server,
|
|
75
83
|
* so a Cockpit preview never flickers. Without it the provider reads the param itself after the first render.
|
|
76
84
|
*/
|
|
77
|
-
export declare const CockpitProvider: ({ apiKey: apiKeyProp, host: hostProp, preview: forced, embedded: embeddedProp, config: bootstrapConfig, distinctId: bootstrapId, consent: consentProp, respectDnt, replay: replayProp, heatmaps, surveys, errors, release, attribution, referralParam, onboarding, appearance, forms, children, }: CockpitProviderProps) => import("react").JSX.Element;
|
|
85
|
+
export declare const CockpitProvider: ({ apiKey: apiKeyProp, host: hostProp, preview: forced, embedded: embeddedProp, config: bootstrapConfig, distinctId: bootstrapId, userHash: bootstrapHash, consent: consentProp, respectDnt, replay: replayProp, heatmaps, surveys, errors, release, attribution, referralParam, onboarding, appearance, forms, children, }: CockpitProviderProps) => import("react").JSX.Element;
|
|
78
86
|
/**
|
|
79
87
|
* `track`, `identify`, `captureError`, the consent mode, the replay consent and their setter, the visitor id and whether
|
|
80
88
|
* the experiments and flags have loaded. `setConsent("cookies")` sets the mode, `setConsent({ replay: true })` the
|
|
@@ -82,7 +90,7 @@ export declare const CockpitProvider: ({ apiKey: apiKeyProp, host: hostProp, pre
|
|
|
82
90
|
*/
|
|
83
91
|
export declare const useCockpit: () => {
|
|
84
92
|
track: (event: string, props?: Record<string, unknown>) => void;
|
|
85
|
-
identify: (id: string, props?: Record<string, unknown
|
|
93
|
+
identify: (id: string, props?: Record<string, unknown>, options?: IdentifyOptions) => void;
|
|
86
94
|
captureError: (error: unknown) => void;
|
|
87
95
|
distinctId: string;
|
|
88
96
|
ready: boolean;
|
package/dist/client.js
CHANGED
|
@@ -39,6 +39,7 @@ import { createFlows } from "./flows.js";
|
|
|
39
39
|
import { startPicker } from "./pick.js";
|
|
40
40
|
import { forgetFlowsStorage, webFlowsEnv } from "./flows-web.js";
|
|
41
41
|
import { createPaywallHost } from "./paywall.js";
|
|
42
|
+
import { hashFor, nextSigned, warnUnsigned } from "./identity.js";
|
|
42
43
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
43
44
|
var warned = /* @__PURE__ */ new Set();
|
|
44
45
|
var warnOnce = (message) => {
|
|
@@ -53,6 +54,7 @@ var CockpitProvider = ({
|
|
|
53
54
|
embedded: embeddedProp,
|
|
54
55
|
config: bootstrapConfig,
|
|
55
56
|
distinctId: bootstrapId,
|
|
57
|
+
userHash: bootstrapHash,
|
|
56
58
|
consent: consentProp = "cookieless",
|
|
57
59
|
respectDnt = false,
|
|
58
60
|
replay: replayProp = false,
|
|
@@ -81,17 +83,24 @@ var CockpitProvider = ({
|
|
|
81
83
|
const [urlEmbedded, setUrlEmbedded] = useState(false);
|
|
82
84
|
const [user, setUser] = useState();
|
|
83
85
|
const [ready, setReady] = useState(!!bootstrapConfig);
|
|
86
|
+
const [signed, setSigned] = useState(null);
|
|
87
|
+
const signedRef = useRef(null);
|
|
84
88
|
const queue = useRef([]);
|
|
85
89
|
const early = useRef([]);
|
|
86
90
|
const exposed = useRef(/* @__PURE__ */ new Set());
|
|
87
91
|
const lastPage = useRef(null);
|
|
88
92
|
const bootstrap = bootstrapId && bootstrapId !== "anonymous" ? bootstrapId : void 0;
|
|
93
|
+
const bootSigned = useMemo(() => bootstrap && bootstrapHash ? nextSigned(null, bootstrap, bootstrapHash) : null, [bootstrap, bootstrapHash]);
|
|
94
|
+
const bootSignedRef = useRef(bootSigned);
|
|
95
|
+
bootSignedRef.current = bootSigned;
|
|
96
|
+
const hashOf = useCallback((id) => hashFor(signedRef.current, id) ?? hashFor(bootSignedRef.current, id), []);
|
|
89
97
|
const preview = useMemo(() => ({ ...urlPreview, ...forced }), [urlPreview, forced]);
|
|
90
98
|
const embedded = embeddedProp ?? urlEmbedded;
|
|
91
99
|
const effectiveConsent = respectDnt && dnt ? "off" : consent;
|
|
92
100
|
const distinctId = identified ?? bootstrap ?? visitor?.id ?? "anonymous";
|
|
93
101
|
const tracking = !embedded && effectiveConsent !== "off" && visitor?.mode === effectiveConsent;
|
|
94
102
|
const sendId = effectiveConsent === "cookies" ? distinctId : identified;
|
|
103
|
+
const userHash = hashFor(signed, distinctId) ?? hashFor(bootSigned, distinctId);
|
|
95
104
|
useEffect(() => {
|
|
96
105
|
const params = new URLSearchParams(window.location.search);
|
|
97
106
|
setUrlPreview(parsePreview(params.get(PREVIEW_PARAM)));
|
|
@@ -165,15 +174,16 @@ var CockpitProvider = ({
|
|
|
165
174
|
return;
|
|
166
175
|
}
|
|
167
176
|
const url = `${host}/api/sdk/events`;
|
|
168
|
-
for (const body of bodies(apiKey, queue.current.splice(0), { v: SDK_VERSION, errors })) {
|
|
177
|
+
for (const body of bodies(apiKey, queue.current.splice(0), { v: SDK_VERSION, errors }, hashOf(live.current.sendId))) {
|
|
169
178
|
const sent = beacon && typeof navigator !== "undefined" && "sendBeacon" in navigator && navigator.sendBeacon(url, body);
|
|
170
179
|
if (!sent)
|
|
171
180
|
fetch(url, { method: "POST", headers: { "content-type": "application/json" }, body, keepalive: true }).then((r) => {
|
|
172
|
-
if (
|
|
181
|
+
if (r.status === 401) warnUnsigned(401);
|
|
182
|
+
else if (!r.ok) warnOnce(`Events were rejected with ${r.status}. Check the public key (Settings \u203A SDK) and NEXT_PUBLIC_MRROCKET_HOST.`);
|
|
173
183
|
}).catch(() => warnOnce(`Could not reach ${host || "this origin"} to send events. Check NEXT_PUBLIC_MRROCKET_HOST.`));
|
|
174
184
|
}
|
|
175
185
|
},
|
|
176
|
-
[apiKey, host, errors]
|
|
186
|
+
[apiKey, host, errors, hashOf]
|
|
177
187
|
);
|
|
178
188
|
useEffect(() => {
|
|
179
189
|
const timer = window.setInterval(() => flush(), 2e3);
|
|
@@ -216,6 +226,7 @@ var CockpitProvider = ({
|
|
|
216
226
|
apiKey,
|
|
217
227
|
track: (event, props) => record(event, props),
|
|
218
228
|
personId: () => live.current.tracking && live.current.identified ? live.current.distinctId : void 0,
|
|
229
|
+
userHash: hashOf,
|
|
219
230
|
canStore: () => live.current.persist,
|
|
220
231
|
auto: onboarding
|
|
221
232
|
})
|
|
@@ -235,21 +246,23 @@ var CockpitProvider = ({
|
|
|
235
246
|
[record, flows]
|
|
236
247
|
);
|
|
237
248
|
const identify = useCallback(
|
|
238
|
-
(id, props) => {
|
|
249
|
+
(id, props, options) => {
|
|
239
250
|
const now = live.current;
|
|
240
251
|
if (!now.resolved) {
|
|
241
|
-
early.current.push(() => identify(id, props));
|
|
252
|
+
early.current.push(() => identify(id, props, options));
|
|
242
253
|
return;
|
|
243
254
|
}
|
|
244
255
|
const previous = now.sendId;
|
|
256
|
+
signedRef.current = nextSigned(signedRef.current ?? bootSignedRef.current, id, options?.hash);
|
|
257
|
+
setSigned(signedRef.current);
|
|
245
258
|
live.current = { ...now, distinctId: id, sendId: id, identified: true };
|
|
246
259
|
record("$identify", { ...props, id, ...previous && previous !== id ? { previousId: previous } : {} });
|
|
247
|
-
replayer.current?.identify(id);
|
|
260
|
+
replayer.current?.identify(id, hashOf(id));
|
|
248
261
|
if (now.persist) writeCookie(ID_COOKIE, id, YEAR_S);
|
|
249
262
|
setIdentified(id);
|
|
250
263
|
setUser({ id, ...props });
|
|
251
264
|
},
|
|
252
|
-
[record]
|
|
265
|
+
[record, hashOf]
|
|
253
266
|
);
|
|
254
267
|
const identifyRef = useRef(identify);
|
|
255
268
|
identifyRef.current = identify;
|
|
@@ -264,6 +277,7 @@ var CockpitProvider = ({
|
|
|
264
277
|
apiKey,
|
|
265
278
|
auto: forms === "auto",
|
|
266
279
|
distinctId: () => live.current.tracking ? live.current.sendId : void 0,
|
|
280
|
+
userHash: hashOf,
|
|
267
281
|
identified: () => live.current.identified,
|
|
268
282
|
identify: (id, props) => identifyRef.current(id, props),
|
|
269
283
|
tracking: () => live.current.tracking,
|
|
@@ -275,7 +289,7 @@ var CockpitProvider = ({
|
|
|
275
289
|
gone = true;
|
|
276
290
|
off?.();
|
|
277
291
|
};
|
|
278
|
-
}, [forms, apiKey, host, embedded]);
|
|
292
|
+
}, [forms, apiKey, host, embedded, hashOf]);
|
|
279
293
|
useEffect(() => {
|
|
280
294
|
if (!visitor) return;
|
|
281
295
|
for (const run of early.current.splice(0)) run();
|
|
@@ -364,7 +378,7 @@ var CockpitProvider = ({
|
|
|
364
378
|
host,
|
|
365
379
|
apiKey,
|
|
366
380
|
release,
|
|
367
|
-
context: () => ({ send: live.current.tracking, distinctId: live.current.sendId, sessionId: page.session?.id }),
|
|
381
|
+
context: () => ({ send: live.current.tracking, distinctId: live.current.sendId, sessionId: page.session?.id, userHash: hashOf(live.current.sendId) }),
|
|
368
382
|
warn: warnOnce
|
|
369
383
|
});
|
|
370
384
|
errorer.current = capture;
|
|
@@ -373,7 +387,7 @@ var CockpitProvider = ({
|
|
|
373
387
|
capture.stop();
|
|
374
388
|
if (errorer.current === capture) errorer.current = null;
|
|
375
389
|
};
|
|
376
|
-
}, [errors, apiKey, host, release, embedded]);
|
|
390
|
+
}, [errors, apiKey, host, release, embedded, hashOf]);
|
|
377
391
|
const captureError = useCallback((error) => errorer.current?.capture(error, "manual"), []);
|
|
378
392
|
useEffect(() => {
|
|
379
393
|
if (!tracking || lastPage.current === pathname) return;
|
|
@@ -450,6 +464,7 @@ var CockpitProvider = ({
|
|
|
450
464
|
sessionId: touchSession(live.current.persist),
|
|
451
465
|
distinctId: live.current.sendId,
|
|
452
466
|
identified: live.current.identified,
|
|
467
|
+
userHash: hashOf(live.current.sendId),
|
|
453
468
|
sampleRate: replayConfig.sampleRate,
|
|
454
469
|
warn: warnOnce
|
|
455
470
|
})
|
|
@@ -462,7 +477,7 @@ var CockpitProvider = ({
|
|
|
462
477
|
handle?.stop(true);
|
|
463
478
|
if (replayer.current === handle) replayer.current = null;
|
|
464
479
|
};
|
|
465
|
-
}, [recording, replayConfig, host, apiKey]);
|
|
480
|
+
}, [recording, replayConfig, host, apiKey, hashOf]);
|
|
466
481
|
useEffect(() => {
|
|
467
482
|
if (!ready || !visitor || embedded) return;
|
|
468
483
|
flows.setConfig(config);
|
|
@@ -511,13 +526,17 @@ var CockpitProvider = ({
|
|
|
511
526
|
if (!distinctId2) return Promise.resolve({ status: "not-signed-in" });
|
|
512
527
|
const N = window.Notification;
|
|
513
528
|
const permission = Promise.resolve(N && N.permission === "default" && options?.ask !== false ? N.requestPermission() : N?.permission);
|
|
514
|
-
return import("./push-web.js").then((m) => m.subscribeWebPush({ host, apiKey, distinctId: distinctId2, permission }, options));
|
|
529
|
+
return import("./push-web.js").then((m) => m.subscribeWebPush({ host, apiKey, distinctId: distinctId2, userHash: hashOf(distinctId2), permission }, options));
|
|
515
530
|
},
|
|
516
|
-
[host, apiKey]
|
|
531
|
+
[host, apiKey, hashOf]
|
|
517
532
|
);
|
|
518
533
|
const unsubscribeFromPush = useCallback(
|
|
519
|
-
() =>
|
|
520
|
-
|
|
534
|
+
() => {
|
|
535
|
+
if (typeof window === "undefined") return Promise.resolve(false);
|
|
536
|
+
const distinctId2 = live.current.identified ? live.current.distinctId : void 0;
|
|
537
|
+
return import("./push-web.js").then((m) => m.unsubscribeWebPush({ host, apiKey, distinctId: distinctId2, userHash: hashOf(distinctId2) }));
|
|
538
|
+
},
|
|
539
|
+
[host, apiKey, hashOf]
|
|
521
540
|
);
|
|
522
541
|
const texts = useMemo(() => textChanges(config, distinctId, preview), [config, distinctId, preview]);
|
|
523
542
|
const value = useMemo(
|
|
@@ -527,6 +546,7 @@ var CockpitProvider = ({
|
|
|
527
546
|
user,
|
|
528
547
|
ready,
|
|
529
548
|
distinctId,
|
|
549
|
+
userHash,
|
|
530
550
|
config,
|
|
531
551
|
preview,
|
|
532
552
|
embedded,
|
|
@@ -551,6 +571,7 @@ var CockpitProvider = ({
|
|
|
551
571
|
user,
|
|
552
572
|
ready,
|
|
553
573
|
distinctId,
|
|
574
|
+
userHash,
|
|
554
575
|
config,
|
|
555
576
|
preview,
|
|
556
577
|
embedded,
|