@mrrocket/sdk 0.14.0 → 0.15.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.
@@ -1,2 +1,2 @@
1
- (function(){'use strict';var sn=Object.defineProperty;var an=(e,t,r)=>t in e?sn(e,t,{enumerable:true,configurable:true,writable:true,value:r}):e[t]=r;var we=(e,t,r)=>an(e,typeof t!="symbol"?t+"":t,r);var Rt=e=>{let t=0;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);s<128?t+=1:s<2048?t+=2:s>=55296&&s<=56319&&r+1<e.length&&(e.charCodeAt(r+1)&64512)===56320?(t+=4,r++):t+=3;}return t},cn=(e,t,r)=>{let s=`{"key":${JSON.stringify(e)},"sdk":${JSON.stringify(r)},"events":[`,c=Rt(s)+2,a=[],f=[],C=[],v=c,k=()=>{f.length&&a.push({body:`${s}${f.join(",")}]}`,events:C}),f=[],C=[],v=c;};for(let E of t){let g=JSON.stringify(E),h=Rt(g)+1;c+h>6e4||((f.length===100||v+h>6e4)&&k(),f.push(g),C.push(E),v+=h);}return k(),a},vt=(e,t,r)=>cn(e,t,r).map(s=>s.body);var xe=class{constructor(t=1e3,r=30,s=3){we(this,"windowMs",t);we(this,"radius",r);we(this,"count",s);we(this,"clicks",[]);we(this,"fired",false);}push(t,r,s){let c=this.clicks.filter(a=>s-a.t<=this.windowMs&&Math.hypot(a.x-t,a.y-r)<=this.radius);return c.length!==this.clicks.length&&(this.fired=false),this.clicks=[...c,{x:t,y:r,t:s}],this.clicks.length>=this.count&&!this.fired?(this.fired=true,true):false}};var ln='a[href],button,input,select,textarea,label,summary,[role="button"],[role="link"],[role="tab"],[role="menuitem"],[role="checkbox"],[role="switch"],[onclick],[data-ck-goal]',dn="[data-ck-mask]",un="[data-ck-block]",Et=/\d{4,}|^[a-z]{1,3}-[a-z0-9]{5,}$|^_|__|css-|^sc-|^jsx-/i,fn=e=>{let t=e.tagName.toLowerCase();if(e.id&&!Et.test(e.id)&&e.id.length<=40)return `${t}#${e.id}`;let r=typeof e.className=="string"?e.className.split(/\s+/).filter(a=>a&&!Et.test(a)&&a.length<=30&&!a.includes(":")):[],s=r.length?`${t}.${r.slice(0,2).join(".")}`:t,c=e.parentElement?[...e.parentElement.children].filter(a=>a.tagName===e.tagName):[];return c.length>1?`${s}:nth-of-type(${c.indexOf(e)+1})`:s},pn=e=>{let t=[],r=e;for(;r&&t.length<3&&r.tagName&&r.tagName!=="BODY"&&r.tagName!=="HTML";){let s=fn(r);if(t.unshift(s),s.includes("#"))break;r=r.parentElement;}return t.join(" > ").slice(0,160)},Pe=e=>(e!=null?e:"").replace(/\s+/g," ").trim().slice(0,40),gn=e=>{var r,s,c,a,f;if(e.closest(`${dn},${un}`))return "";let t=e.tagName.toLowerCase();if(t==="input"){let C=((r=e.getAttribute("type"))!=null?r:"text").toLowerCase();return Pe(C==="submit"||C==="button"?(s=e.getAttribute("aria-label"))!=null?s:e.value:e.getAttribute("aria-label"))}return Pe(t==="select"||t==="textarea"?e.getAttribute("aria-label"):(f=(a=(c=e.getAttribute("aria-label"))!=null?c:e.getAttribute("title"))!=null?a:e.innerText)!=null?f:e.textContent)},_t=e=>{var a,f;let t=e.target instanceof Element?e.target:null;if(!t)return null;let r=t.closest(ln),s=r!=null?r:t,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,(f=(a=document.body)==null?void 0:a.scrollHeight)!=null?f:0),selector:pn(s),label:r?gn(r):"",interactive:!!r}},St=()=>{var r,s;let e=document.documentElement,t=Math.max(e.scrollHeight,(s=(r=document.body)==null?void 0:r.scrollHeight)!=null?s:0);return t?Math.min(100,Math.round((window.scrollY+window.innerHeight)/t*100)):0};var Me="0.14.0",mn=(e,t)=>{let r=t.trim().toLowerCase();for(let[s,c]of Object.entries(e))if(s.toLowerCase()===r)return c},wn=(e,t)=>{let r=e.trim().toLowerCase(),s=t.trim().toLowerCase();return s.startsWith("@")?r.endsWith(s):r===s},hn=(e,t)=>{if(e.op==="in cohort")return false;let r=mn(t,e.property),s=r==null?"":String(r);if(e.op==="\u2265"){let a=Number(s),f=Number(e.values[0]);return s!==""&&Number.isFinite(a)&&Number.isFinite(f)&&a>=f}let c=s!==""&&e.values.some(a=>wn(s,a));return e.op==="is"||e.op==="in"?c:!c},kn=(e,t,r={})=>{var C;if(!e.on)return false;let s={id:t,...r},c=e.sets.length?e.sets.find(v=>v.conditions.every(k=>hn(k,s))):{rollout:100};if(!c||It(`${e.key}:rollout:${t}`)*100>=c.rollout)return false;if(!((C=e.variants)!=null&&C.length))return true;let a=It(`${e.key}:variant:${t}`)*100,f=0;for(let v of e.variants)if(f+=v.split,a<f)return v.key;return e.variants[e.variants.length-1].key},Ze=(e,t,r,s={})=>{var a;let c=(a=t==null?void 0:t.flags)==null?void 0:a.find(f=>f.key===e);return c?kn(c,r,s):false},yn=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],Ot="ck_preview",Ft="ck_embed",ce="ck_id",he="ck_sid";var bn=e=>{var r;let t={};for(let s of yn){let c=(r=e(s))==null?void 0:r.trim();c&&(t[s]=c.slice(0,150));}return t},Pt=e=>{let t=new URLSearchParams(e);return bn(r=>t.get(r))};var xn=e=>{let t=2166136261;for(let r=0;r<e.length;r++)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return (t>>>0)/4294967296},It=e=>{let t=2166136261;for(let r=0;r<e.length;r++)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return t^=t>>>16,t=Math.imul(t,2246822507),t^=t>>>13,t=Math.imul(t,3266489909),t^=t>>>16,(t>>>0)/4294967296},Cn=(e,t)=>{var a,f,C,v;let r=(f=(a=e.variants[0])==null?void 0:a.id)!=null?f:"control";if(e.winner)return e.winner;if(e.status!=="running")return r;let s=xn(`${e.key}:${t}`),c=0;for(let k of e.variants)if(c+=k.weight,s<c)return k.id;return (v=(C=e.variants[e.variants.length-1])==null?void 0:C.id)!=null?v:r},$t=e=>{let t=Array.isArray(e)?e[0]:e;if(!t)return {};let r={};for(let s of t.split(",")){let[c,a]=s.split(":");c&&a&&(r[c.trim()]=a.trim());}return r};var Re=(e,t,r,s)=>{if(s[e])return s[e];let c=t==null?void 0:t.experiments.find(a=>a.key===e);return c?Cn(c,r):"control"},Mt=(e,t,r)=>{var c,a,f,C,v,k;let s={...(c=e==null?void 0:e.texts)!=null?c:{}};for(let E of (a=e==null?void 0:e.experiments)!=null?a:[]){let g=Re(E.key,e,t,r);g!==((C=(f=E.variants[0])==null?void 0:f.id)!=null?C:"control")&&Object.assign(s,(k=(v=E.variants.find(h=>h.id===g))==null?void 0:v.changes)!=null?k:{});}return s},Ce="ck_x",$e=e=>e.replace(/\/+$/,"")||"/",At=(e,t,r,s={})=>{var C,v;if(!e)return null;let c;try{c=new URL(t);}catch(k){return null}if(c.searchParams.has(Ce))return null;let a=$e(c.pathname),f=(k,E)=>{let g;try{g=new URL(k,c);}catch(h){return}if(!(!/^https?:$/.test(g.protocol)||g.origin===c.origin&&$e(g.pathname)===a))return c.searchParams.forEach((h,S)=>{g.searchParams.has(S)||g.searchParams.set(S,h);}),E&&g.searchParams.set(Ce,E),g.hash||(g.hash=c.hash),g.href};for(let k of (C=e.redirects)!=null?C:[]){let E=k.from&&$e(k.from)===a?f(k.to):void 0;if(E)return {to:E}}for(let k of e.experiments){if(!k.path||$e(k.path)!==a)continue;let E=k.status==="running"&&!k.winner;if(E&&r===null&&!s[k.key])return null;let g=Re(k.key,e,r!=null?r:"",s),h=(v=k.variants.find($=>$.id===g))==null?void 0:v.url,S=h?f(h,E?`${k.key}:${g}`:void 0):void 0;return E?{to:S,experiment:k.key,variant:g}:S?{to:S}:null}return null},Nt=(e,t)=>{let[r,s]=(t!=null?t:"").split(":"),c=e==null?void 0:e.experiments.find(a=>a.key===r);return c&&c.variants.some(a=>a.id===s)?{experiment:r,variant:s}:null};var et=()=>typeof crypto!="undefined"&&"randomUUID"in crypto?crypto.randomUUID():`ck_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;var ve=(e,t)=>e.length>t?`${e.slice(0,t-1)}\u2026`:e,Rn=e=>{var t;if(e instanceof Error)return {type:e.name||"Error",message:ve(e.message||String(e),1e3),stack:e.stack?ve(e.stack,8192):void 0};if(typeof e=="string")return {type:"Error",message:ve(e,1e3)};try{return {type:"Error",message:ve((t=JSON.stringify(e))!=null?t:String(e),1e3)}}catch(r){return {type:"Error",message:String(e)}}},Lt=e=>{let t=[],r=[],s=new Set,c=0,a=`${e.host}/api/sdk/errors`,f=(h=false)=>{for(;t.length;){let S=JSON.stringify({key:e.apiKey,errors:t.splice(0,4)});h&&typeof navigator!="undefined"&&"sendBeacon"in navigator&&navigator.sendBeacon(a,S)||fetch(a,{method:"POST",headers:{"content-type":"application/json"},body:S,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(()=>{});}},C=(h,S="manual")=>{let $=e.context();if(!$.send||c>=20)return;let L=Rn(h);if(/\/api\/sdk\/errors/.test(L.message))return;let N=`${L.type}:${L.message}`;s.has(N)||(s.add(N),c++,t.push({...L,mechanism:S,handled:S==="manual",url:window.location.href,ts:Date.now(),crumbs:r.slice(),...e.release?{release:e.release}:{},...$.distinctId?{distinctId:$.distinctId}:{},...$.sessionId?{sessionId:$.sessionId}:{}}));},v=h=>{var S;!h.error&&(!h.message||h.message==="Script error.")||C((S=h.error)!=null?S:new Error(h.message),"onerror");},k=h=>{var S;return C((S=h.reason)!=null?S:new Error("Unhandled promise rejection"),"onunhandledrejection")},E=()=>f(true);window.addEventListener("error",v),window.addEventListener("unhandledrejection",k),window.addEventListener("pagehide",E);let g=window.setInterval(()=>f(),2e3);return {capture:C,crumb:(h,S)=>{r.push({ts:Date.now(),type:h,message:ve(S,120)}),r.length>20&&r.shift();},stop:()=>{window.removeEventListener("error",v),window.removeEventListener("unhandledrejection",k),window.removeEventListener("pagehide",E),window.clearInterval(g),f(true);}}};var Ee="$cancel_flow",re="$onboarding",tt="$inapp",vn={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"},En="Something went wrong. Please try again.",Tt="mrrocket:onboarding",Ae=e=>e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),Dt=new Set(["signed_up","signup","sign_up","registered","account_created","user_signed_up"]),nt=(e,t)=>{let r=Ae(e),s=Ae(t);return !r||!s?false:r===s||Dt.has(r)&&Dt.has(s)},_n=e=>/^(first (launch|visit|open|session|login|sign ?in|app open)|app (opened|launched)|on load|every visit|always)?$/i.test(e.trim()),Sn=()=>`cf_${Math.random().toString(36).slice(2,10)}${Date.now().toString(36)}`;var In=e=>{let t=(e!=null?e:"").trim();return /^https?:\/\//i.test(t)||/^\/(?!\/)/.test(t)?t:void 0},le=e=>{var t;return (t=e.nodes)!=null?t:e.steps},On=e=>Math.max(0,e.amount)*(e.unit==="hours"?36e5:864e5),Fn=(e,t)=>{let r=e.trim(),s=(t.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(/\/+$/,"")||"/")},rt=e=>e.flatMap(t=>t.kind==="condition"?[...rt(t.yes),...rt(t.no)]:t.kind==="wait"?[]:[t]),Ut=e=>{let t=null,r=null,s=null,c=[],a=false,f=null,C,v=null,k=new Map,E=new Set,g=new Set,h=new Set,S=e.auto!==false,$=new Set,L=()=>{var n,i;return (i=(n=e.now)==null?void 0:n.call(e))!=null?i:Date.now()},N=null,z=()=>{var n;return (n=t==null?void 0:t.onboarding)!=null?n:[]},G=n=>n?z().find(i=>i.id===n):void 0,H=n=>{let i=k.get(n);return i||k.set(n,i={done:new Set,dismissed:false,answers:new Map,at:new Map,reached:new Map}),i},Q=false,W=n=>{e.track(re,n),Q=true;},oe=(n,i)=>{n.done.add(i),n.at.set(i,L());},Be=n=>{var i,l,m;if((i=n.page)!=null&&i.trim()){let p=(l=e.path)==null?void 0:l.call(e);return p===void 0?false:Fn(n.page,p)}if((m=n.event)!=null&&m.trim()){if(!a)return;for(let p of $)if(nt(n.event,p))return true;return false}return false},de=(n,i,l,m,p=0,_)=>{var I,b;for(let y=0;y<i.length;y++){let x=i[y];if(x.kind==="wait"){if(l.done.has(x.id)){_=(I=l.at.get(x.id))!=null?I:_;continue}let O=l.reached.get(x.id);if(O===void 0){if(!m)return {at:"pending"};O=_!=null?_:L(),l.reached.set(x.id,O),W({flow:n.id,step:x.id,kind:"wait",action:"shown"});}let B=O+On(x);if(L()<B)return {at:"wait",until:B};if(!m)return {at:"pending"};oe(l,x.id),W({flow:n.id,step:x.id,kind:"wait",action:"completed"}),_=B;continue}if(x.kind==="condition"){let O=l.answers.get(x.id);if(O===void 0){if(!m)return {at:"pending"};if(O=Be(x),O===void 0)return {at:"pending"};l.answers.set(x.id,O),W({flow:n.id,step:x.id,kind:"condition",action:"answered",answer:O?"yes":"no"});}return de(n,O?x.yes:x.no,l,m,p,_)}if(!l.done.has(x.id))return {at:"step",step:x,line:i,index:y,before:p};_=(b=l.at.get(x.id))!=null?b:_,p++;}return {at:"end"}},se=n=>{let i=k.get(n.id);return !!i&&(i.dismissed||de(n,le(n),i,false).at==="end")},ue=n=>`${Tt}:${n!=null?n:"visitor"}`,j=n=>`${Tt}:events:${n!=null?n:"visitor"}`,V=()=>{var l;Q=false;let n=(l=e.storage)==null?void 0:l.call(e);if(!n)return;let i={};for(let[m,p]of k)i[m]={done:[...p.done],...p.dismissed?{dismissed:true}:{},...p.answers.size?{answers:Object.fromEntries([...p.answers].map(([_,I])=>[_,I?"yes":"no"]))}:{},...p.at.size?{at:Object.fromEntries(p.at)}:{},...p.reached.size?{reached:Object.fromEntries(p.reached)}:{}};try{n.set(ue(e.personId()),JSON.stringify(i)),$.size&&n.set(j(e.personId()),JSON.stringify([...$].slice(-200)));}catch(m){}},P=n=>{var i,l,m,p;for(let[_,I]of Object.entries(n!=null?n:{})){let b=H(_);for(let y of (i=I.done)!=null?i:[])b.done.add(y);I.dismissed&&(b.dismissed=true);for(let[y,x]of Object.entries((l=I.answers)!=null?l:{}))b.answers.has(y)||b.answers.set(y,x==="yes");for(let[y,x]of Object.entries((m=I.at)!=null?m:{}))typeof x=="number"&&!b.at.has(y)&&b.at.set(y,x);for(let[y,x]of Object.entries((p=I.reached)!=null?p:{}))typeof x=="number"&&(!b.reached.has(y)||x<b.reached.get(y))&&b.reached.set(y,x);}},Z=n=>{var l;N&&clearTimeout(N),N=null;let i=n-L();i>0&&i<=864e5&&(N=setTimeout(()=>(N=null,M()),i+50),(l=N.unref)==null||l.call(N));},fe=false,ie=()=>{fe=false;let n=G(s);if(!n)return null;let i=H(n.id);if(i.dismissed)return null;let l=de(n,le(n),i,true);if(Q&&V(),l.at==="wait"&&Z(l.until),fe=l.at==="wait"||l.at==="pending",l.at!=="step")return null;let{step:m,line:p,index:_}=l,I=O=>!!O&&O.kind!=="wait"&&O.kind!=="condition";if(m.kind==="checklist"){let O=_;for(;O>0&&I(p[O-1])&&p[O-1].kind==="checklist";)O--;let B=_;for(;B+1<p.length&&I(p[B+1])&&p[B+1].kind==="checklist";)B++;let ye=p.slice(O,B+1).filter(I);for(let Y of ye)!i.done.has(Y.id)&&!g.has(`s:${Y.id}`)&&(g.add(`s:${Y.id}`),e.track(re,{flow:n.id,step:Y.id,kind:"checklist",action:"shown"}));return {type:"checklist",flow:n,items:ye.map(Y=>({step:Y,done:i.done.has(Y.id)}))}}g.has(`s:${m.id}`)||(g.add(`s:${m.id}`),e.track(re,{flow:n.id,step:m.id,kind:m.kind,action:"shown"}));let b=p.slice(_+1),y=b.findIndex(O=>O.kind==="condition"),x=(y<0?b:b.slice(0,y)).filter(I).length;return {type:"step",flow:n,step:m,index:l.before,total:l.before+1+x,last:!x&&y<0}},ae=()=>{if(r){let l=r.reason?r.flow.offers[r.reason]:void 0;return {type:"cancel",screen:r.screen,flow:r.flow,reason:r.reason,offer:r.screen==="offer"?l:void 0,price:r.options.price,busy:r.busy,error:r.error,step:r.plain||r.screen==="survey"?1:r.screen==="offer"?2:3,steps:r.plain?1:3}}let n=ie();if(n)return n;s&&!fe&&(s=null);let i=c.find(l=>!E.has(l.id));return i?{type:"message",message:i}:null},M=()=>{let n=ae();(n==null?void 0:n.type)==="message"&&!g.has(`m:${n.message.id}`)&&(g.add(`m:${n.message.id}`),e.track(tt,{message:n.message.id,journey:n.message.journey,action:"shown"}));for(let i of [...h])try{i();}catch(l){}},J=n=>s===n.id?true:s&&G(s)&&!se(G(s))?false:(s=n.id,e.track(re,{flow:n.id,action:"started"}),M(),true),ke=()=>{var i;if(!S||s||!a||!e.personId()&&!((i=e.storage)!=null&&i.call(e)))return;let n=z().find(l=>_n(l.trigger)&&le(l).length&&!se(l));n&&J(n);},Ie=()=>{let n=e.personId();v!==null&&v!==n&&(k.clear(),$.clear(),E.clear(),s=null,C=void 0),v=n;let i=(async()=>{var p,_,I;let l=(p=e.storage)==null?void 0:p.call(e);if(l)try{let b=await l.get(ue(n));b&&P(JSON.parse(b));let y=await l.get(j(n));if(y)for(let x of JSON.parse(y))typeof x=="string"&&$.add(x);}catch(b){}let m=z().length>0||!!(t!=null&&t.messages);if(n&&m&&C!==n){C=n;let b=await e.fetchInApp(n).catch(()=>null);if(b&&e.personId()===n){P(b.onboarding);for(let y of (_=b.events)!=null?_:[])typeof y=="string"&&$.add(Ae(y));c=((I=b.messages)!=null?I:[]).filter(y=>y&&y.id&&y.title);}}n||(c=[]),a=true,ke(),M();})();return f=i.finally(()=>{f===i&&(f=null);}),f},D=(n,i,l)=>{var p;let m=n.reason?n.flow.offers[n.reason]:void 0;return {outcome:i,run:n.run,...n.reason?{reason:n.reason,reasonLabel:(p=n.flow.reasons.find(_=>_.id===n.reason))==null?void 0:p.label}:{},...i==="saved"&&m?{offer:m}:{},...l!=null&&l.trim()?{comment:l.trim().slice(0,500)}:{}}},U=(n,i)=>{var l;e.track(Ee,{action:"finished",run:n.run,version:n.flow.version,outcome:i.outcome,customer:(l=n.options.customer)!=null?l:"consumer",...i.reason?{reason:i.reason}:{},...i.offer?{offer:i.offer.kind}:{},...i.comment?{comment:i.comment}:{}}),r===n&&(r=null),n.resolve(i),M();},K=(n,i,l)=>{if(n.busy)return;let m=D(n,i,l),p=i==="saved"?n.options.onSave:n.options.onCancel;n.busy=true,n.error=void 0,M(),Promise.resolve().then(()=>p==null?void 0:p(m)).then(()=>U(n,m),()=>{n.busy=false,n.error=En,M();});};return {setConfig:n=>{t=n,s&&!G(s)&&(s=null),M();},refresh:Ie,onEvent:n=>{var I;if(!n||n.startsWith("$"))return;let i=Ae(n),l=!!i&&!$.has(i);l&&$.add(i);let m=G(s),p=false;if(m){let b=H(m.id);for(let y of rt(le(m)))y.kind==="checklist"&&y.event&&!b.done.has(y.id)&&nt(y.event,n)&&(oe(b,y.id),p=true,e.track(re,{flow:m.id,step:y.id,kind:y.kind,action:"completed"}));}if(p||l&&m?(V(),M()):l&&V(),!S||!e.personId()&&!((I=e.storage)!=null&&I.call(e)))return;let _=z().find(b=>le(b).length&&nt(b.trigger,n)&&!se(b));_&&J(_);},openCancelFlow:(n={})=>{var I,b;if(r)return r.promise;let i=(I=t==null?void 0:t.cancelFlow)!=null?I:vn,l=n.customer!=="business"||i.reasons.length<2,m=()=>{},p=new Promise(y=>m=y),_={flow:i,options:n,plain:l,screen:l?"confirm":"survey",run:Sn(),busy:false,resolve:m,promise:p};return r=_,e.track(Ee,{action:"shown",run:_.run,version:i.version,customer:(b=n.customer)!=null?b:"consumer",plain:l}),M(),p},startOnboarding:n=>{let i=n?G(n):z().find(m=>le(m).length&&!se(m));if(!i||!le(i).length)return false;let l=H(i.id);return l.dismissed=false,J(i)},view:ae,subscribe:n=>(h.add(n),()=>h.delete(n)),cancel:{pick:n=>{!r||r.busy||!r.flow.reasons.some(i=>i.id===n)||(r.reason=n,r.error=void 0,M());},next:()=>{let n=r;!n||n.screen!=="survey"||!n.reason||(e.track(Ee,{action:"answered",run:n.run,version:n.flow.version,reason:n.reason}),n.screen=n.flow.offers[n.reason]?"offer":"confirm",M());},accept:n=>{let i=r;if(!i||i.screen!=="offer"||!i.reason)return;let l=i.flow.offers[i.reason];i.busy||e.track(Ee,{action:"offer",run:i.run,version:i.flow.version,reason:i.reason,offer:l==null?void 0:l.kind,outcome:"accepted"}),K(i,"saved",n);},decline:()=>{var i;let n=r;!n||n.screen!=="offer"||n.busy||(e.track(Ee,{action:"offer",run:n.run,version:n.flow.version,reason:n.reason,offer:n.reason?(i=n.flow.offers[n.reason])==null?void 0:i.kind:void 0,outcome:"declined"}),n.screen="confirm",n.error=void 0,M());},confirm:n=>{let i=r;!i||i.screen!=="confirm"||K(i,"cancelled",n);},close:()=>{var l,m;let n=r;if(!n||n.busy)return;let i=D(n,"kept");(m=(l=n.options).onClose)==null||m.call(l,i),U(n,i);}},onboarding:{next:()=>{let n=ie();(n==null?void 0:n.type)==="step"&&(oe(H(n.flow.id),n.step.id),e.track(re,{flow:n.flow.id,step:n.step.id,kind:n.step.kind,action:"completed"}),V(),M());},check:n=>{let i=ie();if((i==null?void 0:i.type)!=="checklist")return;let l=i.items.find(m=>m.step.id===n);!l||l.done||(oe(H(i.flow.id),n),e.track(re,{flow:i.flow.id,step:n,kind:"checklist",action:"completed"}),V(),M());},dismiss:()=>{let n=ie();!n||n.type!=="step"&&n.type!=="checklist"||(H(n.flow.id).dismissed=true,e.track(re,{flow:n.flow.id,...n.type==="step"?{step:n.step.id}:{},action:"dismissed"}),s=null,V(),M());}},message:{click:()=>{var l;let n=ae();if((n==null?void 0:n.type)!=="message")return;E.add(n.message.id),e.track(tt,{message:n.message.id,journey:n.message.journey,action:"clicked"});let i=In(n.message.url);M(),i&&((l=e.openUrl)==null||l.call(e,i));},dismiss:()=>{let n=ae();(n==null?void 0:n.type)==="message"&&(E.add(n.message.id),e.track(tt,{message:n.message.id,journey:n.message.journey,action:"dismissed"}),M());}}}};var Pn="ck_pick",$n="ck_origin",Ne=e=>typeof CSS!="undefined"&&CSS.escape?CSS.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,t=>`\\${t}`),Mn=e=>[...e.classList].filter(t=>t.length<30&&!/\d{2,}|[_-][a-z0-9]{5,}$|^(is|has)-|hover|active|focus|open|selected|:|\[/.test(t)).slice(0,2),jt=e=>{let t=e.ownerDocument,r=f=>{try{return t.querySelectorAll(f).length===1}catch(C){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(`#${Ne(e.id)}`))return `#${Ne(e.id)}`;let c=[],a=e;for(;a&&a!==t.documentElement&&c.length<6;){if(a!==e&&a.id&&!/\d{3,}/.test(a.id)){c.unshift(`#${Ne(a.id)}`);break}let f=a.tagName.toLowerCase(),C=Mn(a).map(h=>`.${Ne(h)}`).join(""),v=a.parentElement,k=v?[...v.children].filter(h=>h.tagName===a.tagName):[],E=k.length>1?`:nth-of-type(${k.indexOf(a)+1})`:"";c.unshift(`${f}${C}${E}`);let g=c.join(" > ");if(r(g))return g;a=v;}return c.join(" > ")},Ht=()=>{var E;if(typeof window=="undefined"||window.top===window)return null;let e=new URLSearchParams(window.location.search);if(e.get(Pn)!=="1")return null;let t;try{t=new URL((E=e.get($n))!=null?E:"").origin;}catch(g){return null}if(!/^https?:\/\//.test(t))return null;let r=g=>window.parent.postMessage(g,t),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 a=null,f=g=>{if(a=g&&g!==s&&!s.contains(g)?g:null,!a){s.style.display="none";return}let h=a.getBoundingClientRect();Object.assign(s.style,{display:"block",left:`${h.left-2}px`,top:`${h.top-2}px`,width:`${h.width+4}px`,height:`${h.height+4}px`}),c.textContent=jt(a);},C=g=>f(document.elementFromPoint(g.clientX,g.clientY)),v=g=>{var S,$;g.preventDefault(),g.stopPropagation();let h=(S=document.elementFromPoint(g.clientX,g.clientY))!=null?S:a;!h||h===s||r({type:"mrrocket:picked",selector:jt(h),text:(($=h.textContent)!=null?$:"").trim().replace(/\s+/g," ").slice(0,80)});},k=g=>{g.key==="Escape"&&r({type:"mrrocket:pick-cancel"});};return window.addEventListener("mousemove",C,true),window.addEventListener("click",v,true),window.addEventListener("keydown",k,true),r({type:"mrrocket:pick-ready"}),()=>{window.removeEventListener("mousemove",C,true),window.removeEventListener("click",v,true),window.removeEventListener("keydown",k,true),s.remove();}};var An={get:e=>{try{return window.localStorage.getItem(e)}catch(t){return null}},set:(e,t)=>{try{window.localStorage.setItem(e,t);}catch(r){}}},Kt=()=>{try{for(let e=window.localStorage.length-1;e>=0;e--){let t=window.localStorage.key(e);t!=null&&t.startsWith("mrrocket:onboarding")&&window.localStorage.removeItem(t);}}catch(e){}},Wt=e=>({track:e.track,personId:e.personId,auto:e.auto,storage:()=>e.canStore()?An:null,openUrl:t=>window.location.assign(t),path:()=>window.location.pathname,fetchInApp:async t=>{if(!e.apiKey)return null;let r=await fetch(`${e.host}/api/sdk/inapp?key=${encodeURIComponent(e.apiKey)}&distinctId=${encodeURIComponent(t)}`);return r.ok?await r.json():null}});var De="mrr_ref",Ue="mrr_ref",Nn="mrr_ref",Ln="mrr_click";var _e=/^[A-Za-z0-9_-]{1,64}$/;var Tn=(e,t="ref")=>{let r=new URLSearchParams(e);return Dn(s=>r.get(s),t)},Dn=(e,t="ref")=>{let r=e(Nn);if(r&&_e.test(r)){let c=e(Ln);return {code:r,clickId:c&&_e.test(c)?c:null,direct:false}}let s=e(t);return s&&_e.test(s)?{code:s,clickId:null,direct:true}:null},Vt=e=>{var t;return `${e.code}.${(t=e.clickId)!=null?t:""}.${e.at}`},Le=(e,t=60,r=Date.now())=>{if(!e)return null;let[s,c,a]=e.split("."),f=Number(a);return !s||!_e.test(s)||!Number.isFinite(f)||c&&!_e.test(c)||r-f>t*864e5||f>r+864e5?null:{code:s,clickId:c||null,at:f}};var T=null,je=()=>typeof document!="undefined",Bt=e=>{var r;if(!je())return;let t=(r=document.cookie.split("; ").find(s=>s.startsWith(`${e}=`)))==null?void 0:r.slice(e.length+1);try{return t?decodeURIComponent(t):void 0}catch(s){return t}},He=()=>{try{return typeof localStorage=="undefined"?null:localStorage}catch(e){return null}},ot=()=>{var e,t;return T||(je()?(t=Le(Bt(De),3650))!=null?t:Le((e=He())==null?void 0:e.getItem(Ue),3650):null)};var Te=(e,t)=>{var c;if(!je())return;let r=Math.max(1,Math.round(t))*86400,s=typeof location!="undefined"&&location.protocol==="https:"?"; secure":"";document.cookie=`${De}=${encodeURIComponent(Vt(e))}; path=/; max-age=${r}; samesite=lax${s}`;try{(c=He())==null||c.setItem(Ue,Vt(e));}catch(a){}},Ke=()=>{var e;if(je()){document.cookie=`${De}=; path=/; max-age=0; samesite=lax`;try{(e=He())==null||e.removeItem(Ue);}catch(t){}}},qt=()=>{T=null;},Yt=async e=>{var s,c,a;let t=Tn(e.search,e.param),r=(s=e.now)!=null?s:Date.now();if(!t)return !T&&e.store&&(T=(a=Le(Bt(De),e.days,r))!=null?a:Le((c=He())==null?void 0:c.getItem(Ue),e.days,r),T||Ke()),T;if(T={code:t.code,clickId:t.clickId,at:r},e.store&&Te(T,e.days),e.beacon)try{let f=await e.beacon({code:t.code,clickId:t.clickId});f&&T&&T.code===t.code&&!T.clickId&&(T={...T,clickId:f},e.store&&Te(T,e.days));}catch(f){}return T},Xt=e=>e==="$identify"||!e.startsWith("$");var st=3600*24*365,Gt=e=>{var r;if(typeof document=="undefined")return;let t=(r=document.cookie.split("; ").find(s=>s.startsWith(`${e}=`)))==null?void 0:r.slice(e.length+1);if(t)try{return decodeURIComponent(t)}catch(s){return t}},We=(e,t,r)=>{let s=window.location.protocol==="https:"?"; secure":"";document.cookie=`${e}=${encodeURIComponent(t)}; path=/; max-age=${r}; samesite=lax${s}`;},Se=e=>{document.cookie=`${e}=; path=/; max-age=0; samesite=lax`;},A={utm:{}},Jt=()=>{var e;return (e=A.id)!=null?e:A.id=et()},it=(e,t)=>{if(e!=="cookies")return Jt();let r=Gt(ce);if(r)return A.id=r;let s=Jt();return We(ce,s,st),s},at=e=>{var c;let t=Date.now(),r=A.session,s=(c=e?Gt(he):void 0)!=null?c:r&&t-r.last<18e5?r.id:et();return A.session={id:s,last:t},e&&We(he,s,18e5/1e3),s},ct=()=>{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 t=Pt(window.location.search);Object.keys(t).length&&(A.utm=t);},Qt=()=>{let e=navigator,t=window;return e.doNotTrack==="1"||t.doNotTrack==="1"||e.globalPrivacyControl===true};var Ve=window,jn=()=>{var e,t;return (t=(e=document.currentScript)!=null?e:document.querySelector('script[data-key][src*="sdk"]'))!=null?t:document.querySelector("script[data-key][src*='mrrocket']")},Zt=new Set,X=e=>{Zt.has(e)||(Zt.add(e),console.warn(`[MRRocket] ${e}`));},Hn=()=>{var kt,yt,bt,xt;let e=jn(),t=o=>{var d;return (d=e==null?void 0:e.getAttribute(`data-${o}`))!=null?d:void 0},r=(o,d)=>{let u=t(o);return u===void 0?d:!["false","0","off","no"].includes(u.trim().toLowerCase())},s=(kt=e==null?void 0:e.src)!=null?kt:"",c="";try{c=s?new URL(s,window.location.href).origin:"";}catch(o){c="";}let a=((yt=t("key"))!=null?yt:"").trim(),f=((bt=t("api-host"))!=null?bt:c).trim().replace(/\/+$/,""),C=t("consent"),v=r("respect-dnt",false),k=r("heatmaps",true),E=r("errors",true),g=t("release"),h=t("attribution"),S=h==="always"||h==="off"?h:"consent",$=t("referral-param")||"ref",L={},N=(o,d)=>{var u;return (u=L[o])!=null?u:L[o]=new Promise((w,R)=>{var Ct;let F=()=>Ve[d];if(F())return w(F());let q=(Ct=t(`${o}-src`))!=null?Ct:s?s.replace(/(\.min)?\.js(\?[^#]*)?(#.*)?$/,`-${o}$1.js?v=${Me}`):"";if(!q)return R(new Error(o));let ne=document.createElement("script");ne.async=true,ne.src=q,ne.onload=()=>F()?w(F()):R(new Error(o)),ne.onerror=()=>R(new Error(o)),document.head.appendChild(ne);}).catch(w=>{throw L[o]=void 0,w})},z=t("theme"),G={theme:z==="light"||z==="dark"?z:"auto",accent:t("accent")},H=new URLSearchParams(window.location.search),Q=$t(H.get(Ot)),W=H.get(Ft)==="1";W&&Ht();let oe=H.get(Ce);if(oe!==null){H.delete(Ce);let o=H.toString();history.replaceState(history.state,"",`${window.location.pathname}${o?`?${o}`:""}${window.location.hash}`);}let Be=Qt(),de=C==="cookies"||C==="off"?C:"cookieless",se=r("replay",false),ue="",j,V,P=null,Z=false,fe=false,ie=null,ae=null,M=window.location.pathname,J=[],ke=new Set,Ie=[],D=()=>v&&Be?"off":de,U=()=>!W&&D()!=="off",K=()=>j!=null?j:ue,pe=()=>D()==="cookies"?K():j;a||X('No public key. Add data-key="mrr_pub_\u2026" to the script tag; nothing is tracked until then.');let Oe=(o=false)=>{if(!J.length)return;if(!a){J.length=0;return}let d=`${f}/api/sdk/events`;for(let u of vt(a,J.splice(0),{v:Me,errors:E,platform:"web"}))o&&"sendBeacon"in navigator&&navigator.sendBeacon(d,u)||fetch(d,{method:"POST",headers:{"content-type":"application/json"},body:u,keepalive:true}).then(R=>{R.ok||X(`Events were rejected with ${R.status}. Check data-key (MRRocket \u203A Settings \u203A Products).`);}).catch(()=>X(`Could not reach ${f||"this origin"} to send events. Check data-api-host.`));},n=null,i=null,l=(o,d,u=Date.now(),w)=>{if(!U())return;let R=Xt(o)?ot():null;J.push({event:o,props:R?{...d,$referral:{code:R.code,clickId:R.clickId}}:d,distinctId:pe(),sessionId:at(D()==="cookies"),ts:u,url:w!=null?w:window.location.href,referrer:A.referrer,...A.utm,screen:{w:window.screen.width,h:window.screen.height}});},m=(o,d)=>{typeof o!="string"||!o||(l(o,d),U()&&(n==null||n.event(o)),p.onEvent(o));},p=Ut(Wt({host:f,apiKey:a,track:l,personId:()=>U()?j:void 0,canStore:()=>D()==="cookies",auto:r("onboarding",true)})),_=false,I;p.subscribe(()=>{_||!p.view()||W||(_=true,N("flows","__mrrocketFlows").then(o=>o.mountFlows(p,G)).catch(()=>{_=false,X("The cancel flow and onboarding dialogs did not load. Check that sdk-flows.js is served next to sdk.js.");}));});let b=(o,d)=>{if(!U())return;let u=`${window.location.pathname}|${o}`;ke.has(u)||(ke.add(u),m("$exposure",{experiment:o,variant:d}));},y=()=>{let o=At(P,window.location.href,K(),Q);return o!=null&&o.to?(Oe(true),window.location.replace(o.to),true):(o!=null&&o.experiment&&b(o.experiment,o.variant),false)},x=()=>{if(!P)return;let o=document.querySelectorAll("[data-ck-text]");if(!o.length)return;let d=Mt(P,K(),Q),u=new Set;o.forEach(w=>{var q,ne;let R=w.dataset.ckText;if(!R)return;u.add(R),w.dataset.ckDefault===void 0&&(w.dataset.ckDefault=(q=w.textContent)!=null?q:"");let F=(ne=d[R])!=null?ne:w.dataset.ckDefault;w.textContent!==F&&(w.textContent=F);});for(let w of P.experiments)w.variants.some(R=>{var F;return Object.keys((F=R.changes)!=null?F:{}).some(q=>u.has(q))})&&b(w.key,Re(w.key,P,K(),Q));},O=()=>{var o,d;return (d=(o=P==null?void 0:P.referral)==null?void 0:o.cookieDays)!=null?d:60},B=()=>S==="always"?D()!=="off":S==="consent"&&D()==="cookies",ye=null,Y=false,qe=()=>{if(!Z||W)return;if(S==="off"||D()==="off"){qt(),(S==="off"||Y)&&Ke();return}let o=window.location.href;ye!==o&&(ye=o,Yt({search:window.location.search,param:$,store:B(),days:O(),beacon:a?({code:d,clickId:u})=>fetch(`${f}/api/sdk/affiliate/click`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({key:a,code:d,clickId:u,url:o,referrer:document.referrer||void 0}),keepalive:true}).then(w=>w.ok?w.json():null).then(w=>{var R;return (R=w==null?void 0:w.clickId)!=null?R:null}):void 0}));},tn=()=>{let o=B(),d=ot();o&&d?Te(d,O()):!o&&Y&&Ke(),Y=o;},lt=0,dt=false,ut=()=>{var w,R;let o=U()&&se&&!!(P!=null&&P.replay)&&!!a;if(o===dt)return;dt=o;let d=++lt;if(!o){n==null||n.stop(true),n=null;return}let u=(R=(w=P==null?void 0:P.replay)==null?void 0:w.sampleRate)!=null?R:.1;N("replay","__mrrocketReplay").then(F=>F.startReplay({host:f,apiKey:a,sessionId:at(D()==="cookies"),distinctId:pe(),identified:!!j,sampleRate:u,warn:X})).then(F=>{d!==lt?F==null||F.stop(true):n=F;}).catch(()=>X("Session recording could not start (the recorder did not load)."));},ft=r("messenger",false),ee=null,ge=o=>{W||a&&(ee!=null||(ee=N("messenger","__mrrocketMessenger").then(d=>{var F;let u=q=>t(`messenger-${q}`)===void 0?void 0:r(`messenger-${q}`,true),w=t("messenger-position"),R=(F=t("messenger-theme"))!=null?F:z;return d.mountMessenger({host:f,apiKey:a,distinctId:K,user:()=>V,launcher:ft,position:w==="bottom-left"||w==="bottom-right"?w:void 0,title:t("messenger-title"),greeting:t("messenger-greeting"),label:t("messenger-label"),askEmail:u("ask-email"),help:u("help"),sound:u("sound"),preview:u("preview"),theme:R==="light"||R==="dark"||R==="auto"?R:void 0,accent:t("accent")})})),ee.then(o).catch(()=>{ee=null,X("sdk-messenger.js did not load.");}));},pt=t("forms")==="auto",Ye=false,Xe=()=>{Ye||!a||W||!document.querySelector(pt?"form":"form[data-mrrocket-form]")||(Ye=true,N("forms","__mrrocketForms").then(o=>o.watchForms({host:f,apiKey:a,auto:pt,distinctId:()=>U()?pe():void 0,identified:()=>!!j,identify:ht,tracking:U,referrer:()=>A.referrer,utm:()=>A.utm})).catch(()=>Ye=false));},ze=()=>{!fe||!U()||ae===window.location.pathname||(ae=window.location.pathname,m("$pageview",{path:window.location.pathname}));},te=null,gt=()=>{let o=te;k&&o&&o.max>0&&l("$scroll",{depth:o.max,docH:o.docH,vw:window.innerWidth,vh:window.innerHeight},Date.now(),o.url),te=null;},be=()=>{var R,F;if(!k||!U()||W)return;let o=document.documentElement,d=Math.max(o.scrollHeight,(F=(R=document.body)==null?void 0:R.scrollHeight)!=null?F:0),u=St(),w=window.location.href;(te==null?void 0:te.url)!==w?te={url:w,max:u,docH:d}:u>te.max&&(te={url:w,max:u,docH:d});},mt=()=>{let o=window.location.pathname;o!==M&&(M=o,!(Z&&y())&&(gt(),ct(),n==null||n.page(o),i==null||i.crumb("navigation",o),ze(),qe(),window.setTimeout(()=>{be(),x(),Xe();},0)));},wt=()=>{let o=D(),d=ie;ie=o,d==="cookies"&&o!=="cookies"&&(Se(ce),Se(he)),o==="off"&&(J.length=0,A.session=void 0),d==="cookies"&&o!=="cookies"&&Kt(),ue=it(o),tn(),qe(),ut(),ze(),be();},nn=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"){X(`setConsent: "${String(d)}" is not a consent mode. Use "cookieless", "cookies" or "off".`);return}d==="off"&&(J.length=0),d&&(de=d),typeof u=="boolean"&&(se=u),wt(),Z&&p.refresh();},ht=(o,d)=>{if(typeof o!="string"||!o)return;let u=pe();j=o,l("$identify",{...d,id:o,...u&&u!==o?{previousId:u}:{}}),n==null||n.identify(o),D()==="cookies"&&We(ce,o,st),V={...d,id:o},x(),Z&&p.refresh();},Fe={track:m,identify:ht,reset:()=>{j=void 0,V=void 0,ke.clear(),D()==="cookies"&&(Se(ce),Se(he)),A.id=void 0,A.session=void 0,ue=it(D()),x(),Z&&p.refresh();},captureError:o=>i==null?void 0:i.capture(o,"manual"),setConsent:nn,getFlag:o=>Ze(o,P,K(),{...V})!==false,getFlagVariant:o=>{let d=Ze(o,P,K(),{...V});return typeof d=="string"?d:null},getVariant:o=>{let d=Re(o,P,K(),Q);return (P||Q[o])&&b(o,d),d},ready:o=>{typeof o=="function"&&(Z?window.setTimeout(()=>o(Fe),0):Ie.push(o));},getDistinctId:K,cancelFlow:{open:o=>p.openCancelFlow(o)},onboarding:{start:o=>p.startOnboarding(o)},openCancelFlow:o=>p.openCancelFlow(o),startOnboarding:o=>p.startOnboarding(o),paywall:{open:(o,d)=>(I!=null?I:I=N("flows","__mrrocketFlows").then(u=>u.paywallHost({config:()=>P,distinctId:K,track:l},G))).then(u=>u.open(o,d))},push:{subscribe:o=>{let d=U()?j:void 0;if(!d)return Promise.resolve({status:"not-signed-in"});let u=window.Notification,w=Promise.resolve(u&&u.permission==="default"&&(o==null?void 0:o.ask)!==false?u.requestPermission():u==null?void 0:u.permission);return N("push","__mrrocketPush").then(R=>R.subscribeWebPush({host:f,apiKey:a,distinctId:d,permission:w},o))},unsubscribe:()=>N("push","__mrrocketPush").then(o=>o.unsubscribeWebPush({host:f,apiKey:a,distinctId:j}))},messenger:{open:o=>ge(d=>d.open(o)),close:()=>{ee==null?void 0:ee.then(o=>o.close()).catch(()=>{});},toggle:()=>ge(o=>o.toggle())},openMessenger:()=>ge(o=>o.open()),version:Me};ct(),wt();let me=Ve.mrrocket,rn=(xt=me==null?void 0:me.q)!=null?xt:[],Je=me&&typeof me=="object"?me:{};Object.assign(Je,Fe,{__loaded:true}),delete Je.q,Ve.mrrocket=Je;for(let[o,d]of rn){let u=Fe[o];if(typeof u=="function")try{u(...Array.from(d!=null?d:[]));}catch(w){console.error(w);}}fe=true,ze(),E&&a&&!W&&(i=Lt({host:f,apiKey:a,release:g,context:()=>{var o;return {send:U(),distinctId:pe(),sessionId:(o=A.session)==null?void 0:o.id}},warn:X}),i.crumb("navigation",window.location.pathname));for(let o of ["pushState","replaceState"]){let d=history[o];history[o]=function(...u){let w=d.apply(this,u);return mt(),w};}window.addEventListener("popstate",mt);let on=new xe;document.addEventListener("click",o=>{var F;o.target instanceof Element&&o.target.closest("[data-ck-messenger]")&&(o.preventDefault(),ge(q=>q.open()));let d=o.target instanceof Element?o.target.closest("[data-ck-goal]"):null;if(d!=null&&d.dataset.ckGoal&&m(d.dataset.ckGoal,{text:(F=d.textContent)==null?void 0:F.trim().slice(0,80)}),!U())return;let u=_t(o);if(!u)return;let w=on.push(u.x,u.y,Date.now());if((u.label||u.selector)&&(i==null||i.crumb("click",u.label||u.selector)),n==null||n.click(u,w),!k)return;let R={x:u.x,y:u.y,vw:u.vw,vh:u.vh,docH:u.docH,selector:u.selector,label:u.label,dead:!u.interactive};l("$click",R),w&&l("$rageclick",R);});let Ge=0;window.addEventListener("scroll",()=>{Ge||(Ge=window.requestAnimationFrame(()=>{Ge=0,be();}));},{passive:true}),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>be()):be(),window.setInterval(()=>Oe(),2e3),window.addEventListener("pagehide",()=>{gt(),Oe(true);});let Qe=()=>{if(Z=true,y())return;let o=Nt(P,oe);o&&b(o.experiment,o.variant),document.documentElement.classList.remove("ck-hide"),qe(),ut(),p.setConfig(P),p.refresh(),ft&&(document.body?ge():document.addEventListener("DOMContentLoaded",()=>ge())),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{x(),Xe();}):(x(),Xe());for(let d of Ie.splice(0))try{d(Fe);}catch(u){console.error(u);}};a?fetch(`${f}/api/sdk/config?key=${encodeURIComponent(a)}`).then(o=>(o.ok||X(`Config request to ${f||"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),Qe();}).catch(()=>{X(`Could not reach ${f||"this origin"}. Check data-api-host. The page keeps its own texts and flags stay off.`),Qe();}):Qe();},en;typeof window!="undefined"&&typeof document!="undefined"&&!((en=Ve.mrrocket)!=null&&en.__loaded)&&Hn();
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();
2
2
  })();
package/dist/core.d.ts CHANGED
@@ -6,7 +6,7 @@ import type { CancelFlowConfig, OnboardingFlow } from "./flows.js";
6
6
  import type { PaywallConfig } from "./paywall.js";
7
7
  export type VariantId = string;
8
8
  /** This build of the SDK. Sent with the config request so MRRocket knows what the site runs (error tracking, flags). */
9
- export declare const SDK_VERSION = "0.14.0";
9
+ export declare const SDK_VERSION = "0.15.0";
10
10
  /** One variant of an experiment. `changes` replaces texts that the page marks with `<Text id>`. */
11
11
  export interface VariantConfig {
12
12
  id: VariantId;
package/dist/core.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/core.ts
2
- var SDK_VERSION = "0.14.0";
2
+ var SDK_VERSION = "0.15.0";
3
3
  var propOf = (person, name) => {
4
4
  const want = name.trim().toLowerCase();
5
5
  for (const [k, v] of Object.entries(person)) if (k.toLowerCase() === want) return v;
package/dist/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core.ts"],"sourcesContent":["/**\n * The part of the SDK that runs anywhere: experiment config, variant assignment, preview links and event shapes.\n * No React, no browser APIs, so the server helper, the proxy helper and the client share it.\n */\nimport type { CancelFlowConfig, OnboardingFlow } from \"./flows\";\nimport type { PaywallConfig } from \"./paywall\";\n\nexport type VariantId = string;\n\n/** This build of the SDK. Sent with the config request so MRRocket knows what the site runs (error tracking, flags). */\nexport const SDK_VERSION = \"0.14.0\";\n\n/** One variant of an experiment. `changes` replaces texts that the page marks with `<Text id>`. */\nexport interface VariantConfig {\n id: VariantId;\n /** Share of traffic, 0 to 1. The weights of an experiment add up to 1. */\n weight: number;\n changes?: Record<string, string>;\n /**\n * A redirect test: where this variant sends the visitor instead of the test's page (a path like \"/pricing-b\" or a\n * full address). Control has none and stays. SDK 0.7.0+.\n */\n url?: string;\n}\n\nexport interface ExperimentConfig {\n /** The experiment's key, the same as in Cockpit. */\n key: string;\n status: \"running\" | \"draft\" | \"stopped\";\n /** Control first. */\n variants: VariantConfig[];\n /** A winner that shipped: everyone gets it, and nobody is assigned anymore. */\n winner?: VariantId;\n /** A redirect test: the path of the page it runs on (\"/pricing\"). Visitors there are sent to their variant's `url`. */\n path?: string;\n}\n\n/** A page redirect set in MRRocket (Conversion › Landing pages › Redirect): everyone on `from` goes to `to`. SDK 0.7.0+. */\nexport interface RedirectConfig {\n /** A path of the site, like \"/old-pricing\". */\n from: string;\n /** A path or a full address. */\n to: string;\n}\n\nexport interface CockpitConfig {\n /** The product the public key belongs to. */\n project: string;\n experiments: ExperimentConfig[];\n /** The product's affiliate program: how many days a partner's referral is kept. Missing without a program. */\n referral?: { cookieDays: number };\n /** Session recordings: present only while the product records (Cockpit › Sessions). See `ReplayConfig`. */\n replay?: ReplayConfig;\n /** Feature flags of the product in Production (MRRocket › Build › Feature flags), evaluated by `useFlag` and `getFlag`. */\n flags?: FlagConfig[];\n /**\n * Published copy for texts the site marks (`<Text id>`, `data-ck-text`): a landing page's headline, subheadline and\n * button (`pricing.headline` …) and a paywall's (`paywall.<placement>.headline` …) as published in MRRocket. A\n * running test's variant changes them on top. Missing when nothing is published. SDK 0.5.0+.\n */\n texts?: Record<string, string>;\n /** The product's live cancel flow (MRRocket › Churn › Cancel flow), for `cancelFlow.open()`. SDK 0.7.0+. */\n cancelFlow?: CancelFlowConfig;\n /** The in-app steps of live onboarding flows (tours, checklists, modals). SDK 0.7.0+. */\n onboarding?: OnboardingFlow[];\n /** A live Lifecycle journey has in-app messages: signed-in people ask `/api/sdk/inapp` for theirs. SDK 0.7.0+. */\n messages?: boolean;\n /** Page redirects set in MRRocket; the SDK sends visitors on before the page shows (`redirectFor`). SDK 0.7.0+. */\n redirects?: RedirectConfig[];\n /** Published paywalls with their pages, per placement (MRRocket › Conversion › Paywalls), for `paywall.open()`. SDK 0.14.0+. */\n paywalls?: PaywallConfig[];\n}\n\n/** One condition of a flag's audience, on a property of the person (`identify(id, props)`), the id or the page. */\nexport interface FlagCondition {\n /** \"Email\", \"Plan\", \"Country\", \"id\", \"path\" … Matched against the person's properties without regard to case. */\n property: string;\n op: \"is\" | \"is not\" | \"in\" | \"not in\" | \"≥\" | \"in cohort\";\n values: string[];\n}\n\n/** Users who match every condition, of whom `rollout` percent get the flag. No conditions: everyone. */\nexport interface FlagConditionSet {\n conditions: FlagCondition[];\n /** 0 to 100. */\n rollout: number;\n}\n\nexport interface FlagConfig {\n key: string;\n /** Off: everyone gets the off side. */\n on: boolean;\n /** The first set a person matches decides; none matched: off. */\n sets: FlagConditionSet[];\n /** Multivariate flags: the variants and their split in percent (control included). Missing for an on/off flag. */\n variants?: { key: string; split: number; payload?: string }[];\n}\n\n/** What a person is for flag conditions: their properties from identify(), their id and the page they are on. */\nexport type FlagPerson = Record<string, unknown>;\n\nconst propOf = (person: FlagPerson, name: string) => {\n const want = name.trim().toLowerCase();\n for (const [k, v] of Object.entries(person)) if (k.toLowerCase() === want) return v;\n return undefined;\n};\n\n/** `\"@acme.com\"` matches every address at that domain; anything else matches the whole value, without regard to case. */\nconst same = (actual: string, value: string) => {\n const a = actual.trim().toLowerCase();\n const v = value.trim().toLowerCase();\n return v.startsWith(\"@\") ? a.endsWith(v) : a === v;\n};\n\nconst matchesCondition = (c: FlagCondition, person: FlagPerson) => {\n // Cohorts live in MRRocket; a browser cannot know them, so a cohort condition never matches here.\n if (c.op === \"in cohort\") return false;\n const raw = propOf(person, c.property);\n const actual = raw === undefined || raw === null ? \"\" : String(raw);\n if (c.op === \"≥\") {\n const a = Number(actual);\n const b = Number(c.values[0]);\n return actual !== \"\" && Number.isFinite(a) && Number.isFinite(b) && a >= b;\n }\n const hit = actual !== \"\" && c.values.some((v) => same(actual, v));\n return c.op === \"is\" || c.op === \"in\" ? hit : !hit;\n};\n\n/**\n * The flag for one person: `false` (off), `true` (on, an on/off flag) or the variant's key (a multivariate flag). The\n * bucket is a stable hash of flag and person, so a person keeps their side as the rollout grows.\n */\nexport const evaluateFlag = (flag: FlagConfig, distinctId: string, person: FlagPerson = {}): boolean | string => {\n if (!flag.on) return false;\n const subject = { id: distinctId, ...person };\n const set = flag.sets.length ? flag.sets.find((s) => s.conditions.every((c) => matchesCondition(c, subject))) : { conditions: [], rollout: 100 };\n if (!set) return false;\n if (flagUnit(`${flag.key}:rollout:${distinctId}`) * 100 >= set.rollout) return false;\n if (!flag.variants?.length) return true;\n const u = flagUnit(`${flag.key}:variant:${distinctId}`) * 100;\n let acc = 0;\n for (const v of flag.variants) {\n acc += v.split;\n if (u < acc) return v.key;\n }\n return flag.variants[flag.variants.length - 1].key;\n};\n\n/** A flag of the config for this person; an unknown flag (or no config) is off. */\nexport const flagFor = (key: string, config: CockpitConfig | null, distinctId: string, person: FlagPerson = {}) => {\n const flag = config?.flags?.find((f) => f.key === key);\n return flag ? evaluateFlag(flag, distinctId, person) : false;\n};\n\n/** One JavaScript error as it goes over the wire to `POST /api/sdk/errors`. */\nexport interface ErrorReport {\n /** \"TypeError\", \"Error\" … */\n type: string;\n message: string;\n /** The raw stack, at most 8 KB. MRRocket parses it into frames. */\n stack?: string;\n /** \"onerror\" (uncaught), \"onunhandledrejection\" (a rejected promise nobody caught) or \"manual\" (captureError). */\n mechanism: \"onerror\" | \"onunhandledrejection\" | \"manual\";\n handled: boolean;\n url: string;\n ts: number;\n /** What happened just before: pages and clicks, newest last, at most 20. */\n crumbs?: { ts: number; type: \"navigation\" | \"click\" | \"lifecycle\"; message: string }[];\n /** Your release (a version or commit), from the provider's `release` prop. */\n release?: string;\n distinctId?: string;\n sessionId?: string;\n}\n\n/**\n * Session recordings of a product, from the config. Recording also needs the visitor's own replay consent\n * (`<CockpitProvider replay>` or `setConsent({ replay: true })`); without it nothing is recorded or buffered.\n */\nexport interface ReplayConfig {\n /**\n * Share of sessions uploaded from their start, 0 to 1 (default 0.1). The others keep only the last minute in\n * memory and upload it when something goes wrong: a JS error, a rage click, a `purchase…` or `checkout…` event.\n */\n sampleRate: number;\n}\n\n/**\n * What the SDK may send and store.\n * - \"cookieless\" (default): no cookie, no localStorage. Events go without a visitor id; the server counts visitors\n * with a hash of key, date, IP and user agent that changes every day.\n * - \"cookies\": a persistent `ck_id` cookie identifies the visitor across visits, `ck_sid` holds the session.\n * - \"off\": nothing is sent and nothing is stored.\n */\nexport type ConsentMode = \"cookieless\" | \"cookies\" | \"off\";\n\n/**\n * What `setConsent` takes: a mode as before, or the parts to change. `replay` is the separate consent for session\n * recordings (default false); it applies only while analytics is not \"off\".\n *\n * setConsent(\"cookies\");\n * setConsent({ replay: true });\n * setConsent({ analytics: \"cookieless\", replay: false });\n */\nexport type ConsentChoice = ConsentMode | { analytics?: ConsentMode; replay?: boolean };\n\n/** The campaign parameters the SDK reads from the landing URL. */\nexport const UTM_KEYS = [\"utm_source\", \"utm_medium\", \"utm_campaign\", \"utm_term\", \"utm_content\"] as const;\nexport type UtmKey = (typeof UTM_KEYS)[number];\n\n/** One event as it goes over the wire to `POST /api/sdk/events`. */\nexport interface CockpitEvent {\n event: string;\n /** The visitor. Missing in \"cookieless\" mode until identify(): the server then uses its daily visitor hash. */\n distinctId?: string;\n /** Ends after 30 minutes without an event. */\n sessionId?: string;\n props?: Record<string, unknown>;\n /** Milliseconds since the epoch. */\n ts: number;\n url?: string;\n /** `document.referrer` on the first page of a page load, the previous in-app URL after client-side navigation. */\n referrer?: string;\n utm_source?: string;\n utm_medium?: string;\n utm_campaign?: string;\n utm_term?: string;\n utm_content?: string;\n /** The screen size in CSS pixels (points on a phone). */\n screen?: { w: number; h: number };\n /** The app that sent it (React Native only): MRRocket stores it with the event and fills OS and device from it. */\n app?: AppContext;\n}\n\n/** Where a React Native event comes from. Every field is optional except the platform; nothing identifies the person. */\nexport interface AppContext {\n /** \"ios\" or \"android\" (React Native's `Platform.OS`). */\n platform: string;\n /** The app's version, like \"1.4.0\" (`expo-application`'s `nativeApplicationVersion`). */\n appVersion?: string;\n /** The build number, like \"42\". */\n build?: string;\n /** The OS version, like \"17.4\". */\n osVersion?: string;\n /** The device model, like \"iPhone 15 Pro\" (`expo-device`). */\n deviceModel?: string;\n /** \"phone\", \"tablet\", \"desktop\" or \"tv\" when `expo-device` knows it. */\n deviceType?: string;\n /** The first preferred locale, like \"de-DE\". */\n locale?: string;\n}\n\n/** The query parameter that forces variants, for previews in Cockpit: `?ck_preview=pricing-annual:a,home-hero:control`. */\nexport const PREVIEW_PARAM = \"ck_preview\";\n/** Set when Cockpit embeds the page: nothing is tracked, so previews never count as visits. */\nexport const EMBED_PARAM = \"ck_embed\";\n/** The cookie that keeps a visitor in the same variant across visits. Only written in \"cookies\" mode. */\nexport const ID_COOKIE = \"ck_id\";\n/** The cookie that holds the session id in \"cookies\" mode. */\nexport const SESSION_COOKIE = \"ck_sid\";\n/** A session ends after this long without an event. */\nexport const SESSION_TIMEOUT_MS = 30 * 60 * 1000;\n\n/** The UTM parameters from a parameter lookup (`URLSearchParams.get` in a browser). Empty values are left out. */\nexport const utmFrom = (get: (name: string) => string | null | undefined): Partial<Record<UtmKey, string>> => {\n const out: Partial<Record<UtmKey, string>> = {};\n for (const key of UTM_KEYS) {\n const value = get(key)?.trim();\n if (value) out[key] = value.slice(0, 150);\n }\n return out;\n};\n\n/** The UTM parameters of a query string, like `\"?utm_source=x\"`. Empty values are left out. */\nexport const readUtm = (search: string): Partial<Record<UtmKey, string>> => {\n const params = new URLSearchParams(search);\n return utmFrom((k) => params.get(k));\n};\n\n/**\n * The query parameters of a URL or query string, without `URLSearchParams` (React Native's is incomplete): `+` is a\n * space, values are percent-decoded, the first of a repeated name wins.\n */\nexport const parseQuery = (url: string): Record<string, string> => {\n const out: Record<string, string> = {};\n const q = url.split(\"#\")[0];\n const at = q.indexOf(\"?\");\n if (at < 0) return out;\n const dec = (s: string) => {\n try {\n return decodeURIComponent(s.replace(/\\+/g, \" \"));\n } catch {\n return s;\n }\n };\n for (const pair of q.slice(at + 1).split(\"&\")) {\n if (!pair) continue;\n const eq = pair.indexOf(\"=\");\n const k = dec(eq < 0 ? pair : pair.slice(0, eq));\n if (k && !(k in out)) out[k] = eq < 0 ? \"\" : dec(pair.slice(eq + 1));\n }\n return out;\n};\n\n/** FNV-1a, 32 bit, mapped to [0, 1). Stable across server and browser. */\nexport const hashUnit = (input: string) => {\n let h = 0x811c9dc5;\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n return (h >>> 0) / 4294967296;\n};\n\n/**\n * FNV-1a with murmur3's finalizer, mapped to [0, 1): ids that differ only at the end (\"user-1\", \"user-2\") still spread\n * evenly, so a 30 % rollout reaches about 30 % of people. Flags only; experiments keep `hashUnit` so nobody switches.\n */\nexport const flagUnit = (input: string) => {\n let h = 0x811c9dc5;\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n h ^= h >>> 16;\n h = Math.imul(h, 0x85ebca6b);\n h ^= h >>> 13;\n h = Math.imul(h, 0xc2b2ae35);\n h ^= h >>> 16;\n return (h >>> 0) / 4294967296;\n};\n\n/** The variant a visitor sees: a shipped winner, control while the experiment does not run, else a stable bucket by visitor. */\nexport const assign = (experiment: ExperimentConfig, distinctId: string): VariantId => {\n const control = experiment.variants[0]?.id ?? \"control\";\n if (experiment.winner) return experiment.winner;\n if (experiment.status !== \"running\") return control;\n const u = hashUnit(`${experiment.key}:${distinctId}`);\n let acc = 0;\n for (const v of experiment.variants) {\n acc += v.weight;\n if (u < acc) return v.id;\n }\n return experiment.variants[experiment.variants.length - 1]?.id ?? control;\n};\n\n/** `\"a:b,c:d\"` → `{ a: \"b\", c: \"d\" }`. Ignores anything malformed. */\nexport const parsePreview = (value: string | string[] | null | undefined): Record<string, VariantId> => {\n const raw = Array.isArray(value) ? value[0] : value;\n if (!raw) return {};\n const out: Record<string, VariantId> = {};\n for (const pair of raw.split(\",\")) {\n const [key, variant] = pair.split(\":\");\n if (key && variant) out[key.trim()] = variant.trim();\n }\n return out;\n};\n\n/** A link that shows one variant of a page, for example in Cockpit's preview frames. */\nexport const previewHref = (url: string, forced: Record<string, VariantId>, embed = true) => {\n const [path, query = \"\"] = url.split(\"?\");\n const params = new URLSearchParams(query);\n const value = Object.entries(forced)\n .map(([k, v]) => `${k}:${v}`)\n .join(\",\");\n if (value) params.set(PREVIEW_PARAM, value);\n if (embed) params.set(EMBED_PARAM, \"1\");\n return `${path}?${params.toString()}`;\n};\n\n/** The variant for one experiment, from a forced preview first, then the config. Unknown experiments get control. */\n/** The experiments whose variants change the text `id`: showing that text is an exposure to them. */\nexport const experimentsOfText = (config: CockpitConfig | null, id: string) =>\n (config?.experiments ?? []).filter((e) => e.variants.some((v) => v.changes && id in v.changes)).map((e) => e.key);\n\nexport const resolveVariant = (key: string, config: CockpitConfig | null, distinctId: string, preview: Record<string, VariantId>): VariantId => {\n if (preview[key]) return preview[key];\n const experiment = config?.experiments.find((e) => e.key === key);\n return experiment ? assign(experiment, distinctId) : \"control\";\n};\n\n/**\n * Every text change that applies to this visitor: the published texts first, then each experiment's in config order.\n * Control keeps the published (or the page's own) words, so only a non-control variant (assigned, forced in a preview,\n * or a shipped winner) changes them further.\n */\nexport const textChanges = (config: CockpitConfig | null, distinctId: string, preview: Record<string, VariantId>) => {\n const out: Record<string, string> = { ...(config?.texts ?? {}) };\n for (const experiment of config?.experiments ?? []) {\n const id = resolveVariant(experiment.key, config, distinctId, preview);\n if (id === (experiment.variants[0]?.id ?? \"control\")) continue;\n Object.assign(out, experiment.variants.find((v) => v.id === id)?.changes ?? {});\n }\n return out;\n};\n\n/**\n * The query parameter a redirect test adds to the variant's address (`ck_x=<test>:<variant>`): the page there records\n * the exposure and takes it out of the address bar. It also keeps that page from redirecting again.\n */\nexport const EXPOSURE_PARAM = \"ck_x\";\n\n/** What `redirectFor` decided: go to `to`, and/or the redirect test this page belongs to and the visitor's variant. */\nexport interface RedirectDecision {\n /** Where to send the visitor now. Missing for control, which stays on the page. */\n to?: string;\n /** The redirect test, while it runs: record `$exposure` for it (on this page for control, on `to` otherwise). */\n experiment?: string;\n variant?: VariantId;\n}\n\nconst pathOf = (p: string) => p.replace(/\\/+$/, \"\") || \"/\";\n\n/**\n * Where a page sends the visitor, before it shows: a page redirect set in MRRocket first, else a redirect test that runs\n * on this path (the visitor's variant, by the same stable assignment as every test). Null when nothing applies.\n *\n * - The new address keeps the page's query (UTM parameters) and its hash; a running test adds `ck_x=<test>:<variant>`,\n * so the page it lands on records the exposure (and never redirects again).\n * - `distinctId` null (no stable id, as on a server without the `ck_id` cookie): running tests are left to the browser,\n * page redirects and shipped winners still apply.\n * - A redirect to the page itself is ignored.\n */\nexport const redirectFor = (config: CockpitConfig | null, href: string, distinctId: string | null, preview: Record<string, VariantId> = {}): RedirectDecision | null => {\n if (!config) return null;\n let here: URL;\n try {\n here = new URL(href);\n } catch {\n return null;\n }\n if (here.searchParams.has(EXPOSURE_PARAM)) return null;\n const path = pathOf(here.pathname);\n const go = (to: string, mark?: string) => {\n let t: URL;\n try {\n t = new URL(to, here);\n } catch {\n return undefined;\n }\n if (!/^https?:$/.test(t.protocol) || (t.origin === here.origin && pathOf(t.pathname) === path)) return undefined;\n here.searchParams.forEach((v, k) => {\n if (!t.searchParams.has(k)) t.searchParams.set(k, v);\n });\n if (mark) t.searchParams.set(EXPOSURE_PARAM, mark);\n if (!t.hash) t.hash = here.hash;\n return t.href;\n };\n for (const r of config.redirects ?? []) {\n const to = r.from && pathOf(r.from) === path ? go(r.to) : undefined;\n if (to) return { to };\n }\n for (const e of config.experiments) {\n if (!e.path || pathOf(e.path) !== path) continue;\n const running = e.status === \"running\" && !e.winner;\n if (running && distinctId === null && !preview[e.key]) return null;\n const variant = resolveVariant(e.key, config, distinctId ?? \"\", preview);\n const url = e.variants.find((v) => v.id === variant)?.url;\n const to = url ? go(url, running ? `${e.key}:${variant}` : undefined) : undefined;\n return running ? { to, experiment: e.key, variant } : to ? { to } : null;\n }\n return null;\n};\n\n/** The test and variant a redirect test's `ck_x` names, when the config has them; null otherwise. */\nexport const exposureFrom = (config: CockpitConfig | null, value: string | null | undefined) => {\n const [key, variant] = (value ?? \"\").split(\":\");\n const e = config?.experiments.find((x) => x.key === key);\n return e && e.variants.some((v) => v.id === variant) ? { experiment: key, variant } : null;\n};\n\n/**\n * The MRRocket API host from `NEXT_PUBLIC_MRROCKET_HOST`. Written as a literal property access on purpose: Next.js\n * inlines `process.env.NEXT_PUBLIC_*` at build time, in the browser bundle and in the server bundle (also on\n * Cloudflare Workers), and only replaces the literal form. Without a bundler (or a `process`) it is undefined.\n */\nexport const envHost = (): string | undefined => {\n try {\n return process.env.NEXT_PUBLIC_MRROCKET_HOST || undefined;\n } catch {\n return undefined;\n }\n};\n\n/** The public key from `NEXT_PUBLIC_MRROCKET_KEY`, the default for the `apiKey` prop. Same literal-access rule as `envHost`. */\nexport const envKey = (): string | undefined => {\n try {\n return process.env.NEXT_PUBLIC_MRROCKET_KEY || undefined;\n } catch {\n return undefined;\n }\n};\n\n/**\n * Where the API lives: the `host` prop, else `NEXT_PUBLIC_MRROCKET_HOST`, else \"\" (the page's own origin, which is how\n * MRRocket's own demo pages call it). Without a trailing slash.\n */\nexport const resolveHost = (host?: string) => (host ?? envHost() ?? \"\").trim().replace(/\\/+$/, \"\");\n\n/** A random visitor id. */\nexport const newDistinctId = () =>\n typeof crypto !== \"undefined\" && \"randomUUID\" in crypto ? crypto.randomUUID() : `ck_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;\n"],"mappings":";AAUO,IAAM,cAAc;AA2F3B,IAAM,SAAS,CAAC,QAAoB,SAAiB;AACjD,QAAM,OAAO,KAAK,KAAK,EAAE,YAAY;AACrC,aAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,MAAM,EAAG,KAAI,EAAE,YAAY,MAAM,KAAM,QAAO;AAClF,SAAO;AACX;AAGA,IAAM,OAAO,CAAC,QAAgB,UAAkB;AAC5C,QAAM,IAAI,OAAO,KAAK,EAAE,YAAY;AACpC,QAAM,IAAI,MAAM,KAAK,EAAE,YAAY;AACnC,SAAO,EAAE,WAAW,GAAG,IAAI,EAAE,SAAS,CAAC,IAAI,MAAM;AACrD;AAEA,IAAM,mBAAmB,CAAC,GAAkB,WAAuB;AAE/D,MAAI,EAAE,OAAO,YAAa,QAAO;AACjC,QAAM,MAAM,OAAO,QAAQ,EAAE,QAAQ;AACrC,QAAM,SAAS,QAAQ,UAAa,QAAQ,OAAO,KAAK,OAAO,GAAG;AAClE,MAAI,EAAE,OAAO,UAAK;AACd,UAAM,IAAI,OAAO,MAAM;AACvB,UAAM,IAAI,OA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Q,cAAc,IAAI,OAAO;AACvE,UAAM,MAAM,EAAE,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,OAAO,GAAG;AACtD,UAAM,KAAK,MAAM,GAAG,KAAK,UAAU,GAAG,EAAE,GAAG,IAAI,OAAO,KAAK,MAAS,IAAI;AACxE,WAAO,UAAU,EAAE,IAAI,YAAY,EAAE,KAAK,QAAQ,IAAI,KAAK,EAAE,GAAG,IAAI;AAAA,EACxE;AACA,SAAO;AACX;AAGO,IAAM,eAAe,CAAC,QAA8B,UAAqC;AAC5F,QAAM,CAAC,KAAK,OAAO,KAAK,SAAS,IAAI,MAAM,GAAG;AAC9C,QAAM,IAAI,QAAQ,YAAY,KAAK,CAAC,MAAM,EAAE,QAAQ,GAAG;AACvD,SAAO,KAAK,EAAE,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,OAAO,IAAI,EAAE,YAAY,KAAK,QAAQ,IAAI;AAC1F;AAOO,IAAM,UAAU,MAA0B;AAC7C,MAAI;AACA,WAAO,QAAQ,IAAI,6BAA6B;AAAA,EACpD,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAGO,IAAM,SAAS,MAA0B;AAC5C,MAAI;AACA,WAAO,QAAQ,IAAI,4BAA4B;AAAA,EACnD,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAMO,IAAM,cAAc,CAAC,UAAmB,QAAQ,QAAQ,KAAK,IAAI,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAG1F,IAAM,gBAAgB,MACzB,OAAO,WAAW,eAAe,gBAAgB,SAAS,OAAO,WAAW,IAAI,MAAM,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,GAAG,KAAK,IAAI,EAAE,SAAS,EAAE,CAAC;","names":[]}
1
+ {"version":3,"sources":["../src/core.ts"],"sourcesContent":["/**\n * The part of the SDK that runs anywhere: experiment config, variant assignment, preview links and event shapes.\n * No React, no browser APIs, so the server helper, the proxy helper and the client share it.\n */\nimport type { CancelFlowConfig, OnboardingFlow } from \"./flows\";\nimport type { PaywallConfig } from \"./paywall\";\n\nexport type VariantId = string;\n\n/** This build of the SDK. Sent with the config request so MRRocket knows what the site runs (error tracking, flags). */\nexport const SDK_VERSION = \"0.15.0\";\n\n/** One variant of an experiment. `changes` replaces texts that the page marks with `<Text id>`. */\nexport interface VariantConfig {\n id: VariantId;\n /** Share of traffic, 0 to 1. The weights of an experiment add up to 1. */\n weight: number;\n changes?: Record<string, string>;\n /**\n * A redirect test: where this variant sends the visitor instead of the test's page (a path like \"/pricing-b\" or a\n * full address). Control has none and stays. SDK 0.7.0+.\n */\n url?: string;\n}\n\nexport interface ExperimentConfig {\n /** The experiment's key, the same as in Cockpit. */\n key: string;\n status: \"running\" | \"draft\" | \"stopped\";\n /** Control first. */\n variants: VariantConfig[];\n /** A winner that shipped: everyone gets it, and nobody is assigned anymore. */\n winner?: VariantId;\n /** A redirect test: the path of the page it runs on (\"/pricing\"). Visitors there are sent to their variant's `url`. */\n path?: string;\n}\n\n/** A page redirect set in MRRocket (Conversion › Landing pages › Redirect): everyone on `from` goes to `to`. SDK 0.7.0+. */\nexport interface RedirectConfig {\n /** A path of the site, like \"/old-pricing\". */\n from: string;\n /** A path or a full address. */\n to: string;\n}\n\nexport interface CockpitConfig {\n /** The product the public key belongs to. */\n project: string;\n experiments: ExperimentConfig[];\n /** The product's affiliate program: how many days a partner's referral is kept. Missing without a program. */\n referral?: { cookieDays: number };\n /** Session recordings: present only while the product records (Cockpit › Sessions). See `ReplayConfig`. */\n replay?: ReplayConfig;\n /** Feature flags of the product in Production (MRRocket › Build › Feature flags), evaluated by `useFlag` and `getFlag`. */\n flags?: FlagConfig[];\n /**\n * Published copy for texts the site marks (`<Text id>`, `data-ck-text`): a landing page's headline, subheadline and\n * button (`pricing.headline` …) and a paywall's (`paywall.<placement>.headline` …) as published in MRRocket. A\n * running test's variant changes them on top. Missing when nothing is published. SDK 0.5.0+.\n */\n texts?: Record<string, string>;\n /** The product's live cancel flow (MRRocket › Churn › Cancel flow), for `cancelFlow.open()`. SDK 0.7.0+. */\n cancelFlow?: CancelFlowConfig;\n /** The in-app steps of live onboarding flows (tours, checklists, modals). SDK 0.7.0+. */\n onboarding?: OnboardingFlow[];\n /** A live Lifecycle journey has in-app messages: signed-in people ask `/api/sdk/inapp` for theirs. SDK 0.7.0+. */\n messages?: boolean;\n /** Page redirects set in MRRocket; the SDK sends visitors on before the page shows (`redirectFor`). SDK 0.7.0+. */\n redirects?: RedirectConfig[];\n /** Published paywalls with their pages, per placement (MRRocket › Conversion › Paywalls), for `paywall.open()`. SDK 0.14.0+. */\n paywalls?: PaywallConfig[];\n}\n\n/** One condition of a flag's audience, on a property of the person (`identify(id, props)`), the id or the page. */\nexport interface FlagCondition {\n /** \"Email\", \"Plan\", \"Country\", \"id\", \"path\" … Matched against the person's properties without regard to case. */\n property: string;\n op: \"is\" | \"is not\" | \"in\" | \"not in\" | \"≥\" | \"in cohort\";\n values: string[];\n}\n\n/** Users who match every condition, of whom `rollout` percent get the flag. No conditions: everyone. */\nexport interface FlagConditionSet {\n conditions: FlagCondition[];\n /** 0 to 100. */\n rollout: number;\n}\n\nexport interface FlagConfig {\n key: string;\n /** Off: everyone gets the off side. */\n on: boolean;\n /** The first set a person matches decides; none matched: off. */\n sets: FlagConditionSet[];\n /** Multivariate flags: the variants and their split in percent (control included). Missing for an on/off flag. */\n variants?: { key: string; split: number; payload?: string }[];\n}\n\n/** What a person is for flag conditions: their properties from identify(), their id and the page they are on. */\nexport type FlagPerson = Record<string, unknown>;\n\nconst propOf = (person: FlagPerson, name: string) => {\n const want = name.trim().toLowerCase();\n for (const [k, v] of Object.entries(person)) if (k.toLowerCase() === want) return v;\n return undefined;\n};\n\n/** `\"@acme.com\"` matches every address at that domain; anything else matches the whole value, without regard to case. */\nconst same = (actual: string, value: string) => {\n const a = actual.trim().toLowerCase();\n const v = value.trim().toLowerCase();\n return v.startsWith(\"@\") ? a.endsWith(v) : a === v;\n};\n\nconst matchesCondition = (c: FlagCondition, person: FlagPerson) => {\n // Cohorts live in MRRocket; a browser cannot know them, so a cohort condition never matches here.\n if (c.op === \"in cohort\") return false;\n const raw = propOf(person, c.property);\n const actual = raw === undefined || raw === null ? \"\" : String(raw);\n if (c.op === \"≥\") {\n const a = Number(actual);\n const b = Number(c.values[0]);\n return actual !== \"\" && Number.isFinite(a) && Number.isFinite(b) && a >= b;\n }\n const hit = actual !== \"\" && c.values.some((v) => same(actual, v));\n return c.op === \"is\" || c.op === \"in\" ? hit : !hit;\n};\n\n/**\n * The flag for one person: `false` (off), `true` (on, an on/off flag) or the variant's key (a multivariate flag). The\n * bucket is a stable hash of flag and person, so a person keeps their side as the rollout grows.\n */\nexport const evaluateFlag = (flag: FlagConfig, distinctId: string, person: FlagPerson = {}): boolean | string => {\n if (!flag.on) return false;\n const subject = { id: distinctId, ...person };\n const set = flag.sets.length ? flag.sets.find((s) => s.conditions.every((c) => matchesCondition(c, subject))) : { conditions: [], rollout: 100 };\n if (!set) return false;\n if (flagUnit(`${flag.key}:rollout:${distinctId}`) * 100 >= set.rollout) return false;\n if (!flag.variants?.length) return true;\n const u = flagUnit(`${flag.key}:variant:${distinctId}`) * 100;\n let acc = 0;\n for (const v of flag.variants) {\n acc += v.split;\n if (u < acc) return v.key;\n }\n return flag.variants[flag.variants.length - 1].key;\n};\n\n/** A flag of the config for this person; an unknown flag (or no config) is off. */\nexport const flagFor = (key: string, config: CockpitConfig | null, distinctId: string, person: FlagPerson = {}) => {\n const flag = config?.flags?.find((f) => f.key === key);\n return flag ? evaluateFlag(flag, distinctId, person) : false;\n};\n\n/** One JavaScript error as it goes over the wire to `POST /api/sdk/errors`. */\nexport interface ErrorReport {\n /** \"TypeError\", \"Error\" … */\n type: string;\n message: string;\n /** The raw stack, at most 8 KB. MRRocket parses it into frames. */\n stack?: string;\n /** \"onerror\" (uncaught), \"onunhandledrejection\" (a rejected promise nobody caught) or \"manual\" (captureError). */\n mechanism: \"onerror\" | \"onunhandledrejection\" | \"manual\";\n handled: boolean;\n url: string;\n ts: number;\n /** What happened just before: pages and clicks, newest last, at most 20. */\n crumbs?: { ts: number; type: \"navigation\" | \"click\" | \"lifecycle\"; message: string }[];\n /** Your release (a version or commit), from the provider's `release` prop. */\n release?: string;\n distinctId?: string;\n sessionId?: string;\n}\n\n/**\n * Session recordings of a product, from the config. Recording also needs the visitor's own replay consent\n * (`<CockpitProvider replay>` or `setConsent({ replay: true })`); without it nothing is recorded or buffered.\n */\nexport interface ReplayConfig {\n /**\n * Share of sessions uploaded from their start, 0 to 1 (default 0.1). The others keep only the last minute in\n * memory and upload it when something goes wrong: a JS error, a rage click, a `purchase…` or `checkout…` event.\n */\n sampleRate: number;\n}\n\n/**\n * What the SDK may send and store.\n * - \"cookieless\" (default): no cookie, no localStorage. Events go without a visitor id; the server counts visitors\n * with a hash of key, date, IP and user agent that changes every day.\n * - \"cookies\": a persistent `ck_id` cookie identifies the visitor across visits, `ck_sid` holds the session.\n * - \"off\": nothing is sent and nothing is stored.\n */\nexport type ConsentMode = \"cookieless\" | \"cookies\" | \"off\";\n\n/**\n * What `setConsent` takes: a mode as before, or the parts to change. `replay` is the separate consent for session\n * recordings (default false); it applies only while analytics is not \"off\".\n *\n * setConsent(\"cookies\");\n * setConsent({ replay: true });\n * setConsent({ analytics: \"cookieless\", replay: false });\n */\nexport type ConsentChoice = ConsentMode | { analytics?: ConsentMode; replay?: boolean };\n\n/** The campaign parameters the SDK reads from the landing URL. */\nexport const UTM_KEYS = [\"utm_source\", \"utm_medium\", \"utm_campaign\", \"utm_term\", \"utm_content\"] as const;\nexport type UtmKey = (typeof UTM_KEYS)[number];\n\n/** One event as it goes over the wire to `POST /api/sdk/events`. */\nexport interface CockpitEvent {\n event: string;\n /** The visitor. Missing in \"cookieless\" mode until identify(): the server then uses its daily visitor hash. */\n distinctId?: string;\n /** Ends after 30 minutes without an event. */\n sessionId?: string;\n props?: Record<string, unknown>;\n /** Milliseconds since the epoch. */\n ts: number;\n url?: string;\n /** `document.referrer` on the first page of a page load, the previous in-app URL after client-side navigation. */\n referrer?: string;\n utm_source?: string;\n utm_medium?: string;\n utm_campaign?: string;\n utm_term?: string;\n utm_content?: string;\n /** The screen size in CSS pixels (points on a phone). */\n screen?: { w: number; h: number };\n /** The app that sent it (React Native only): MRRocket stores it with the event and fills OS and device from it. */\n app?: AppContext;\n}\n\n/** Where a React Native event comes from. Every field is optional except the platform; nothing identifies the person. */\nexport interface AppContext {\n /** \"ios\" or \"android\" (React Native's `Platform.OS`). */\n platform: string;\n /** The app's version, like \"1.4.0\" (`expo-application`'s `nativeApplicationVersion`). */\n appVersion?: string;\n /** The build number, like \"42\". */\n build?: string;\n /** The OS version, like \"17.4\". */\n osVersion?: string;\n /** The device model, like \"iPhone 15 Pro\" (`expo-device`). */\n deviceModel?: string;\n /** \"phone\", \"tablet\", \"desktop\" or \"tv\" when `expo-device` knows it. */\n deviceType?: string;\n /** The first preferred locale, like \"de-DE\". */\n locale?: string;\n}\n\n/** The query parameter that forces variants, for previews in Cockpit: `?ck_preview=pricing-annual:a,home-hero:control`. */\nexport const PREVIEW_PARAM = \"ck_preview\";\n/** Set when Cockpit embeds the page: nothing is tracked, so previews never count as visits. */\nexport const EMBED_PARAM = \"ck_embed\";\n/** The cookie that keeps a visitor in the same variant across visits. Only written in \"cookies\" mode. */\nexport const ID_COOKIE = \"ck_id\";\n/** The cookie that holds the session id in \"cookies\" mode. */\nexport const SESSION_COOKIE = \"ck_sid\";\n/** A session ends after this long without an event. */\nexport const SESSION_TIMEOUT_MS = 30 * 60 * 1000;\n\n/** The UTM parameters from a parameter lookup (`URLSearchParams.get` in a browser). Empty values are left out. */\nexport const utmFrom = (get: (name: string) => string | null | undefined): Partial<Record<UtmKey, string>> => {\n const out: Partial<Record<UtmKey, string>> = {};\n for (const key of UTM_KEYS) {\n const value = get(key)?.trim();\n if (value) out[key] = value.slice(0, 150);\n }\n return out;\n};\n\n/** The UTM parameters of a query string, like `\"?utm_source=x\"`. Empty values are left out. */\nexport const readUtm = (search: string): Partial<Record<UtmKey, string>> => {\n const params = new URLSearchParams(search);\n return utmFrom((k) => params.get(k));\n};\n\n/**\n * The query parameters of a URL or query string, without `URLSearchParams` (React Native's is incomplete): `+` is a\n * space, values are percent-decoded, the first of a repeated name wins.\n */\nexport const parseQuery = (url: string): Record<string, string> => {\n const out: Record<string, string> = {};\n const q = url.split(\"#\")[0];\n const at = q.indexOf(\"?\");\n if (at < 0) return out;\n const dec = (s: string) => {\n try {\n return decodeURIComponent(s.replace(/\\+/g, \" \"));\n } catch {\n return s;\n }\n };\n for (const pair of q.slice(at + 1).split(\"&\")) {\n if (!pair) continue;\n const eq = pair.indexOf(\"=\");\n const k = dec(eq < 0 ? pair : pair.slice(0, eq));\n if (k && !(k in out)) out[k] = eq < 0 ? \"\" : dec(pair.slice(eq + 1));\n }\n return out;\n};\n\n/** FNV-1a, 32 bit, mapped to [0, 1). Stable across server and browser. */\nexport const hashUnit = (input: string) => {\n let h = 0x811c9dc5;\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n return (h >>> 0) / 4294967296;\n};\n\n/**\n * FNV-1a with murmur3's finalizer, mapped to [0, 1): ids that differ only at the end (\"user-1\", \"user-2\") still spread\n * evenly, so a 30 % rollout reaches about 30 % of people. Flags only; experiments keep `hashUnit` so nobody switches.\n */\nexport const flagUnit = (input: string) => {\n let h = 0x811c9dc5;\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n h ^= h >>> 16;\n h = Math.imul(h, 0x85ebca6b);\n h ^= h >>> 13;\n h = Math.imul(h, 0xc2b2ae35);\n h ^= h >>> 16;\n return (h >>> 0) / 4294967296;\n};\n\n/** The variant a visitor sees: a shipped winner, control while the experiment does not run, else a stable bucket by visitor. */\nexport const assign = (experiment: ExperimentConfig, distinctId: string): VariantId => {\n const control = experiment.variants[0]?.id ?? \"control\";\n if (experiment.winner) return experiment.winner;\n if (experiment.status !== \"running\") return control;\n const u = hashUnit(`${experiment.key}:${distinctId}`);\n let acc = 0;\n for (const v of experiment.variants) {\n acc += v.weight;\n if (u < acc) return v.id;\n }\n return experiment.variants[experiment.variants.length - 1]?.id ?? control;\n};\n\n/** `\"a:b,c:d\"` → `{ a: \"b\", c: \"d\" }`. Ignores anything malformed. */\nexport const parsePreview = (value: string | string[] | null | undefined): Record<string, VariantId> => {\n const raw = Array.isArray(value) ? value[0] : value;\n if (!raw) return {};\n const out: Record<string, VariantId> = {};\n for (const pair of raw.split(\",\")) {\n const [key, variant] = pair.split(\":\");\n if (key && variant) out[key.trim()] = variant.trim();\n }\n return out;\n};\n\n/** A link that shows one variant of a page, for example in Cockpit's preview frames. */\nexport const previewHref = (url: string, forced: Record<string, VariantId>, embed = true) => {\n const [path, query = \"\"] = url.split(\"?\");\n const params = new URLSearchParams(query);\n const value = Object.entries(forced)\n .map(([k, v]) => `${k}:${v}`)\n .join(\",\");\n if (value) params.set(PREVIEW_PARAM, value);\n if (embed) params.set(EMBED_PARAM, \"1\");\n return `${path}?${params.toString()}`;\n};\n\n/** The variant for one experiment, from a forced preview first, then the config. Unknown experiments get control. */\n/** The experiments whose variants change the text `id`: showing that text is an exposure to them. */\nexport const experimentsOfText = (config: CockpitConfig | null, id: string) =>\n (config?.experiments ?? []).filter((e) => e.variants.some((v) => v.changes && id in v.changes)).map((e) => e.key);\n\nexport const resolveVariant = (key: string, config: CockpitConfig | null, distinctId: string, preview: Record<string, VariantId>): VariantId => {\n if (preview[key]) return preview[key];\n const experiment = config?.experiments.find((e) => e.key === key);\n return experiment ? assign(experiment, distinctId) : \"control\";\n};\n\n/**\n * Every text change that applies to this visitor: the published texts first, then each experiment's in config order.\n * Control keeps the published (or the page's own) words, so only a non-control variant (assigned, forced in a preview,\n * or a shipped winner) changes them further.\n */\nexport const textChanges = (config: CockpitConfig | null, distinctId: string, preview: Record<string, VariantId>) => {\n const out: Record<string, string> = { ...(config?.texts ?? {}) };\n for (const experiment of config?.experiments ?? []) {\n const id = resolveVariant(experiment.key, config, distinctId, preview);\n if (id === (experiment.variants[0]?.id ?? \"control\")) continue;\n Object.assign(out, experiment.variants.find((v) => v.id === id)?.changes ?? {});\n }\n return out;\n};\n\n/**\n * The query parameter a redirect test adds to the variant's address (`ck_x=<test>:<variant>`): the page there records\n * the exposure and takes it out of the address bar. It also keeps that page from redirecting again.\n */\nexport const EXPOSURE_PARAM = \"ck_x\";\n\n/** What `redirectFor` decided: go to `to`, and/or the redirect test this page belongs to and the visitor's variant. */\nexport interface RedirectDecision {\n /** Where to send the visitor now. Missing for control, which stays on the page. */\n to?: string;\n /** The redirect test, while it runs: record `$exposure` for it (on this page for control, on `to` otherwise). */\n experiment?: string;\n variant?: VariantId;\n}\n\nconst pathOf = (p: string) => p.replace(/\\/+$/, \"\") || \"/\";\n\n/**\n * Where a page sends the visitor, before it shows: a page redirect set in MRRocket first, else a redirect test that runs\n * on this path (the visitor's variant, by the same stable assignment as every test). Null when nothing applies.\n *\n * - The new address keeps the page's query (UTM parameters) and its hash; a running test adds `ck_x=<test>:<variant>`,\n * so the page it lands on records the exposure (and never redirects again).\n * - `distinctId` null (no stable id, as on a server without the `ck_id` cookie): running tests are left to the browser,\n * page redirects and shipped winners still apply.\n * - A redirect to the page itself is ignored.\n */\nexport const redirectFor = (config: CockpitConfig | null, href: string, distinctId: string | null, preview: Record<string, VariantId> = {}): RedirectDecision | null => {\n if (!config) return null;\n let here: URL;\n try {\n here = new URL(href);\n } catch {\n return null;\n }\n if (here.searchParams.has(EXPOSURE_PARAM)) return null;\n const path = pathOf(here.pathname);\n const go = (to: string, mark?: string) => {\n let t: URL;\n try {\n t = new URL(to, here);\n } catch {\n return undefined;\n }\n if (!/^https?:$/.test(t.protocol) || (t.origin === here.origin && pathOf(t.pathname) === path)) return undefined;\n here.searchParams.forEach((v, k) => {\n if (!t.searchParams.has(k)) t.searchParams.set(k, v);\n });\n if (mark) t.searchParams.set(EXPOSURE_PARAM, mark);\n if (!t.hash) t.hash = here.hash;\n return t.href;\n };\n for (const r of config.redirects ?? []) {\n const to = r.from && pathOf(r.from) === path ? go(r.to) : undefined;\n if (to) return { to };\n }\n for (const e of config.experiments) {\n if (!e.path || pathOf(e.path) !== path) continue;\n const running = e.status === \"running\" && !e.winner;\n if (running && distinctId === null && !preview[e.key]) return null;\n const variant = resolveVariant(e.key, config, distinctId ?? \"\", preview);\n const url = e.variants.find((v) => v.id === variant)?.url;\n const to = url ? go(url, running ? `${e.key}:${variant}` : undefined) : undefined;\n return running ? { to, experiment: e.key, variant } : to ? { to } : null;\n }\n return null;\n};\n\n/** The test and variant a redirect test's `ck_x` names, when the config has them; null otherwise. */\nexport const exposureFrom = (config: CockpitConfig | null, value: string | null | undefined) => {\n const [key, variant] = (value ?? \"\").split(\":\");\n const e = config?.experiments.find((x) => x.key === key);\n return e && e.variants.some((v) => v.id === variant) ? { experiment: key, variant } : null;\n};\n\n/**\n * The MRRocket API host from `NEXT_PUBLIC_MRROCKET_HOST`. Written as a literal property access on purpose: Next.js\n * inlines `process.env.NEXT_PUBLIC_*` at build time, in the browser bundle and in the server bundle (also on\n * Cloudflare Workers), and only replaces the literal form. Without a bundler (or a `process`) it is undefined.\n */\nexport const envHost = (): string | undefined => {\n try {\n return process.env.NEXT_PUBLIC_MRROCKET_HOST || undefined;\n } catch {\n return undefined;\n }\n};\n\n/** The public key from `NEXT_PUBLIC_MRROCKET_KEY`, the default for the `apiKey` prop. Same literal-access rule as `envHost`. */\nexport const envKey = (): string | undefined => {\n try {\n return process.env.NEXT_PUBLIC_MRROCKET_KEY || undefined;\n } catch {\n return undefined;\n }\n};\n\n/**\n * Where the API lives: the `host` prop, else `NEXT_PUBLIC_MRROCKET_HOST`, else \"\" (the page's own origin, which is how\n * MRRocket's own demo pages call it). Without a trailing slash.\n */\nexport const resolveHost = (host?: string) => (host ?? envHost() ?? \"\").trim().replace(/\\/+$/, \"\");\n\n/** A random visitor id. */\nexport const newDistinctId = () =>\n typeof crypto !== \"undefined\" && \"randomUUID\" in crypto ? crypto.randomUUID() : `ck_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;\n"],"mappings":";AAUO,IAAM,cAAc;AA2F3B,IAAM,SAAS,CAAC,QAAoB,SAAiB;AACjD,QAAM,OAAO,KAAK,KAAK,EAAE,YAAY;AACrC,aAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,MAAM,EAAG,KAAI,EAAE,YAAY,MAAM,KAAM,QAAO;AAClF,SAAO;AACX;AAGA,IAAM,OAAO,CAAC,QAAgB,UAAkB;AAC5C,QAAM,IAAI,OAAO,KAAK,EAAE,YAAY;AACpC,QAAM,IAAI,MAAM,KAAK,EAAE,YAAY;AACnC,SAAO,EAAE,WAAW,GAAG,IAAI,EAAE,SAAS,CAAC,IAAI,MAAM;AACrD;AAEA,IAAM,mBAAmB,CAAC,GAAkB,WAAuB;AAE/D,MAAI,EAAE,OAAO,YAAa,QAAO;AACjC,QAAM,MAAM,OAAO,QAAQ,EAAE,QAAQ;AACrC,QAAM,SAAS,QAAQ,UAAa,QAAQ,OAAO,KAAK,OAAO,GAAG;AAClE,MAAI,EAAE,OAAO,UAAK;AACd,UAAM,IAAI,OAAO,MAAM;AACvB,UAAM,IAAI,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5B,WAAO,WAAW,MAAM,OAAO,SAAS,CAAC,KAAK,OAAO,SAAS,CAAC,KAAK,KAAK;AAAA,EAC7E;AACA,QAAM,MAAM,WAAW,MAAM,EAAE,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC;AACjE,SAAO,EAAE,OAAO,QAAQ,EAAE,OAAO,OAAO,MAAM,CAAC;AACnD;AAMO,IAAM,eAAe,CAAC,MAAkB,YAAoB,SAAqB,CAAC,MAAwB;AAC7G,MAAI,CAAC,KAAK,GAAI,QAAO;AACrB,QAAM,UAAU,EAAE,IAAI,YAAY,GAAG,OAAO;AAC5C,QAAM,MAAM,KAA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C,MAAM,EAAE,QAAQ,GAAG;AACvD,SAAO,KAAK,EAAE,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,OAAO,IAAI,EAAE,YAAY,KAAK,QAAQ,IAAI;AAC1F;AAOO,IAAM,UAAU,MAA0B;AAC7C,MAAI;AACA,WAAO,QAAQ,IAAI,6BAA6B;AAAA,EACpD,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAGO,IAAM,SAAS,MAA0B;AAC5C,MAAI;AACA,WAAO,QAAQ,IAAI,4BAA4B;AAAA,EACnD,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAMO,IAAM,cAAc,CAAC,UAAmB,QAAQ,QAAQ,KAAK,IAAI,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAG1F,IAAM,gBAAgB,MACzB,OAAO,WAAW,eAAe,gBAAgB,SAAS,OAAO,WAAW,IAAI,MAAM,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,GAAG,KAAK,IAAI,EAAE,SAAS,EAAE,CAAC;","names":[]}
package/dist/flows-ui.js CHANGED
@@ -102,7 +102,7 @@ var dots = (step, steps) => steps > 1 ? h(
102
102
  { className: "ckf-dots", role: "img", "aria-label": `Step ${step} of ${steps}` },
103
103
  ...Array.from({ length: steps }, (_, i) => h("span", { className: "ckf-dot", "data-on": i < step }))
104
104
  ) : h("span");
105
- var screenKey = (v) => v.type === "cancel" ? `c:${v.screen}` : v.type === "step" ? `s:${v.step.id}` : v.type === "checklist" ? `l:${v.flow.id}` : `m:${v.message.id}`;
105
+ var screenKey = (v) => v.type === "cancel" ? `c:${v.screen}:${v.round ?? 1}` : v.type === "step" ? `s:${v.step.id}` : v.type === "checklist" ? `l:${v.flow.id}` : `m:${v.message.id}`;
106
106
  var rootFor = (theme) => {
107
107
  if (!document.getElementById(STYLE_ID)) {
108
108
  const style = document.createElement("style");
@@ -156,6 +156,53 @@ var mountFlows = (ctl, theme = {}) => {
156
156
  button("Never mind, keep my plan", "quiet", ctl.cancel.close)
157
157
  )
158
158
  );
159
+ } else if (v.screen === "followup" && v.followUp) {
160
+ const f = v.followUp;
161
+ let field;
162
+ if (f.answers.length)
163
+ field = h(
164
+ "div",
165
+ { className: "ckf-opts", role: "radiogroup", "aria-labelledby": titleId },
166
+ ...f.answers.map(
167
+ (a, i) => h(
168
+ "button",
169
+ {
170
+ type: "button",
171
+ role: "radio",
172
+ className: "ckf-opt",
173
+ "aria-checked": String(v.answer === a),
174
+ "data-ckf-id": `a:${i}`,
175
+ onClick: () => ctl.cancel.answer(a)
176
+ },
177
+ h("span", { className: "ckf-radio" }),
178
+ a
179
+ )
180
+ )
181
+ );
182
+ else {
183
+ const text = h("textarea", {
184
+ className: "ckf-text",
185
+ placeholder: "Your answer (optional)",
186
+ "aria-labelledby": titleId,
187
+ maxlength: "500",
188
+ "data-ckf-id": "answer",
189
+ onInput: (e) => ctl.cancel.answer(e.target.value)
190
+ });
191
+ text.value = v.answer ?? "";
192
+ field = text;
193
+ }
194
+ const label = v.flow.reasons.find((r) => r.id === v.reason)?.label;
195
+ body.push(
196
+ label ? h("p", { className: "ckf-small" }, `You said: ${label}`) : false,
197
+ h("h2", { className: "ckf-h", id: titleId }, f.question),
198
+ field,
199
+ h(
200
+ "div",
201
+ { className: "ckf-btns" },
202
+ button("Continue", "primary", ctl.cancel.next, { id: "go" }),
203
+ button("Never mind, keep my plan", "quiet", ctl.cancel.close)
204
+ )
205
+ );
159
206
  } else if (v.screen === "offer" && v.offer) {
160
207
  const o = v.offer;
161
208
  const label = v.flow.reasons.find((r) => r.id === v.reason)?.label;