@indiebob/tracker 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var st=Object.defineProperty,at=Object.defineProperties;var ct=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var ut=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable;var C=(e,t,n)=>t in e?st(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))ut.call(t,n)&&C(e,n,t[n]);if(A)for(var n of A(t))lt.call(t,n)&&C(e,n,t[n]);return e},P=(e,t)=>at(e,ct(t));var l=(e,t,n)=>new Promise((o,i)=>{var r=a=>{try{s(n.next(a));}catch(u){i(u);}},c=a=>{try{s(n.throw(a));}catch(u){i(u);}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((n=n.apply(e,t)).next());});var dt="https://www.indiebob.com/api/collect";function D(e){var t,n,o,i,r;if(!e.projectId||!e.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${e.projectId}". Must start with "proj_".`);return {projectId:e.projectId,endpoint:(t=e.endpoint)!=null?t:dt,debug:(n=e.debug)!=null?n:false,respectDnt:(o=e.respectDnt)!=null?o:true,respectGpc:(i=e.respectGpc)!=null?i:true,autoDetect:(r=e.autoDetect)!=null?r:true}}var d="_ib_anon";function h(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let n=new Uint8Array(21);crypto.getRandomValues(n);for(let o of n)t+=e[o%e.length];}else for(let n=0;n<21;n++)t+=e[Math.floor(Math.random()*e.length)];return t}function v(){try{let e=localStorage.getItem(d);return e||(e=h(),localStorage.setItem(d,e)),e}catch(e){try{let t=sessionStorage.getItem(d);return t||(t=h(),sessionStorage.setItem(d,t)),t}catch(t){return h()}}}function N(){try{localStorage.removeItem(d);}catch(e){}try{sessionStorage.removeItem(d);}catch(e){}}var y="_ib_session",b="_ib_session_last";function F(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function I(){var e;try{let t=Date.now(),n=parseInt((e=sessionStorage.getItem(b))!=null?e:"0",10),o=sessionStorage.getItem(y),i=n>0&&t-n>18e5;return (!o||i)&&(o=F(),sessionStorage.setItem(y,o)),sessionStorage.setItem(b,String(t)),o}catch(t){return F()}}function L(){try{sessionStorage.removeItem(y);}catch(e){}try{sessionStorage.removeItem(b);}catch(e){}}var E="_ib_first_utm",M="_ib_last_utm",S="_ib_referrer";function U(e){let t=new URLSearchParams(e),n={},o=false;return t.has("utm_source")&&(n.source=t.get("utm_source"),o=true),t.has("utm_medium")&&(n.medium=t.get("utm_medium"),o=true),t.has("utm_campaign")&&(n.campaign=t.get("utm_campaign"),o=true),t.has("utm_term")&&(n.term=t.get("utm_term"),o=true),t.has("utm_content")&&(n.content=t.get("utm_content"),o=true),o?n:null}function j(e,t){let n=U(e);try{n&&!localStorage.getItem(E)&&localStorage.setItem(E,JSON.stringify(n)),n&&localStorage.setItem(M,JSON.stringify(n)),t&&!localStorage.getItem(S)&&localStorage.setItem(S,t);}catch(o){}}function q(e){var t;return (t=U(e))!=null?t:void 0}function B(){try{localStorage.removeItem(E);}catch(e){}try{localStorage.removeItem(M);}catch(e){}try{localStorage.removeItem(S);}catch(e){}}var g="_ib_optout",pt="_ib_queue";function p(e){try{if(localStorage.getItem(g))return !1}catch(t){}return !(e.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||e.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function Y(){try{localStorage.setItem(g,"1");}catch(e){}N(),L(),B();try{localStorage.removeItem(pt);}catch(e){}}function H(){try{localStorage.removeItem(g);}catch(e){}}function K(){try{return !!localStorage.getItem(g)}catch(e){return false}}var ft=[1e3,2e3,4e3];function gt(e){return l(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function _(e,t,n=false){return l(this,null,function*(){let o=JSON.stringify(e);if(n&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([o],{type:"application/json"}),r=navigator.sendBeacon(t.endpoint,i);return t.debug&&console.log("[IndieBob] sendBeacon:",r,e.batch.length,"events"),r}for(let i=0;i<3;i++){try{let r=yield fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:o,keepalive:!0});if(r.ok)return t.debug&&console.log("[IndieBob] sent:",e.batch.length,"events"),!0;if(r.status>=400&&r.status<500)return t.debug&&console.warn("[IndieBob] 4xx error, not retrying:",r.status),!1}catch(r){t.debug&&console.warn("[IndieBob] fetch error (attempt",i+1,"):",r);}i<2&&(yield gt(ft[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var w="_ib_queue",mt=10,ht=5e3,vt=50,m=class{constructor(t){this.queue=[];this.timer=null;this.flushing=false;this.config=t,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(t){this.queue.push(t),this.queue.length>=mt&&this.flush();}flush(t=false){return l(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let n=this.queue.splice(0);(yield _({batch:n},this.config,t))||this.pushToOfflineQueue(n),this.flushing=false;})}flushOfflineQueue(){return l(this,null,function*(){let t=this.getOfflineQueue();if(t.length===0)return;this.clearOfflineQueue(),yield _({batch:t},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},ht);}setupVisibilityFlush(){typeof document!="undefined"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(true);},{passive:true});}setupOnlineFlush(){typeof window!="undefined"&&(window.addEventListener("online",()=>{this.flushOfflineQueue();}),navigator.onLine&&this.flushOfflineQueue());}pushToOfflineQueue(t){try{let i=[...this.getOfflineQueue(),...t].slice(-vt);localStorage.setItem(w,JSON.stringify(i));}catch(n){}}getOfflineQueue(){try{let t=localStorage.getItem(w);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(w);}catch(t){}}};function V(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function Q(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}function T(e){var u,R,O,x;let t=typeof window=="undefined",n=(u=e==null?void 0:e.path)!=null?u:t?"":window.location.pathname+window.location.search,o=t?"":window.location.href,i=(R=e==null?void 0:e.title)!=null?R:t?"":document.title,r=(O=e==null?void 0:e.referrer)!=null?O:t?"":document.referrer,c=Q(),s=V(),a=t?void 0:q(window.location.search);return {page:{path:n,url:o,title:i,referrer:r},device:P(f({},c),{type:s}),utm:a,locale:t?"en":navigator.language,timezone:t?"UTC":(x=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?x:"UTC",sdkVersion:"0.2.1"}}function z(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),n=history.replaceState.bind(history);return history.pushState=function(...o){t(...o),e();},history.replaceState=function(...o){n(...o);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=n,window.removeEventListener("popstate",e);}}var yt={signup:[/\/(sign-?up|register|join|create-?account|get-?started|onboard|registro|inscription|s-?inscrire|anmeldung|registrieren|cadastro|registrazione|aanmelden|inschrijven)/i],login:[/\/(log-?in|sign-?in|auth(\/login)?|iniciar-?sesion|connexion|se-?connecter|anmelden|einloggen|entrar|accesso|accedi|inloggen)/i],pricing:[/\/(pricing|plans|upgrade|subscribe|precios|tarifs|preise|precos|prezzi|prijzen)/i],checkout:[/\/(checkout|cart|basket|pay(ment)?|order|comprar|pagar|panier|caisse|warenkorb|kasse|carrinho|carrello|winkelwagen)/i],success:[/\/(success|thank-?you|thanks|confirmation|confirmed|complete[d]?|gracias|merci|danke|obrigado|grazie|bedankt)/i],onboarding:[/\/(onboarding|welcome|getting-?started|setup|bienvenido|bienvenue|willkommen|benvenuto|welkom)/i],contact:[/\/(contact|contacto|kontakt|contato|contatto|nous-?contacter)/i]},X={signup:"signup_start",login:"login_view",pricing:"pricing_view",checkout:"checkout_view",success:"success_view",onboarding:"onboarding_view",contact:"contact_view"};function bt(e,t){return e instanceof RegExp?e.test(t):t.includes(e)}function J(e,t){var n;for(let o of Object.keys(X))if(((n=t==null?void 0:t[o])!=null?n:yt[o]).some(r=>bt(r,e)))return X[o];return null}function $(e){return e==="signup_start"?"signup_submit":e==="login_view"?"login_submit":e==="checkout_view"?"checkout_submit":null}function G(e,t){if(typeof document=="undefined")return ()=>{};let n=o=>{o.target instanceof HTMLFormElement&&t(e);};return document.addEventListener("submit",n,true),()=>document.removeEventListener("submit",n,true)}var k="ib_identified";function W(){return typeof localStorage=="undefined"?true:!localStorage.getItem(k)}function Z(){typeof localStorage!="undefined"&&localStorage.setItem(k,"1");}function tt(){typeof localStorage!="undefined"&&localStorage.removeItem(k);}var et="data-ib-event",nt="data-ib-";function ot(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){let i=o.getAttribute(et);if(i){let r={auto:true};for(let c of o.attributes)if(c.name.startsWith(nt)&&c.name!==et){let s=c.name.slice(nt.length);r[s]=c.value;}e(i,r);return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}function it(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){if(o.tagName==="A"){let i=o.href;if(!i||!/^https?:\/\//.test(i))return;try{let r=new URL(i);r.hostname!==window.location.hostname&&e("outbound_click",{auto:!0,url:i,hostname:r.hostname});}catch(r){}return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}var rt=class e{constructor(t){this.cleanupHistory=null;this.cleanupAttributes=null;this.cleanupOutbound=null;this.cleanupFormSubmit=null;if(this.config=t,this.queue=new m(t),typeof window!="undefined"&&(j(window.location.search,document.referrer),t.autoDetect!==false)){let n=typeof t.autoDetect=="object"?t.autoDetect:{};n.dataAttributes!==false&&(this.cleanupAttributes=ot((o,i)=>this.track(o,i))),n.outboundClicks!==false&&(this.cleanupOutbound=it((o,i)=>this.track(o,i)));}}static init(t){let n=D(t);return new e(n)}page(t){var o;if(!p(this.config))return;let n=T(t);if(this.queue.push(this.buildEvent("page",{context:n})),this.config.autoDetect!==false){let i=n.page.path,r=typeof this.config.autoDetect=="object"?this.config.autoDetect:{},c={signup:r.signupPaths,login:r.loginPaths,pricing:r.pricingPaths,checkout:r.checkoutPaths,success:r.successPaths,onboarding:r.onboardingPaths,contact:r.contactPaths},s=J(i,c);if(s&&(this.queue.push(this.buildEvent("track",{event:s,properties:{auto:true},context:n})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${s} on ${i}`),r.formSubmit!==false)){(o=this.cleanupFormSubmit)==null||o.call(this);let a=$(s);a&&(this.cleanupFormSubmit=G(a,u=>{this.queue.push(this.buildEvent("track",{event:u,properties:{auto:true}})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${u}`);}));}}}track(t,n){p(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:n}));}identify(t,n){if(p(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:n,userId:t})),this.config.autoDetect!==false)){let o=W(),i=o?"signup":"login";this.queue.push(this.buildEvent("track",{event:i,properties:{auto:true}})),o&&Z(),this.config.debug&&console.log(`[IndieBob] auto-detected: ${i} for ${t}`);}}revenue(t){var n;p(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(n=t.currency)!=null?n:"USD",plan:t.plan,type:t.type}}));}optOut(){var t,n,o;this.queue.flush(),Y(),tt(),this.userId=void 0,(t=this.cleanupAttributes)==null||t.call(this),(n=this.cleanupOutbound)==null||n.call(this),(o=this.cleanupFormSubmit)==null||o.call(this),this.cleanupAttributes=null,this.cleanupOutbound=null,this.cleanupFormSubmit=null,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){H(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return K()}flush(){return l(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return v()}getSessionId(){return I()}getConfig(){return Object.freeze(f({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=z(()=>this.page()),()=>{var n;(n=this.cleanupHistory)==null||n.call(this),this.cleanupHistory=null;}}buildEvent(t,n){var o,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:v(),userId:(o=this.userId)!=null?o:n.userId,sessionId:I(),timestamp:new Date().toISOString(),context:(i=n.context)!=null?i:T(),event:n.event,properties:n.properties,traits:n.traits,revenue:n.revenue}}};
2
- exports.IndieBob=rt;
1
+ 'use strict';var dt=Object.defineProperty,ft=Object.defineProperties;var pt=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var gt=Object.prototype.hasOwnProperty,mt=Object.prototype.propertyIsEnumerable;var F=(e,t,n)=>t in e?dt(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,p=(e,t)=>{for(var n in t||(t={}))gt.call(t,n)&&F(e,n,t[n]);if(D)for(var n of D(t))mt.call(t,n)&&F(e,n,t[n]);return e},N=(e,t)=>ft(e,pt(t));var l=(e,t,n)=>new Promise((o,i)=>{var r=a=>{try{s(n.next(a));}catch(u){i(u);}},c=a=>{try{s(n.throw(a));}catch(u){i(u);}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((n=n.apply(e,t)).next());});var ht="https://www.indiebob.com/api/collect";function U(e){var t,n,o,i,r;if(!e.projectId||!e.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${e.projectId}". Must start with "proj_".`);return {projectId:e.projectId,endpoint:(t=e.endpoint)!=null?t:ht,debug:(n=e.debug)!=null?n:false,respectDnt:(o=e.respectDnt)!=null?o:true,respectGpc:(i=e.respectGpc)!=null?i:true,autoDetect:(r=e.autoDetect)!=null?r:true}}var d="_ib_anon";function y(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let n=new Uint8Array(21);crypto.getRandomValues(n);for(let o of n)t+=e[o%e.length];}else for(let n=0;n<21;n++)t+=e[Math.floor(Math.random()*e.length)];return t}function b(){try{let e=localStorage.getItem(d);return e||(e=y(),localStorage.setItem(d,e)),e}catch(e){try{let t=sessionStorage.getItem(d);return t||(t=y(),sessionStorage.setItem(d,t)),t}catch(t){return y()}}}function L(){try{localStorage.removeItem(d);}catch(e){}try{sessionStorage.removeItem(d);}catch(e){}}var I="_ib_session",S="_ib_session_last";function M(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function E(){var e;try{let t=Date.now(),n=parseInt((e=sessionStorage.getItem(S))!=null?e:"0",10),o=sessionStorage.getItem(I),i=n>0&&t-n>18e5;return (!o||i)&&(o=M(),sessionStorage.setItem(I,o)),sessionStorage.setItem(S,String(t)),o}catch(t){return M()}}function q(){try{sessionStorage.removeItem(I);}catch(e){}try{sessionStorage.removeItem(S);}catch(e){}}var g="_ib_first_utm",j="_ib_last_utm",m="_ib_referrer";function B(e){let t=new URLSearchParams(e),n={},o=false;return t.has("utm_source")?(n.source=t.get("utm_source"),o=true):t.get("ref")&&(n.source=t.get("ref"),o=true),t.has("utm_medium")&&(n.medium=t.get("utm_medium"),o=true),t.has("utm_campaign")&&(n.campaign=t.get("utm_campaign"),o=true),t.has("utm_term")&&(n.term=t.get("utm_term"),o=true),t.has("utm_content")&&(n.content=t.get("utm_content"),o=true),o?n:null}function Y(e,t){let n=B(e);try{n&&!localStorage.getItem(g)&&localStorage.setItem(g,JSON.stringify(n)),n&&localStorage.setItem(j,JSON.stringify(n)),t&&!localStorage.getItem(m)&&localStorage.setItem(m,t);}catch(o){}}function H(){try{let e=localStorage.getItem(g);return e?JSON.parse(e):void 0}catch(e){return}}function K(){var e;try{return (e=localStorage.getItem(m))!=null?e:void 0}catch(t){return}}function V(e){var t;return (t=B(e))!=null?t:void 0}function Q(){try{localStorage.removeItem(g);}catch(e){}try{localStorage.removeItem(j);}catch(e){}try{localStorage.removeItem(m);}catch(e){}}var h="_ib_optout",vt="_ib_queue";function f(e){try{if(localStorage.getItem(h))return !1}catch(t){}return !(e.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||e.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function z(){try{localStorage.setItem(h,"1");}catch(e){}L(),q(),Q();try{localStorage.removeItem(vt);}catch(e){}}function X(){try{localStorage.removeItem(h);}catch(e){}}function J(){try{return !!localStorage.getItem(h)}catch(e){return false}}var yt=[1e3,2e3,4e3];function bt(e){return l(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function _(e,t,n=false){return l(this,null,function*(){let o=JSON.stringify(e);if(n&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([o],{type:"text/plain;charset=UTF-8"}),r=navigator.sendBeacon(t.endpoint,i);return t.debug&&console.log("[IndieBob] sendBeacon:",r,e.batch.length,"events"),r}for(let i=0;i<3;i++){try{let r=yield fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:o,keepalive:!0});if(r.ok)return t.debug&&console.log("[IndieBob] sent:",e.batch.length,"events"),!0;if(r.status>=400&&r.status<500)return t.debug&&console.warn("[IndieBob] 4xx error, not retrying:",r.status),!1}catch(r){t.debug&&console.warn("[IndieBob] fetch error (attempt",i+1,"):",r);}i<2&&(yield bt(yt[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var w="_ib_queue",It=10,St=5e3,Et=50,v=class{constructor(t){this.queue=[];this.timer=null;this.flushing=false;this.config=t,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(t){this.queue.push(t),this.queue.length>=It&&this.flush();}flush(t=false){return l(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let n=this.queue.splice(0);(yield _({batch:n},this.config,t))||this.pushToOfflineQueue(n),this.flushing=false;})}flushOfflineQueue(){return l(this,null,function*(){let t=this.getOfflineQueue();if(t.length===0)return;this.clearOfflineQueue(),yield _({batch:t},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},St);}setupVisibilityFlush(){typeof document!="undefined"&&(document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(true);},{passive:true}),window.addEventListener("pagehide",()=>{this.flush(true);},{passive:true}));}setupOnlineFlush(){typeof window!="undefined"&&(window.addEventListener("online",()=>{this.flushOfflineQueue();}),navigator.onLine&&this.flushOfflineQueue());}pushToOfflineQueue(t){try{let i=[...this.getOfflineQueue(),...t].slice(-Et);localStorage.setItem(w,JSON.stringify(i));}catch(n){}}getOfflineQueue(){try{let t=localStorage.getItem(w);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(w);}catch(t){}}};function $(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function G(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}var _t=/^https?:\/\/[^/]*(stripe\.com|paypal\.com|paddle\.com|lemonsqueezy\.com|gumroad\.com)(\/|$)/i;function T(e){var R,O,x,A,C,P;let t=typeof window=="undefined",n=(R=e==null?void 0:e.path)!=null?R:t?"":window.location.pathname+window.location.search,o=t?"":window.location.href,i=(O=e==null?void 0:e.title)!=null?O:t?"":document.title,r=(x=e==null?void 0:e.referrer)!=null?x:t?"":document.referrer,c=!t&&(r===""||_t.test(r))&&(A=K())!=null?A:r,s=G(),a=$(),u=t?void 0:(C=V(window.location.search))!=null?C:H();return {page:{path:n,url:o,title:i,referrer:c},device:N(p({},s),{type:a}),utm:u,locale:t?"en":navigator.language,timezone:t?"UTC":(P=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?P:"UTC",sdkVersion:"0.2.3"}}function W(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),n=history.replaceState.bind(history);return history.pushState=function(...o){t(...o),e();},history.replaceState=function(...o){n(...o);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=n,window.removeEventListener("popstate",e);}}var wt={signup:[/\/(sign-?up|register|join|create-?account|get-?started|onboard|registro|inscription|s-?inscrire|anmeldung|registrieren|cadastro|registrazione|aanmelden|inschrijven)/i],login:[/\/(log-?in|sign-?in|auth(\/login)?|iniciar-?sesion|connexion|se-?connecter|anmelden|einloggen|entrar|accesso|accedi|inloggen)/i],pricing:[/\/(pricing|plans|upgrade|subscribe|precios|tarifs|preise|precos|prezzi|prijzen)/i],checkout:[/\/(checkout|cart|basket|pay(ment)?|order|comprar|pagar|panier|caisse|warenkorb|kasse|carrinho|carrello|winkelwagen)/i],success:[/\/(success|thank-?you|thanks|confirmation|confirmed|complete[d]?|gracias|merci|danke|obrigado|grazie|bedankt)/i],onboarding:[/\/(onboarding|welcome|getting-?started|setup|bienvenido|bienvenue|willkommen|benvenuto|welkom)/i],contact:[/\/(contact|contacto|kontakt|contato|contatto|nous-?contacter)/i]},Z={signup:"signup_start",login:"login_view",pricing:"pricing_view",checkout:"checkout_view",success:"success_view",onboarding:"onboarding_view",contact:"contact_view"};function Tt(e,t){return e instanceof RegExp?e.test(t):t.includes(e)}function tt(e,t){var n;for(let o of Object.keys(Z))if(((n=t==null?void 0:t[o])!=null?n:wt[o]).some(r=>Tt(r,e)))return Z[o];return null}function et(e){return e==="signup_start"?"signup_submit":e==="login_view"?"login_submit":e==="checkout_view"?"checkout_submit":null}function nt(e,t){if(typeof document=="undefined")return ()=>{};let n=o=>{o.target instanceof HTMLFormElement&&t(e);};return document.addEventListener("submit",n,true),()=>document.removeEventListener("submit",n,true)}var k="ib_identified";function ot(){return typeof localStorage=="undefined"?true:!localStorage.getItem(k)}function it(){typeof localStorage!="undefined"&&localStorage.setItem(k,"1");}function rt(){typeof localStorage!="undefined"&&localStorage.removeItem(k);}var st="data-ib-event",at="data-ib-";function ct(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){let i=o.getAttribute(st);if(i){let r={auto:true};for(let c of o.attributes)if(c.name.startsWith(at)&&c.name!==st){let s=c.name.slice(at.length);r[s]=c.value;}e(i,r);return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}function ut(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){if(o.tagName==="A"){let i=o.href;if(!i||!/^https?:\/\//.test(i))return;try{let r=new URL(i);r.hostname!==window.location.hostname&&e("outbound_click",{auto:!0,url:i,hostname:r.hostname});}catch(r){}return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}var lt=class e{constructor(t){this.cleanupHistory=null;this.cleanupAttributes=null;this.cleanupOutbound=null;this.cleanupFormSubmit=null;if(this.config=t,this.queue=new v(t),typeof window!="undefined"&&(Y(window.location.search,document.referrer),t.autoDetect!==false)){let n=typeof t.autoDetect=="object"?t.autoDetect:{};n.dataAttributes!==false&&(this.cleanupAttributes=ct((o,i)=>this.track(o,i))),n.outboundClicks!==false&&(this.cleanupOutbound=ut((o,i)=>this.track(o,i)));}}static init(t){let n=U(t);return new e(n)}page(t){var o;if(!f(this.config))return;let n=T(t);if(this.queue.push(this.buildEvent("page",{context:n})),this.config.autoDetect!==false){let i=n.page.path,r=typeof this.config.autoDetect=="object"?this.config.autoDetect:{},c={signup:r.signupPaths,login:r.loginPaths,pricing:r.pricingPaths,checkout:r.checkoutPaths,success:r.successPaths,onboarding:r.onboardingPaths,contact:r.contactPaths},s=tt(i,c);if(s&&(this.queue.push(this.buildEvent("track",{event:s,properties:{auto:true},context:n})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${s} on ${i}`),r.formSubmit!==false)){(o=this.cleanupFormSubmit)==null||o.call(this);let a=et(s);a&&(this.cleanupFormSubmit=nt(a,u=>{this.queue.push(this.buildEvent("track",{event:u,properties:{auto:true}})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${u}`);}));}}}track(t,n){f(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:n}));}identify(t,n){if(f(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:n,userId:t})),this.config.autoDetect!==false)){let o=ot(),i=o?"signup":"login";this.queue.push(this.buildEvent("track",{event:i,properties:{auto:true}})),o&&it(),this.config.debug&&console.log(`[IndieBob] auto-detected: ${i} for ${t}`);}}revenue(t){var n;f(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(n=t.currency)!=null?n:"USD",plan:t.plan,type:t.type}}));}optOut(){var t,n,o;this.queue.flush(),z(),rt(),this.userId=void 0,(t=this.cleanupAttributes)==null||t.call(this),(n=this.cleanupOutbound)==null||n.call(this),(o=this.cleanupFormSubmit)==null||o.call(this),this.cleanupAttributes=null,this.cleanupOutbound=null,this.cleanupFormSubmit=null,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){X(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return J()}flush(){return l(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return b()}getSessionId(){return E()}getConfig(){return Object.freeze(p({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=W(()=>this.page()),()=>{var n;(n=this.cleanupHistory)==null||n.call(this),this.cleanupHistory=null;}}buildEvent(t,n){var o,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:b(),userId:(o=this.userId)!=null?o:n.userId,sessionId:E(),timestamp:new Date().toISOString(),context:(i=n.context)!=null?i:T(),event:n.event,properties:n.properties,traits:n.traits,revenue:n.revenue}}};
2
+ exports.IndieBob=lt;
@@ -1,3 +1,3 @@
1
- var IndieBob=(function(exports){'use strict';var st=Object.defineProperty,at=Object.defineProperties;var ct=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var ut=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable;var C=(e,t,n)=>t in e?st(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))ut.call(t,n)&&C(e,n,t[n]);if(A)for(var n of A(t))lt.call(t,n)&&C(e,n,t[n]);return e},P=(e,t)=>at(e,ct(t));var l=(e,t,n)=>new Promise((o,i)=>{var r=a=>{try{s(n.next(a));}catch(u){i(u);}},c=a=>{try{s(n.throw(a));}catch(u){i(u);}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((n=n.apply(e,t)).next());});var dt="https://www.indiebob.com/api/collect";function D(e){var t,n,o,i,r;if(!e.projectId||!e.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${e.projectId}". Must start with "proj_".`);return {projectId:e.projectId,endpoint:(t=e.endpoint)!=null?t:dt,debug:(n=e.debug)!=null?n:false,respectDnt:(o=e.respectDnt)!=null?o:true,respectGpc:(i=e.respectGpc)!=null?i:true,autoDetect:(r=e.autoDetect)!=null?r:true}}var d="_ib_anon";function h(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let n=new Uint8Array(21);crypto.getRandomValues(n);for(let o of n)t+=e[o%e.length];}else for(let n=0;n<21;n++)t+=e[Math.floor(Math.random()*e.length)];return t}function v(){try{let e=localStorage.getItem(d);return e||(e=h(),localStorage.setItem(d,e)),e}catch(e){try{let t=sessionStorage.getItem(d);return t||(t=h(),sessionStorage.setItem(d,t)),t}catch(t){return h()}}}function N(){try{localStorage.removeItem(d);}catch(e){}try{sessionStorage.removeItem(d);}catch(e){}}var y="_ib_session",b="_ib_session_last";function F(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function I(){var e;try{let t=Date.now(),n=parseInt((e=sessionStorage.getItem(b))!=null?e:"0",10),o=sessionStorage.getItem(y),i=n>0&&t-n>18e5;return (!o||i)&&(o=F(),sessionStorage.setItem(y,o)),sessionStorage.setItem(b,String(t)),o}catch(t){return F()}}function L(){try{sessionStorage.removeItem(y);}catch(e){}try{sessionStorage.removeItem(b);}catch(e){}}var E="_ib_first_utm",M="_ib_last_utm",S="_ib_referrer";function U(e){let t=new URLSearchParams(e),n={},o=false;return t.has("utm_source")&&(n.source=t.get("utm_source"),o=true),t.has("utm_medium")&&(n.medium=t.get("utm_medium"),o=true),t.has("utm_campaign")&&(n.campaign=t.get("utm_campaign"),o=true),t.has("utm_term")&&(n.term=t.get("utm_term"),o=true),t.has("utm_content")&&(n.content=t.get("utm_content"),o=true),o?n:null}function j(e,t){let n=U(e);try{n&&!localStorage.getItem(E)&&localStorage.setItem(E,JSON.stringify(n)),n&&localStorage.setItem(M,JSON.stringify(n)),t&&!localStorage.getItem(S)&&localStorage.setItem(S,t);}catch(o){}}function q(e){var t;return (t=U(e))!=null?t:void 0}function B(){try{localStorage.removeItem(E);}catch(e){}try{localStorage.removeItem(M);}catch(e){}try{localStorage.removeItem(S);}catch(e){}}var g="_ib_optout",pt="_ib_queue";function p(e){try{if(localStorage.getItem(g))return !1}catch(t){}return !(e.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||e.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function Y(){try{localStorage.setItem(g,"1");}catch(e){}N(),L(),B();try{localStorage.removeItem(pt);}catch(e){}}function H(){try{localStorage.removeItem(g);}catch(e){}}function K(){try{return !!localStorage.getItem(g)}catch(e){return false}}var ft=[1e3,2e3,4e3];function gt(e){return l(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function _(e,t,n=false){return l(this,null,function*(){let o=JSON.stringify(e);if(n&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([o],{type:"application/json"}),r=navigator.sendBeacon(t.endpoint,i);return t.debug&&console.log("[IndieBob] sendBeacon:",r,e.batch.length,"events"),r}for(let i=0;i<3;i++){try{let r=yield fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:o,keepalive:!0});if(r.ok)return t.debug&&console.log("[IndieBob] sent:",e.batch.length,"events"),!0;if(r.status>=400&&r.status<500)return t.debug&&console.warn("[IndieBob] 4xx error, not retrying:",r.status),!1}catch(r){t.debug&&console.warn("[IndieBob] fetch error (attempt",i+1,"):",r);}i<2&&(yield gt(ft[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var w="_ib_queue",mt=10,ht=5e3,vt=50,m=class{constructor(t){this.queue=[];this.timer=null;this.flushing=false;this.config=t,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(t){this.queue.push(t),this.queue.length>=mt&&this.flush();}flush(t=false){return l(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let n=this.queue.splice(0);(yield _({batch:n},this.config,t))||this.pushToOfflineQueue(n),this.flushing=false;})}flushOfflineQueue(){return l(this,null,function*(){let t=this.getOfflineQueue();if(t.length===0)return;this.clearOfflineQueue(),yield _({batch:t},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},ht);}setupVisibilityFlush(){typeof document!="undefined"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(true);},{passive:true});}setupOnlineFlush(){typeof window!="undefined"&&(window.addEventListener("online",()=>{this.flushOfflineQueue();}),navigator.onLine&&this.flushOfflineQueue());}pushToOfflineQueue(t){try{let i=[...this.getOfflineQueue(),...t].slice(-vt);localStorage.setItem(w,JSON.stringify(i));}catch(n){}}getOfflineQueue(){try{let t=localStorage.getItem(w);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(w);}catch(t){}}};function V(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function Q(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}function T(e){var u,R,O,x;let t=typeof window=="undefined",n=(u=e==null?void 0:e.path)!=null?u:t?"":window.location.pathname+window.location.search,o=t?"":window.location.href,i=(R=e==null?void 0:e.title)!=null?R:t?"":document.title,r=(O=e==null?void 0:e.referrer)!=null?O:t?"":document.referrer,c=Q(),s=V(),a=t?void 0:q(window.location.search);return {page:{path:n,url:o,title:i,referrer:r},device:P(f({},c),{type:s}),utm:a,locale:t?"en":navigator.language,timezone:t?"UTC":(x=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?x:"UTC",sdkVersion:"0.2.1"}}function z(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),n=history.replaceState.bind(history);return history.pushState=function(...o){t(...o),e();},history.replaceState=function(...o){n(...o);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=n,window.removeEventListener("popstate",e);}}var yt={signup:[/\/(sign-?up|register|join|create-?account|get-?started|onboard|registro|inscription|s-?inscrire|anmeldung|registrieren|cadastro|registrazione|aanmelden|inschrijven)/i],login:[/\/(log-?in|sign-?in|auth(\/login)?|iniciar-?sesion|connexion|se-?connecter|anmelden|einloggen|entrar|accesso|accedi|inloggen)/i],pricing:[/\/(pricing|plans|upgrade|subscribe|precios|tarifs|preise|precos|prezzi|prijzen)/i],checkout:[/\/(checkout|cart|basket|pay(ment)?|order|comprar|pagar|panier|caisse|warenkorb|kasse|carrinho|carrello|winkelwagen)/i],success:[/\/(success|thank-?you|thanks|confirmation|confirmed|complete[d]?|gracias|merci|danke|obrigado|grazie|bedankt)/i],onboarding:[/\/(onboarding|welcome|getting-?started|setup|bienvenido|bienvenue|willkommen|benvenuto|welkom)/i],contact:[/\/(contact|contacto|kontakt|contato|contatto|nous-?contacter)/i]},X={signup:"signup_start",login:"login_view",pricing:"pricing_view",checkout:"checkout_view",success:"success_view",onboarding:"onboarding_view",contact:"contact_view"};function bt(e,t){return e instanceof RegExp?e.test(t):t.includes(e)}function J(e,t){var n;for(let o of Object.keys(X))if(((n=t==null?void 0:t[o])!=null?n:yt[o]).some(r=>bt(r,e)))return X[o];return null}function $(e){return e==="signup_start"?"signup_submit":e==="login_view"?"login_submit":e==="checkout_view"?"checkout_submit":null}function G(e,t){if(typeof document=="undefined")return ()=>{};let n=o=>{o.target instanceof HTMLFormElement&&t(e);};return document.addEventListener("submit",n,true),()=>document.removeEventListener("submit",n,true)}var k="ib_identified";function W(){return typeof localStorage=="undefined"?true:!localStorage.getItem(k)}function Z(){typeof localStorage!="undefined"&&localStorage.setItem(k,"1");}function tt(){typeof localStorage!="undefined"&&localStorage.removeItem(k);}var et="data-ib-event",nt="data-ib-";function ot(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){let i=o.getAttribute(et);if(i){let r={auto:true};for(let c of o.attributes)if(c.name.startsWith(nt)&&c.name!==et){let s=c.name.slice(nt.length);r[s]=c.value;}e(i,r);return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}function it(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){if(o.tagName==="A"){let i=o.href;if(!i||!/^https?:\/\//.test(i))return;try{let r=new URL(i);r.hostname!==window.location.hostname&&e("outbound_click",{auto:!0,url:i,hostname:r.hostname});}catch(r){}return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}var rt=class e{constructor(t){this.cleanupHistory=null;this.cleanupAttributes=null;this.cleanupOutbound=null;this.cleanupFormSubmit=null;if(this.config=t,this.queue=new m(t),typeof window!="undefined"&&(j(window.location.search,document.referrer),t.autoDetect!==false)){let n=typeof t.autoDetect=="object"?t.autoDetect:{};n.dataAttributes!==false&&(this.cleanupAttributes=ot((o,i)=>this.track(o,i))),n.outboundClicks!==false&&(this.cleanupOutbound=it((o,i)=>this.track(o,i)));}}static init(t){let n=D(t);return new e(n)}page(t){var o;if(!p(this.config))return;let n=T(t);if(this.queue.push(this.buildEvent("page",{context:n})),this.config.autoDetect!==false){let i=n.page.path,r=typeof this.config.autoDetect=="object"?this.config.autoDetect:{},c={signup:r.signupPaths,login:r.loginPaths,pricing:r.pricingPaths,checkout:r.checkoutPaths,success:r.successPaths,onboarding:r.onboardingPaths,contact:r.contactPaths},s=J(i,c);if(s&&(this.queue.push(this.buildEvent("track",{event:s,properties:{auto:true},context:n})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${s} on ${i}`),r.formSubmit!==false)){(o=this.cleanupFormSubmit)==null||o.call(this);let a=$(s);a&&(this.cleanupFormSubmit=G(a,u=>{this.queue.push(this.buildEvent("track",{event:u,properties:{auto:true}})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${u}`);}));}}}track(t,n){p(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:n}));}identify(t,n){if(p(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:n,userId:t})),this.config.autoDetect!==false)){let o=W(),i=o?"signup":"login";this.queue.push(this.buildEvent("track",{event:i,properties:{auto:true}})),o&&Z(),this.config.debug&&console.log(`[IndieBob] auto-detected: ${i} for ${t}`);}}revenue(t){var n;p(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(n=t.currency)!=null?n:"USD",plan:t.plan,type:t.type}}));}optOut(){var t,n,o;this.queue.flush(),Y(),tt(),this.userId=void 0,(t=this.cleanupAttributes)==null||t.call(this),(n=this.cleanupOutbound)==null||n.call(this),(o=this.cleanupFormSubmit)==null||o.call(this),this.cleanupAttributes=null,this.cleanupOutbound=null,this.cleanupFormSubmit=null,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){H(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return K()}flush(){return l(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return v()}getSessionId(){return I()}getConfig(){return Object.freeze(f({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=z(()=>this.page()),()=>{var n;(n=this.cleanupHistory)==null||n.call(this),this.cleanupHistory=null;}}buildEvent(t,n){var o,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:v(),userId:(o=this.userId)!=null?o:n.userId,sessionId:I(),timestamp:new Date().toISOString(),context:(i=n.context)!=null?i:T(),event:n.event,properties:n.properties,traits:n.traits,revenue:n.revenue}}};
2
- exports.IndieBob=rt;return exports;})({});
1
+ var IndieBob=(function(exports){'use strict';var dt=Object.defineProperty,ft=Object.defineProperties;var pt=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var gt=Object.prototype.hasOwnProperty,mt=Object.prototype.propertyIsEnumerable;var F=(e,t,n)=>t in e?dt(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,p=(e,t)=>{for(var n in t||(t={}))gt.call(t,n)&&F(e,n,t[n]);if(D)for(var n of D(t))mt.call(t,n)&&F(e,n,t[n]);return e},N=(e,t)=>ft(e,pt(t));var l=(e,t,n)=>new Promise((o,i)=>{var r=a=>{try{s(n.next(a));}catch(u){i(u);}},c=a=>{try{s(n.throw(a));}catch(u){i(u);}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((n=n.apply(e,t)).next());});var ht="https://www.indiebob.com/api/collect";function U(e){var t,n,o,i,r;if(!e.projectId||!e.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${e.projectId}". Must start with "proj_".`);return {projectId:e.projectId,endpoint:(t=e.endpoint)!=null?t:ht,debug:(n=e.debug)!=null?n:false,respectDnt:(o=e.respectDnt)!=null?o:true,respectGpc:(i=e.respectGpc)!=null?i:true,autoDetect:(r=e.autoDetect)!=null?r:true}}var d="_ib_anon";function y(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let n=new Uint8Array(21);crypto.getRandomValues(n);for(let o of n)t+=e[o%e.length];}else for(let n=0;n<21;n++)t+=e[Math.floor(Math.random()*e.length)];return t}function b(){try{let e=localStorage.getItem(d);return e||(e=y(),localStorage.setItem(d,e)),e}catch(e){try{let t=sessionStorage.getItem(d);return t||(t=y(),sessionStorage.setItem(d,t)),t}catch(t){return y()}}}function L(){try{localStorage.removeItem(d);}catch(e){}try{sessionStorage.removeItem(d);}catch(e){}}var I="_ib_session",S="_ib_session_last";function M(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function E(){var e;try{let t=Date.now(),n=parseInt((e=sessionStorage.getItem(S))!=null?e:"0",10),o=sessionStorage.getItem(I),i=n>0&&t-n>18e5;return (!o||i)&&(o=M(),sessionStorage.setItem(I,o)),sessionStorage.setItem(S,String(t)),o}catch(t){return M()}}function q(){try{sessionStorage.removeItem(I);}catch(e){}try{sessionStorage.removeItem(S);}catch(e){}}var g="_ib_first_utm",j="_ib_last_utm",m="_ib_referrer";function B(e){let t=new URLSearchParams(e),n={},o=false;return t.has("utm_source")?(n.source=t.get("utm_source"),o=true):t.get("ref")&&(n.source=t.get("ref"),o=true),t.has("utm_medium")&&(n.medium=t.get("utm_medium"),o=true),t.has("utm_campaign")&&(n.campaign=t.get("utm_campaign"),o=true),t.has("utm_term")&&(n.term=t.get("utm_term"),o=true),t.has("utm_content")&&(n.content=t.get("utm_content"),o=true),o?n:null}function Y(e,t){let n=B(e);try{n&&!localStorage.getItem(g)&&localStorage.setItem(g,JSON.stringify(n)),n&&localStorage.setItem(j,JSON.stringify(n)),t&&!localStorage.getItem(m)&&localStorage.setItem(m,t);}catch(o){}}function H(){try{let e=localStorage.getItem(g);return e?JSON.parse(e):void 0}catch(e){return}}function K(){var e;try{return (e=localStorage.getItem(m))!=null?e:void 0}catch(t){return}}function V(e){var t;return (t=B(e))!=null?t:void 0}function Q(){try{localStorage.removeItem(g);}catch(e){}try{localStorage.removeItem(j);}catch(e){}try{localStorage.removeItem(m);}catch(e){}}var h="_ib_optout",vt="_ib_queue";function f(e){try{if(localStorage.getItem(h))return !1}catch(t){}return !(e.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||e.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function z(){try{localStorage.setItem(h,"1");}catch(e){}L(),q(),Q();try{localStorage.removeItem(vt);}catch(e){}}function X(){try{localStorage.removeItem(h);}catch(e){}}function J(){try{return !!localStorage.getItem(h)}catch(e){return false}}var yt=[1e3,2e3,4e3];function bt(e){return l(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function _(e,t,n=false){return l(this,null,function*(){let o=JSON.stringify(e);if(n&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([o],{type:"text/plain;charset=UTF-8"}),r=navigator.sendBeacon(t.endpoint,i);return t.debug&&console.log("[IndieBob] sendBeacon:",r,e.batch.length,"events"),r}for(let i=0;i<3;i++){try{let r=yield fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:o,keepalive:!0});if(r.ok)return t.debug&&console.log("[IndieBob] sent:",e.batch.length,"events"),!0;if(r.status>=400&&r.status<500)return t.debug&&console.warn("[IndieBob] 4xx error, not retrying:",r.status),!1}catch(r){t.debug&&console.warn("[IndieBob] fetch error (attempt",i+1,"):",r);}i<2&&(yield bt(yt[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var w="_ib_queue",It=10,St=5e3,Et=50,v=class{constructor(t){this.queue=[];this.timer=null;this.flushing=false;this.config=t,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(t){this.queue.push(t),this.queue.length>=It&&this.flush();}flush(t=false){return l(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let n=this.queue.splice(0);(yield _({batch:n},this.config,t))||this.pushToOfflineQueue(n),this.flushing=false;})}flushOfflineQueue(){return l(this,null,function*(){let t=this.getOfflineQueue();if(t.length===0)return;this.clearOfflineQueue(),yield _({batch:t},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},St);}setupVisibilityFlush(){typeof document!="undefined"&&(document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(true);},{passive:true}),window.addEventListener("pagehide",()=>{this.flush(true);},{passive:true}));}setupOnlineFlush(){typeof window!="undefined"&&(window.addEventListener("online",()=>{this.flushOfflineQueue();}),navigator.onLine&&this.flushOfflineQueue());}pushToOfflineQueue(t){try{let i=[...this.getOfflineQueue(),...t].slice(-Et);localStorage.setItem(w,JSON.stringify(i));}catch(n){}}getOfflineQueue(){try{let t=localStorage.getItem(w);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(w);}catch(t){}}};function $(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function G(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}var _t=/^https?:\/\/[^/]*(stripe\.com|paypal\.com|paddle\.com|lemonsqueezy\.com|gumroad\.com)(\/|$)/i;function T(e){var R,O,x,A,C,P;let t=typeof window=="undefined",n=(R=e==null?void 0:e.path)!=null?R:t?"":window.location.pathname+window.location.search,o=t?"":window.location.href,i=(O=e==null?void 0:e.title)!=null?O:t?"":document.title,r=(x=e==null?void 0:e.referrer)!=null?x:t?"":document.referrer,c=!t&&(r===""||_t.test(r))&&(A=K())!=null?A:r,s=G(),a=$(),u=t?void 0:(C=V(window.location.search))!=null?C:H();return {page:{path:n,url:o,title:i,referrer:c},device:N(p({},s),{type:a}),utm:u,locale:t?"en":navigator.language,timezone:t?"UTC":(P=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?P:"UTC",sdkVersion:"0.2.3"}}function W(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),n=history.replaceState.bind(history);return history.pushState=function(...o){t(...o),e();},history.replaceState=function(...o){n(...o);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=n,window.removeEventListener("popstate",e);}}var wt={signup:[/\/(sign-?up|register|join|create-?account|get-?started|onboard|registro|inscription|s-?inscrire|anmeldung|registrieren|cadastro|registrazione|aanmelden|inschrijven)/i],login:[/\/(log-?in|sign-?in|auth(\/login)?|iniciar-?sesion|connexion|se-?connecter|anmelden|einloggen|entrar|accesso|accedi|inloggen)/i],pricing:[/\/(pricing|plans|upgrade|subscribe|precios|tarifs|preise|precos|prezzi|prijzen)/i],checkout:[/\/(checkout|cart|basket|pay(ment)?|order|comprar|pagar|panier|caisse|warenkorb|kasse|carrinho|carrello|winkelwagen)/i],success:[/\/(success|thank-?you|thanks|confirmation|confirmed|complete[d]?|gracias|merci|danke|obrigado|grazie|bedankt)/i],onboarding:[/\/(onboarding|welcome|getting-?started|setup|bienvenido|bienvenue|willkommen|benvenuto|welkom)/i],contact:[/\/(contact|contacto|kontakt|contato|contatto|nous-?contacter)/i]},Z={signup:"signup_start",login:"login_view",pricing:"pricing_view",checkout:"checkout_view",success:"success_view",onboarding:"onboarding_view",contact:"contact_view"};function Tt(e,t){return e instanceof RegExp?e.test(t):t.includes(e)}function tt(e,t){var n;for(let o of Object.keys(Z))if(((n=t==null?void 0:t[o])!=null?n:wt[o]).some(r=>Tt(r,e)))return Z[o];return null}function et(e){return e==="signup_start"?"signup_submit":e==="login_view"?"login_submit":e==="checkout_view"?"checkout_submit":null}function nt(e,t){if(typeof document=="undefined")return ()=>{};let n=o=>{o.target instanceof HTMLFormElement&&t(e);};return document.addEventListener("submit",n,true),()=>document.removeEventListener("submit",n,true)}var k="ib_identified";function ot(){return typeof localStorage=="undefined"?true:!localStorage.getItem(k)}function it(){typeof localStorage!="undefined"&&localStorage.setItem(k,"1");}function rt(){typeof localStorage!="undefined"&&localStorage.removeItem(k);}var st="data-ib-event",at="data-ib-";function ct(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){let i=o.getAttribute(st);if(i){let r={auto:true};for(let c of o.attributes)if(c.name.startsWith(at)&&c.name!==st){let s=c.name.slice(at.length);r[s]=c.value;}e(i,r);return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}function ut(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){if(o.tagName==="A"){let i=o.href;if(!i||!/^https?:\/\//.test(i))return;try{let r=new URL(i);r.hostname!==window.location.hostname&&e("outbound_click",{auto:!0,url:i,hostname:r.hostname});}catch(r){}return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}var lt=class e{constructor(t){this.cleanupHistory=null;this.cleanupAttributes=null;this.cleanupOutbound=null;this.cleanupFormSubmit=null;if(this.config=t,this.queue=new v(t),typeof window!="undefined"&&(Y(window.location.search,document.referrer),t.autoDetect!==false)){let n=typeof t.autoDetect=="object"?t.autoDetect:{};n.dataAttributes!==false&&(this.cleanupAttributes=ct((o,i)=>this.track(o,i))),n.outboundClicks!==false&&(this.cleanupOutbound=ut((o,i)=>this.track(o,i)));}}static init(t){let n=U(t);return new e(n)}page(t){var o;if(!f(this.config))return;let n=T(t);if(this.queue.push(this.buildEvent("page",{context:n})),this.config.autoDetect!==false){let i=n.page.path,r=typeof this.config.autoDetect=="object"?this.config.autoDetect:{},c={signup:r.signupPaths,login:r.loginPaths,pricing:r.pricingPaths,checkout:r.checkoutPaths,success:r.successPaths,onboarding:r.onboardingPaths,contact:r.contactPaths},s=tt(i,c);if(s&&(this.queue.push(this.buildEvent("track",{event:s,properties:{auto:true},context:n})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${s} on ${i}`),r.formSubmit!==false)){(o=this.cleanupFormSubmit)==null||o.call(this);let a=et(s);a&&(this.cleanupFormSubmit=nt(a,u=>{this.queue.push(this.buildEvent("track",{event:u,properties:{auto:true}})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${u}`);}));}}}track(t,n){f(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:n}));}identify(t,n){if(f(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:n,userId:t})),this.config.autoDetect!==false)){let o=ot(),i=o?"signup":"login";this.queue.push(this.buildEvent("track",{event:i,properties:{auto:true}})),o&&it(),this.config.debug&&console.log(`[IndieBob] auto-detected: ${i} for ${t}`);}}revenue(t){var n;f(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(n=t.currency)!=null?n:"USD",plan:t.plan,type:t.type}}));}optOut(){var t,n,o;this.queue.flush(),z(),rt(),this.userId=void 0,(t=this.cleanupAttributes)==null||t.call(this),(n=this.cleanupOutbound)==null||n.call(this),(o=this.cleanupFormSubmit)==null||o.call(this),this.cleanupAttributes=null,this.cleanupOutbound=null,this.cleanupFormSubmit=null,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){X(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return J()}flush(){return l(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return b()}getSessionId(){return E()}getConfig(){return Object.freeze(p({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=W(()=>this.page()),()=>{var n;(n=this.cleanupHistory)==null||n.call(this),this.cleanupHistory=null;}}buildEvent(t,n){var o,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:b(),userId:(o=this.userId)!=null?o:n.userId,sessionId:E(),timestamp:new Date().toISOString(),context:(i=n.context)!=null?i:T(),event:n.event,properties:n.properties,traits:n.traits,revenue:n.revenue}}};
2
+ exports.IndieBob=lt;return exports;})({});
3
3
  ;if(typeof IndieBob!=="undefined"&&IndieBob&&IndieBob.IndieBob){IndieBob=Object.assign(IndieBob.IndieBob,IndieBob);}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var st=Object.defineProperty,at=Object.defineProperties;var ct=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var ut=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable;var C=(e,t,n)=>t in e?st(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))ut.call(t,n)&&C(e,n,t[n]);if(A)for(var n of A(t))lt.call(t,n)&&C(e,n,t[n]);return e},P=(e,t)=>at(e,ct(t));var l=(e,t,n)=>new Promise((o,i)=>{var r=a=>{try{s(n.next(a));}catch(u){i(u);}},c=a=>{try{s(n.throw(a));}catch(u){i(u);}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((n=n.apply(e,t)).next());});var dt="https://www.indiebob.com/api/collect";function D(e){var t,n,o,i,r;if(!e.projectId||!e.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${e.projectId}". Must start with "proj_".`);return {projectId:e.projectId,endpoint:(t=e.endpoint)!=null?t:dt,debug:(n=e.debug)!=null?n:false,respectDnt:(o=e.respectDnt)!=null?o:true,respectGpc:(i=e.respectGpc)!=null?i:true,autoDetect:(r=e.autoDetect)!=null?r:true}}var d="_ib_anon";function h(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let n=new Uint8Array(21);crypto.getRandomValues(n);for(let o of n)t+=e[o%e.length];}else for(let n=0;n<21;n++)t+=e[Math.floor(Math.random()*e.length)];return t}function v(){try{let e=localStorage.getItem(d);return e||(e=h(),localStorage.setItem(d,e)),e}catch(e){try{let t=sessionStorage.getItem(d);return t||(t=h(),sessionStorage.setItem(d,t)),t}catch(t){return h()}}}function N(){try{localStorage.removeItem(d);}catch(e){}try{sessionStorage.removeItem(d);}catch(e){}}var y="_ib_session",b="_ib_session_last";function F(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function I(){var e;try{let t=Date.now(),n=parseInt((e=sessionStorage.getItem(b))!=null?e:"0",10),o=sessionStorage.getItem(y),i=n>0&&t-n>18e5;return (!o||i)&&(o=F(),sessionStorage.setItem(y,o)),sessionStorage.setItem(b,String(t)),o}catch(t){return F()}}function L(){try{sessionStorage.removeItem(y);}catch(e){}try{sessionStorage.removeItem(b);}catch(e){}}var E="_ib_first_utm",M="_ib_last_utm",S="_ib_referrer";function U(e){let t=new URLSearchParams(e),n={},o=false;return t.has("utm_source")&&(n.source=t.get("utm_source"),o=true),t.has("utm_medium")&&(n.medium=t.get("utm_medium"),o=true),t.has("utm_campaign")&&(n.campaign=t.get("utm_campaign"),o=true),t.has("utm_term")&&(n.term=t.get("utm_term"),o=true),t.has("utm_content")&&(n.content=t.get("utm_content"),o=true),o?n:null}function j(e,t){let n=U(e);try{n&&!localStorage.getItem(E)&&localStorage.setItem(E,JSON.stringify(n)),n&&localStorage.setItem(M,JSON.stringify(n)),t&&!localStorage.getItem(S)&&localStorage.setItem(S,t);}catch(o){}}function q(e){var t;return (t=U(e))!=null?t:void 0}function B(){try{localStorage.removeItem(E);}catch(e){}try{localStorage.removeItem(M);}catch(e){}try{localStorage.removeItem(S);}catch(e){}}var g="_ib_optout",pt="_ib_queue";function p(e){try{if(localStorage.getItem(g))return !1}catch(t){}return !(e.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||e.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function Y(){try{localStorage.setItem(g,"1");}catch(e){}N(),L(),B();try{localStorage.removeItem(pt);}catch(e){}}function H(){try{localStorage.removeItem(g);}catch(e){}}function K(){try{return !!localStorage.getItem(g)}catch(e){return false}}var ft=[1e3,2e3,4e3];function gt(e){return l(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function _(e,t,n=false){return l(this,null,function*(){let o=JSON.stringify(e);if(n&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([o],{type:"application/json"}),r=navigator.sendBeacon(t.endpoint,i);return t.debug&&console.log("[IndieBob] sendBeacon:",r,e.batch.length,"events"),r}for(let i=0;i<3;i++){try{let r=yield fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:o,keepalive:!0});if(r.ok)return t.debug&&console.log("[IndieBob] sent:",e.batch.length,"events"),!0;if(r.status>=400&&r.status<500)return t.debug&&console.warn("[IndieBob] 4xx error, not retrying:",r.status),!1}catch(r){t.debug&&console.warn("[IndieBob] fetch error (attempt",i+1,"):",r);}i<2&&(yield gt(ft[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var w="_ib_queue",mt=10,ht=5e3,vt=50,m=class{constructor(t){this.queue=[];this.timer=null;this.flushing=false;this.config=t,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(t){this.queue.push(t),this.queue.length>=mt&&this.flush();}flush(t=false){return l(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let n=this.queue.splice(0);(yield _({batch:n},this.config,t))||this.pushToOfflineQueue(n),this.flushing=false;})}flushOfflineQueue(){return l(this,null,function*(){let t=this.getOfflineQueue();if(t.length===0)return;this.clearOfflineQueue(),yield _({batch:t},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},ht);}setupVisibilityFlush(){typeof document!="undefined"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(true);},{passive:true});}setupOnlineFlush(){typeof window!="undefined"&&(window.addEventListener("online",()=>{this.flushOfflineQueue();}),navigator.onLine&&this.flushOfflineQueue());}pushToOfflineQueue(t){try{let i=[...this.getOfflineQueue(),...t].slice(-vt);localStorage.setItem(w,JSON.stringify(i));}catch(n){}}getOfflineQueue(){try{let t=localStorage.getItem(w);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(w);}catch(t){}}};function V(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function Q(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}function T(e){var u,R,O,x;let t=typeof window=="undefined",n=(u=e==null?void 0:e.path)!=null?u:t?"":window.location.pathname+window.location.search,o=t?"":window.location.href,i=(R=e==null?void 0:e.title)!=null?R:t?"":document.title,r=(O=e==null?void 0:e.referrer)!=null?O:t?"":document.referrer,c=Q(),s=V(),a=t?void 0:q(window.location.search);return {page:{path:n,url:o,title:i,referrer:r},device:P(f({},c),{type:s}),utm:a,locale:t?"en":navigator.language,timezone:t?"UTC":(x=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?x:"UTC",sdkVersion:"0.2.1"}}function z(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),n=history.replaceState.bind(history);return history.pushState=function(...o){t(...o),e();},history.replaceState=function(...o){n(...o);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=n,window.removeEventListener("popstate",e);}}var yt={signup:[/\/(sign-?up|register|join|create-?account|get-?started|onboard|registro|inscription|s-?inscrire|anmeldung|registrieren|cadastro|registrazione|aanmelden|inschrijven)/i],login:[/\/(log-?in|sign-?in|auth(\/login)?|iniciar-?sesion|connexion|se-?connecter|anmelden|einloggen|entrar|accesso|accedi|inloggen)/i],pricing:[/\/(pricing|plans|upgrade|subscribe|precios|tarifs|preise|precos|prezzi|prijzen)/i],checkout:[/\/(checkout|cart|basket|pay(ment)?|order|comprar|pagar|panier|caisse|warenkorb|kasse|carrinho|carrello|winkelwagen)/i],success:[/\/(success|thank-?you|thanks|confirmation|confirmed|complete[d]?|gracias|merci|danke|obrigado|grazie|bedankt)/i],onboarding:[/\/(onboarding|welcome|getting-?started|setup|bienvenido|bienvenue|willkommen|benvenuto|welkom)/i],contact:[/\/(contact|contacto|kontakt|contato|contatto|nous-?contacter)/i]},X={signup:"signup_start",login:"login_view",pricing:"pricing_view",checkout:"checkout_view",success:"success_view",onboarding:"onboarding_view",contact:"contact_view"};function bt(e,t){return e instanceof RegExp?e.test(t):t.includes(e)}function J(e,t){var n;for(let o of Object.keys(X))if(((n=t==null?void 0:t[o])!=null?n:yt[o]).some(r=>bt(r,e)))return X[o];return null}function $(e){return e==="signup_start"?"signup_submit":e==="login_view"?"login_submit":e==="checkout_view"?"checkout_submit":null}function G(e,t){if(typeof document=="undefined")return ()=>{};let n=o=>{o.target instanceof HTMLFormElement&&t(e);};return document.addEventListener("submit",n,true),()=>document.removeEventListener("submit",n,true)}var k="ib_identified";function W(){return typeof localStorage=="undefined"?true:!localStorage.getItem(k)}function Z(){typeof localStorage!="undefined"&&localStorage.setItem(k,"1");}function tt(){typeof localStorage!="undefined"&&localStorage.removeItem(k);}var et="data-ib-event",nt="data-ib-";function ot(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){let i=o.getAttribute(et);if(i){let r={auto:true};for(let c of o.attributes)if(c.name.startsWith(nt)&&c.name!==et){let s=c.name.slice(nt.length);r[s]=c.value;}e(i,r);return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}function it(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){if(o.tagName==="A"){let i=o.href;if(!i||!/^https?:\/\//.test(i))return;try{let r=new URL(i);r.hostname!==window.location.hostname&&e("outbound_click",{auto:!0,url:i,hostname:r.hostname});}catch(r){}return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}var rt=class e{constructor(t){this.cleanupHistory=null;this.cleanupAttributes=null;this.cleanupOutbound=null;this.cleanupFormSubmit=null;if(this.config=t,this.queue=new m(t),typeof window!="undefined"&&(j(window.location.search,document.referrer),t.autoDetect!==false)){let n=typeof t.autoDetect=="object"?t.autoDetect:{};n.dataAttributes!==false&&(this.cleanupAttributes=ot((o,i)=>this.track(o,i))),n.outboundClicks!==false&&(this.cleanupOutbound=it((o,i)=>this.track(o,i)));}}static init(t){let n=D(t);return new e(n)}page(t){var o;if(!p(this.config))return;let n=T(t);if(this.queue.push(this.buildEvent("page",{context:n})),this.config.autoDetect!==false){let i=n.page.path,r=typeof this.config.autoDetect=="object"?this.config.autoDetect:{},c={signup:r.signupPaths,login:r.loginPaths,pricing:r.pricingPaths,checkout:r.checkoutPaths,success:r.successPaths,onboarding:r.onboardingPaths,contact:r.contactPaths},s=J(i,c);if(s&&(this.queue.push(this.buildEvent("track",{event:s,properties:{auto:true},context:n})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${s} on ${i}`),r.formSubmit!==false)){(o=this.cleanupFormSubmit)==null||o.call(this);let a=$(s);a&&(this.cleanupFormSubmit=G(a,u=>{this.queue.push(this.buildEvent("track",{event:u,properties:{auto:true}})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${u}`);}));}}}track(t,n){p(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:n}));}identify(t,n){if(p(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:n,userId:t})),this.config.autoDetect!==false)){let o=W(),i=o?"signup":"login";this.queue.push(this.buildEvent("track",{event:i,properties:{auto:true}})),o&&Z(),this.config.debug&&console.log(`[IndieBob] auto-detected: ${i} for ${t}`);}}revenue(t){var n;p(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(n=t.currency)!=null?n:"USD",plan:t.plan,type:t.type}}));}optOut(){var t,n,o;this.queue.flush(),Y(),tt(),this.userId=void 0,(t=this.cleanupAttributes)==null||t.call(this),(n=this.cleanupOutbound)==null||n.call(this),(o=this.cleanupFormSubmit)==null||o.call(this),this.cleanupAttributes=null,this.cleanupOutbound=null,this.cleanupFormSubmit=null,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){H(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return K()}flush(){return l(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return v()}getSessionId(){return I()}getConfig(){return Object.freeze(f({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=z(()=>this.page()),()=>{var n;(n=this.cleanupHistory)==null||n.call(this),this.cleanupHistory=null;}}buildEvent(t,n){var o,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:v(),userId:(o=this.userId)!=null?o:n.userId,sessionId:I(),timestamp:new Date().toISOString(),context:(i=n.context)!=null?i:T(),event:n.event,properties:n.properties,traits:n.traits,revenue:n.revenue}}};
2
- export{rt as IndieBob};
1
+ var dt=Object.defineProperty,ft=Object.defineProperties;var pt=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var gt=Object.prototype.hasOwnProperty,mt=Object.prototype.propertyIsEnumerable;var F=(e,t,n)=>t in e?dt(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,p=(e,t)=>{for(var n in t||(t={}))gt.call(t,n)&&F(e,n,t[n]);if(D)for(var n of D(t))mt.call(t,n)&&F(e,n,t[n]);return e},N=(e,t)=>ft(e,pt(t));var l=(e,t,n)=>new Promise((o,i)=>{var r=a=>{try{s(n.next(a));}catch(u){i(u);}},c=a=>{try{s(n.throw(a));}catch(u){i(u);}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((n=n.apply(e,t)).next());});var ht="https://www.indiebob.com/api/collect";function U(e){var t,n,o,i,r;if(!e.projectId||!e.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${e.projectId}". Must start with "proj_".`);return {projectId:e.projectId,endpoint:(t=e.endpoint)!=null?t:ht,debug:(n=e.debug)!=null?n:false,respectDnt:(o=e.respectDnt)!=null?o:true,respectGpc:(i=e.respectGpc)!=null?i:true,autoDetect:(r=e.autoDetect)!=null?r:true}}var d="_ib_anon";function y(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let n=new Uint8Array(21);crypto.getRandomValues(n);for(let o of n)t+=e[o%e.length];}else for(let n=0;n<21;n++)t+=e[Math.floor(Math.random()*e.length)];return t}function b(){try{let e=localStorage.getItem(d);return e||(e=y(),localStorage.setItem(d,e)),e}catch(e){try{let t=sessionStorage.getItem(d);return t||(t=y(),sessionStorage.setItem(d,t)),t}catch(t){return y()}}}function L(){try{localStorage.removeItem(d);}catch(e){}try{sessionStorage.removeItem(d);}catch(e){}}var I="_ib_session",S="_ib_session_last";function M(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function E(){var e;try{let t=Date.now(),n=parseInt((e=sessionStorage.getItem(S))!=null?e:"0",10),o=sessionStorage.getItem(I),i=n>0&&t-n>18e5;return (!o||i)&&(o=M(),sessionStorage.setItem(I,o)),sessionStorage.setItem(S,String(t)),o}catch(t){return M()}}function q(){try{sessionStorage.removeItem(I);}catch(e){}try{sessionStorage.removeItem(S);}catch(e){}}var g="_ib_first_utm",j="_ib_last_utm",m="_ib_referrer";function B(e){let t=new URLSearchParams(e),n={},o=false;return t.has("utm_source")?(n.source=t.get("utm_source"),o=true):t.get("ref")&&(n.source=t.get("ref"),o=true),t.has("utm_medium")&&(n.medium=t.get("utm_medium"),o=true),t.has("utm_campaign")&&(n.campaign=t.get("utm_campaign"),o=true),t.has("utm_term")&&(n.term=t.get("utm_term"),o=true),t.has("utm_content")&&(n.content=t.get("utm_content"),o=true),o?n:null}function Y(e,t){let n=B(e);try{n&&!localStorage.getItem(g)&&localStorage.setItem(g,JSON.stringify(n)),n&&localStorage.setItem(j,JSON.stringify(n)),t&&!localStorage.getItem(m)&&localStorage.setItem(m,t);}catch(o){}}function H(){try{let e=localStorage.getItem(g);return e?JSON.parse(e):void 0}catch(e){return}}function K(){var e;try{return (e=localStorage.getItem(m))!=null?e:void 0}catch(t){return}}function V(e){var t;return (t=B(e))!=null?t:void 0}function Q(){try{localStorage.removeItem(g);}catch(e){}try{localStorage.removeItem(j);}catch(e){}try{localStorage.removeItem(m);}catch(e){}}var h="_ib_optout",vt="_ib_queue";function f(e){try{if(localStorage.getItem(h))return !1}catch(t){}return !(e.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||e.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function z(){try{localStorage.setItem(h,"1");}catch(e){}L(),q(),Q();try{localStorage.removeItem(vt);}catch(e){}}function X(){try{localStorage.removeItem(h);}catch(e){}}function J(){try{return !!localStorage.getItem(h)}catch(e){return false}}var yt=[1e3,2e3,4e3];function bt(e){return l(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function _(e,t,n=false){return l(this,null,function*(){let o=JSON.stringify(e);if(n&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([o],{type:"text/plain;charset=UTF-8"}),r=navigator.sendBeacon(t.endpoint,i);return t.debug&&console.log("[IndieBob] sendBeacon:",r,e.batch.length,"events"),r}for(let i=0;i<3;i++){try{let r=yield fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:o,keepalive:!0});if(r.ok)return t.debug&&console.log("[IndieBob] sent:",e.batch.length,"events"),!0;if(r.status>=400&&r.status<500)return t.debug&&console.warn("[IndieBob] 4xx error, not retrying:",r.status),!1}catch(r){t.debug&&console.warn("[IndieBob] fetch error (attempt",i+1,"):",r);}i<2&&(yield bt(yt[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var w="_ib_queue",It=10,St=5e3,Et=50,v=class{constructor(t){this.queue=[];this.timer=null;this.flushing=false;this.config=t,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(t){this.queue.push(t),this.queue.length>=It&&this.flush();}flush(t=false){return l(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let n=this.queue.splice(0);(yield _({batch:n},this.config,t))||this.pushToOfflineQueue(n),this.flushing=false;})}flushOfflineQueue(){return l(this,null,function*(){let t=this.getOfflineQueue();if(t.length===0)return;this.clearOfflineQueue(),yield _({batch:t},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},St);}setupVisibilityFlush(){typeof document!="undefined"&&(document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(true);},{passive:true}),window.addEventListener("pagehide",()=>{this.flush(true);},{passive:true}));}setupOnlineFlush(){typeof window!="undefined"&&(window.addEventListener("online",()=>{this.flushOfflineQueue();}),navigator.onLine&&this.flushOfflineQueue());}pushToOfflineQueue(t){try{let i=[...this.getOfflineQueue(),...t].slice(-Et);localStorage.setItem(w,JSON.stringify(i));}catch(n){}}getOfflineQueue(){try{let t=localStorage.getItem(w);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(w);}catch(t){}}};function $(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function G(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}var _t=/^https?:\/\/[^/]*(stripe\.com|paypal\.com|paddle\.com|lemonsqueezy\.com|gumroad\.com)(\/|$)/i;function T(e){var R,O,x,A,C,P;let t=typeof window=="undefined",n=(R=e==null?void 0:e.path)!=null?R:t?"":window.location.pathname+window.location.search,o=t?"":window.location.href,i=(O=e==null?void 0:e.title)!=null?O:t?"":document.title,r=(x=e==null?void 0:e.referrer)!=null?x:t?"":document.referrer,c=!t&&(r===""||_t.test(r))&&(A=K())!=null?A:r,s=G(),a=$(),u=t?void 0:(C=V(window.location.search))!=null?C:H();return {page:{path:n,url:o,title:i,referrer:c},device:N(p({},s),{type:a}),utm:u,locale:t?"en":navigator.language,timezone:t?"UTC":(P=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?P:"UTC",sdkVersion:"0.2.3"}}function W(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),n=history.replaceState.bind(history);return history.pushState=function(...o){t(...o),e();},history.replaceState=function(...o){n(...o);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=n,window.removeEventListener("popstate",e);}}var wt={signup:[/\/(sign-?up|register|join|create-?account|get-?started|onboard|registro|inscription|s-?inscrire|anmeldung|registrieren|cadastro|registrazione|aanmelden|inschrijven)/i],login:[/\/(log-?in|sign-?in|auth(\/login)?|iniciar-?sesion|connexion|se-?connecter|anmelden|einloggen|entrar|accesso|accedi|inloggen)/i],pricing:[/\/(pricing|plans|upgrade|subscribe|precios|tarifs|preise|precos|prezzi|prijzen)/i],checkout:[/\/(checkout|cart|basket|pay(ment)?|order|comprar|pagar|panier|caisse|warenkorb|kasse|carrinho|carrello|winkelwagen)/i],success:[/\/(success|thank-?you|thanks|confirmation|confirmed|complete[d]?|gracias|merci|danke|obrigado|grazie|bedankt)/i],onboarding:[/\/(onboarding|welcome|getting-?started|setup|bienvenido|bienvenue|willkommen|benvenuto|welkom)/i],contact:[/\/(contact|contacto|kontakt|contato|contatto|nous-?contacter)/i]},Z={signup:"signup_start",login:"login_view",pricing:"pricing_view",checkout:"checkout_view",success:"success_view",onboarding:"onboarding_view",contact:"contact_view"};function Tt(e,t){return e instanceof RegExp?e.test(t):t.includes(e)}function tt(e,t){var n;for(let o of Object.keys(Z))if(((n=t==null?void 0:t[o])!=null?n:wt[o]).some(r=>Tt(r,e)))return Z[o];return null}function et(e){return e==="signup_start"?"signup_submit":e==="login_view"?"login_submit":e==="checkout_view"?"checkout_submit":null}function nt(e,t){if(typeof document=="undefined")return ()=>{};let n=o=>{o.target instanceof HTMLFormElement&&t(e);};return document.addEventListener("submit",n,true),()=>document.removeEventListener("submit",n,true)}var k="ib_identified";function ot(){return typeof localStorage=="undefined"?true:!localStorage.getItem(k)}function it(){typeof localStorage!="undefined"&&localStorage.setItem(k,"1");}function rt(){typeof localStorage!="undefined"&&localStorage.removeItem(k);}var st="data-ib-event",at="data-ib-";function ct(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){let i=o.getAttribute(st);if(i){let r={auto:true};for(let c of o.attributes)if(c.name.startsWith(at)&&c.name!==st){let s=c.name.slice(at.length);r[s]=c.value;}e(i,r);return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}function ut(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){if(o.tagName==="A"){let i=o.href;if(!i||!/^https?:\/\//.test(i))return;try{let r=new URL(i);r.hostname!==window.location.hostname&&e("outbound_click",{auto:!0,url:i,hostname:r.hostname});}catch(r){}return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}var lt=class e{constructor(t){this.cleanupHistory=null;this.cleanupAttributes=null;this.cleanupOutbound=null;this.cleanupFormSubmit=null;if(this.config=t,this.queue=new v(t),typeof window!="undefined"&&(Y(window.location.search,document.referrer),t.autoDetect!==false)){let n=typeof t.autoDetect=="object"?t.autoDetect:{};n.dataAttributes!==false&&(this.cleanupAttributes=ct((o,i)=>this.track(o,i))),n.outboundClicks!==false&&(this.cleanupOutbound=ut((o,i)=>this.track(o,i)));}}static init(t){let n=U(t);return new e(n)}page(t){var o;if(!f(this.config))return;let n=T(t);if(this.queue.push(this.buildEvent("page",{context:n})),this.config.autoDetect!==false){let i=n.page.path,r=typeof this.config.autoDetect=="object"?this.config.autoDetect:{},c={signup:r.signupPaths,login:r.loginPaths,pricing:r.pricingPaths,checkout:r.checkoutPaths,success:r.successPaths,onboarding:r.onboardingPaths,contact:r.contactPaths},s=tt(i,c);if(s&&(this.queue.push(this.buildEvent("track",{event:s,properties:{auto:true},context:n})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${s} on ${i}`),r.formSubmit!==false)){(o=this.cleanupFormSubmit)==null||o.call(this);let a=et(s);a&&(this.cleanupFormSubmit=nt(a,u=>{this.queue.push(this.buildEvent("track",{event:u,properties:{auto:true}})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${u}`);}));}}}track(t,n){f(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:n}));}identify(t,n){if(f(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:n,userId:t})),this.config.autoDetect!==false)){let o=ot(),i=o?"signup":"login";this.queue.push(this.buildEvent("track",{event:i,properties:{auto:true}})),o&&it(),this.config.debug&&console.log(`[IndieBob] auto-detected: ${i} for ${t}`);}}revenue(t){var n;f(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(n=t.currency)!=null?n:"USD",plan:t.plan,type:t.type}}));}optOut(){var t,n,o;this.queue.flush(),z(),rt(),this.userId=void 0,(t=this.cleanupAttributes)==null||t.call(this),(n=this.cleanupOutbound)==null||n.call(this),(o=this.cleanupFormSubmit)==null||o.call(this),this.cleanupAttributes=null,this.cleanupOutbound=null,this.cleanupFormSubmit=null,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){X(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return J()}flush(){return l(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return b()}getSessionId(){return E()}getConfig(){return Object.freeze(p({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=W(()=>this.page()),()=>{var n;(n=this.cleanupHistory)==null||n.call(this),this.cleanupHistory=null;}}buildEvent(t,n){var o,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:b(),userId:(o=this.userId)!=null?o:n.userId,sessionId:E(),timestamp:new Date().toISOString(),context:(i=n.context)!=null?i:T(),event:n.event,properties:n.properties,traits:n.traits,revenue:n.revenue}}};
2
+ export{lt as IndieBob};
package/dist/server.js CHANGED
@@ -80,7 +80,7 @@ var IndieBobServer = class _IndieBobServer {
80
80
  device: { width: 0, height: 0, type: "desktop" },
81
81
  locale: "en",
82
82
  timezone: "UTC",
83
- sdkVersion: "0.2.1"
83
+ sdkVersion: "0.2.3"
84
84
  },
85
85
  event: extras.event,
86
86
  properties: extras.properties,
package/dist/server.mjs CHANGED
@@ -78,7 +78,7 @@ var IndieBobServer = class _IndieBobServer {
78
78
  device: { width: 0, height: 0, type: "desktop" },
79
79
  locale: "en",
80
80
  timezone: "UTC",
81
- sdkVersion: "0.2.1"
81
+ sdkVersion: "0.2.3"
82
82
  },
83
83
  event: extras.event,
84
84
  properties: extras.properties,
package/dist/vue.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var at=Object.defineProperty,ct=Object.defineProperties;var ut=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var lt=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var D=(e,t,n)=>t in e?at(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&D(e,n,t[n]);if(P)for(var n of P(t))dt.call(t,n)&&D(e,n,t[n]);return e},N=(e,t)=>ct(e,ut(t));var l=(e,t,n)=>new Promise((o,i)=>{var r=a=>{try{s(n.next(a));}catch(u){i(u);}},c=a=>{try{s(n.throw(a));}catch(u){i(u);}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((n=n.apply(e,t)).next());});var pt="https://www.indiebob.com/api/collect";function F(e){var t,n,o,i,r;if(!e.projectId||!e.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${e.projectId}". Must start with "proj_".`);return {projectId:e.projectId,endpoint:(t=e.endpoint)!=null?t:pt,debug:(n=e.debug)!=null?n:false,respectDnt:(o=e.respectDnt)!=null?o:true,respectGpc:(i=e.respectGpc)!=null?i:true,autoDetect:(r=e.autoDetect)!=null?r:true}}var d="_ib_anon";function v(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let n=new Uint8Array(21);crypto.getRandomValues(n);for(let o of n)t+=e[o%e.length];}else for(let n=0;n<21;n++)t+=e[Math.floor(Math.random()*e.length)];return t}function y(){try{let e=localStorage.getItem(d);return e||(e=v(),localStorage.setItem(d,e)),e}catch(e){try{let t=sessionStorage.getItem(d);return t||(t=v(),sessionStorage.setItem(d,t)),t}catch(t){return v()}}}function L(){try{localStorage.removeItem(d);}catch(e){}try{sessionStorage.removeItem(d);}catch(e){}}var b="_ib_session",I="_ib_session_last";function B(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function E(){var e;try{let t=Date.now(),n=parseInt((e=sessionStorage.getItem(I))!=null?e:"0",10),o=sessionStorage.getItem(b),i=n>0&&t-n>18e5;return (!o||i)&&(o=B(),sessionStorage.setItem(b,o)),sessionStorage.setItem(I,String(t)),o}catch(t){return B()}}function M(){try{sessionStorage.removeItem(b);}catch(e){}try{sessionStorage.removeItem(I);}catch(e){}}var S="_ib_first_utm",U="_ib_last_utm",_="_ib_referrer";function j(e){let t=new URLSearchParams(e),n={},o=false;return t.has("utm_source")&&(n.source=t.get("utm_source"),o=true),t.has("utm_medium")&&(n.medium=t.get("utm_medium"),o=true),t.has("utm_campaign")&&(n.campaign=t.get("utm_campaign"),o=true),t.has("utm_term")&&(n.term=t.get("utm_term"),o=true),t.has("utm_content")&&(n.content=t.get("utm_content"),o=true),o?n:null}function q(e,t){let n=j(e);try{n&&!localStorage.getItem(S)&&localStorage.setItem(S,JSON.stringify(n)),n&&localStorage.setItem(U,JSON.stringify(n)),t&&!localStorage.getItem(_)&&localStorage.setItem(_,t);}catch(o){}}function Y(e){var t;return (t=j(e))!=null?t:void 0}function H(){try{localStorage.removeItem(S);}catch(e){}try{localStorage.removeItem(U);}catch(e){}try{localStorage.removeItem(_);}catch(e){}}var g="_ib_optout",ft="_ib_queue";function p(e){try{if(localStorage.getItem(g))return !1}catch(t){}return !(e.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||e.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function K(){try{localStorage.setItem(g,"1");}catch(e){}L(),M(),H();try{localStorage.removeItem(ft);}catch(e){}}function V(){try{localStorage.removeItem(g);}catch(e){}}function Q(){try{return !!localStorage.getItem(g)}catch(e){return false}}var gt=[1e3,2e3,4e3];function mt(e){return l(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function w(e,t,n=false){return l(this,null,function*(){let o=JSON.stringify(e);if(n&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([o],{type:"application/json"}),r=navigator.sendBeacon(t.endpoint,i);return t.debug&&console.log("[IndieBob] sendBeacon:",r,e.batch.length,"events"),r}for(let i=0;i<3;i++){try{let r=yield fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:o,keepalive:!0});if(r.ok)return t.debug&&console.log("[IndieBob] sent:",e.batch.length,"events"),!0;if(r.status>=400&&r.status<500)return t.debug&&console.warn("[IndieBob] 4xx error, not retrying:",r.status),!1}catch(r){t.debug&&console.warn("[IndieBob] fetch error (attempt",i+1,"):",r);}i<2&&(yield mt(gt[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var T="_ib_queue",ht=10,vt=5e3,yt=50,m=class{constructor(t){this.queue=[];this.timer=null;this.flushing=false;this.config=t,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(t){this.queue.push(t),this.queue.length>=ht&&this.flush();}flush(t=false){return l(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let n=this.queue.splice(0);(yield w({batch:n},this.config,t))||this.pushToOfflineQueue(n),this.flushing=false;})}flushOfflineQueue(){return l(this,null,function*(){let t=this.getOfflineQueue();if(t.length===0)return;this.clearOfflineQueue(),yield w({batch:t},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},vt);}setupVisibilityFlush(){typeof document!="undefined"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(true);},{passive:true});}setupOnlineFlush(){typeof window!="undefined"&&(window.addEventListener("online",()=>{this.flushOfflineQueue();}),navigator.onLine&&this.flushOfflineQueue());}pushToOfflineQueue(t){try{let i=[...this.getOfflineQueue(),...t].slice(-yt);localStorage.setItem(T,JSON.stringify(i));}catch(n){}}getOfflineQueue(){try{let t=localStorage.getItem(T);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(T);}catch(t){}}};function z(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function X(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}function k(e){var u,x,A,C;let t=typeof window=="undefined",n=(u=e==null?void 0:e.path)!=null?u:t?"":window.location.pathname+window.location.search,o=t?"":window.location.href,i=(x=e==null?void 0:e.title)!=null?x:t?"":document.title,r=(A=e==null?void 0:e.referrer)!=null?A:t?"":document.referrer,c=X(),s=z(),a=t?void 0:Y(window.location.search);return {page:{path:n,url:o,title:i,referrer:r},device:N(f({},c),{type:s}),utm:a,locale:t?"en":navigator.language,timezone:t?"UTC":(C=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?C:"UTC",sdkVersion:"0.2.1"}}function $(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),n=history.replaceState.bind(history);return history.pushState=function(...o){t(...o),e();},history.replaceState=function(...o){n(...o);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=n,window.removeEventListener("popstate",e);}}var bt={signup:[/\/(sign-?up|register|join|create-?account|get-?started|onboard|registro|inscription|s-?inscrire|anmeldung|registrieren|cadastro|registrazione|aanmelden|inschrijven)/i],login:[/\/(log-?in|sign-?in|auth(\/login)?|iniciar-?sesion|connexion|se-?connecter|anmelden|einloggen|entrar|accesso|accedi|inloggen)/i],pricing:[/\/(pricing|plans|upgrade|subscribe|precios|tarifs|preise|precos|prezzi|prijzen)/i],checkout:[/\/(checkout|cart|basket|pay(ment)?|order|comprar|pagar|panier|caisse|warenkorb|kasse|carrinho|carrello|winkelwagen)/i],success:[/\/(success|thank-?you|thanks|confirmation|confirmed|complete[d]?|gracias|merci|danke|obrigado|grazie|bedankt)/i],onboarding:[/\/(onboarding|welcome|getting-?started|setup|bienvenido|bienvenue|willkommen|benvenuto|welkom)/i],contact:[/\/(contact|contacto|kontakt|contato|contatto|nous-?contacter)/i]},J={signup:"signup_start",login:"login_view",pricing:"pricing_view",checkout:"checkout_view",success:"success_view",onboarding:"onboarding_view",contact:"contact_view"};function It(e,t){return e instanceof RegExp?e.test(t):t.includes(e)}function G(e,t){var n;for(let o of Object.keys(J))if(((n=t==null?void 0:t[o])!=null?n:bt[o]).some(r=>It(r,e)))return J[o];return null}function W(e){return e==="signup_start"?"signup_submit":e==="login_view"?"login_submit":e==="checkout_view"?"checkout_submit":null}function Z(e,t){if(typeof document=="undefined")return ()=>{};let n=o=>{o.target instanceof HTMLFormElement&&t(e);};return document.addEventListener("submit",n,true),()=>document.removeEventListener("submit",n,true)}var R="ib_identified";function tt(){return typeof localStorage=="undefined"?true:!localStorage.getItem(R)}function et(){typeof localStorage!="undefined"&&localStorage.setItem(R,"1");}function nt(){typeof localStorage!="undefined"&&localStorage.removeItem(R);}var ot="data-ib-event",it="data-ib-";function rt(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){let i=o.getAttribute(ot);if(i){let r={auto:true};for(let c of o.attributes)if(c.name.startsWith(it)&&c.name!==ot){let s=c.name.slice(it.length);r[s]=c.value;}e(i,r);return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}function st(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){if(o.tagName==="A"){let i=o.href;if(!i||!/^https?:\/\//.test(i))return;try{let r=new URL(i);r.hostname!==window.location.hostname&&e("outbound_click",{auto:!0,url:i,hostname:r.hostname});}catch(r){}return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}var h=class e{constructor(t){this.cleanupHistory=null;this.cleanupAttributes=null;this.cleanupOutbound=null;this.cleanupFormSubmit=null;if(this.config=t,this.queue=new m(t),typeof window!="undefined"&&(q(window.location.search,document.referrer),t.autoDetect!==false)){let n=typeof t.autoDetect=="object"?t.autoDetect:{};n.dataAttributes!==false&&(this.cleanupAttributes=rt((o,i)=>this.track(o,i))),n.outboundClicks!==false&&(this.cleanupOutbound=st((o,i)=>this.track(o,i)));}}static init(t){let n=F(t);return new e(n)}page(t){var o;if(!p(this.config))return;let n=k(t);if(this.queue.push(this.buildEvent("page",{context:n})),this.config.autoDetect!==false){let i=n.page.path,r=typeof this.config.autoDetect=="object"?this.config.autoDetect:{},c={signup:r.signupPaths,login:r.loginPaths,pricing:r.pricingPaths,checkout:r.checkoutPaths,success:r.successPaths,onboarding:r.onboardingPaths,contact:r.contactPaths},s=G(i,c);if(s&&(this.queue.push(this.buildEvent("track",{event:s,properties:{auto:true},context:n})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${s} on ${i}`),r.formSubmit!==false)){(o=this.cleanupFormSubmit)==null||o.call(this);let a=W(s);a&&(this.cleanupFormSubmit=Z(a,u=>{this.queue.push(this.buildEvent("track",{event:u,properties:{auto:true}})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${u}`);}));}}}track(t,n){p(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:n}));}identify(t,n){if(p(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:n,userId:t})),this.config.autoDetect!==false)){let o=tt(),i=o?"signup":"login";this.queue.push(this.buildEvent("track",{event:i,properties:{auto:true}})),o&&et(),this.config.debug&&console.log(`[IndieBob] auto-detected: ${i} for ${t}`);}}revenue(t){var n;p(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(n=t.currency)!=null?n:"USD",plan:t.plan,type:t.type}}));}optOut(){var t,n,o;this.queue.flush(),K(),nt(),this.userId=void 0,(t=this.cleanupAttributes)==null||t.call(this),(n=this.cleanupOutbound)==null||n.call(this),(o=this.cleanupFormSubmit)==null||o.call(this),this.cleanupAttributes=null,this.cleanupOutbound=null,this.cleanupFormSubmit=null,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){V(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return Q()}flush(){return l(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return y()}getSessionId(){return E()}getConfig(){return Object.freeze(f({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=$(()=>this.page()),()=>{var n;(n=this.cleanupHistory)==null||n.call(this),this.cleanupHistory=null;}}buildEvent(t,n){var o,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:y(),userId:(o=this.userId)!=null?o:n.userId,sessionId:E(),timestamp:new Date().toISOString(),context:(i=n.context)!=null?i:k(),event:n.event,properties:n.properties,traits:n.traits,revenue:n.revenue}}};var Et=Symbol("indiebob"),O=null,re={install(e,t){let n=h.init(t);O=n,e.provide(Et,n),e.config.globalProperties.$bob=n;let o=e.config.globalProperties.$router;o&&o.afterEach(()=>{n.page();});}};function se(){if(O)return O;throw new Error("[IndieBob] useTracker() called before IndieBobPlugin was installed.")}
2
- exports.IndieBob=h;exports.IndieBobPlugin=re;exports.useTracker=se;
1
+ 'use strict';var ft=Object.defineProperty,pt=Object.defineProperties;var gt=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var mt=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable;var U=(e,t,n)=>t in e?ft(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,p=(e,t)=>{for(var n in t||(t={}))mt.call(t,n)&&U(e,n,t[n]);if(F)for(var n of F(t))ht.call(t,n)&&U(e,n,t[n]);return e},L=(e,t)=>pt(e,gt(t));var l=(e,t,n)=>new Promise((o,i)=>{var r=a=>{try{s(n.next(a));}catch(u){i(u);}},c=a=>{try{s(n.throw(a));}catch(u){i(u);}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((n=n.apply(e,t)).next());});var vt="https://www.indiebob.com/api/collect";function M(e){var t,n,o,i,r;if(!e.projectId||!e.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${e.projectId}". Must start with "proj_".`);return {projectId:e.projectId,endpoint:(t=e.endpoint)!=null?t:vt,debug:(n=e.debug)!=null?n:false,respectDnt:(o=e.respectDnt)!=null?o:true,respectGpc:(i=e.respectGpc)!=null?i:true,autoDetect:(r=e.autoDetect)!=null?r:true}}var d="_ib_anon";function b(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let n=new Uint8Array(21);crypto.getRandomValues(n);for(let o of n)t+=e[o%e.length];}else for(let n=0;n<21;n++)t+=e[Math.floor(Math.random()*e.length)];return t}function I(){try{let e=localStorage.getItem(d);return e||(e=b(),localStorage.setItem(d,e)),e}catch(e){try{let t=sessionStorage.getItem(d);return t||(t=b(),sessionStorage.setItem(d,t)),t}catch(t){return b()}}}function B(){try{localStorage.removeItem(d);}catch(e){}try{sessionStorage.removeItem(d);}catch(e){}}var S="_ib_session",E="_ib_session_last";function q(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function _(){var e;try{let t=Date.now(),n=parseInt((e=sessionStorage.getItem(E))!=null?e:"0",10),o=sessionStorage.getItem(S),i=n>0&&t-n>18e5;return (!o||i)&&(o=q(),sessionStorage.setItem(S,o)),sessionStorage.setItem(E,String(t)),o}catch(t){return q()}}function j(){try{sessionStorage.removeItem(S);}catch(e){}try{sessionStorage.removeItem(E);}catch(e){}}var g="_ib_first_utm",Y="_ib_last_utm",m="_ib_referrer";function H(e){let t=new URLSearchParams(e),n={},o=false;return t.has("utm_source")?(n.source=t.get("utm_source"),o=true):t.get("ref")&&(n.source=t.get("ref"),o=true),t.has("utm_medium")&&(n.medium=t.get("utm_medium"),o=true),t.has("utm_campaign")&&(n.campaign=t.get("utm_campaign"),o=true),t.has("utm_term")&&(n.term=t.get("utm_term"),o=true),t.has("utm_content")&&(n.content=t.get("utm_content"),o=true),o?n:null}function K(e,t){let n=H(e);try{n&&!localStorage.getItem(g)&&localStorage.setItem(g,JSON.stringify(n)),n&&localStorage.setItem(Y,JSON.stringify(n)),t&&!localStorage.getItem(m)&&localStorage.setItem(m,t);}catch(o){}}function V(){try{let e=localStorage.getItem(g);return e?JSON.parse(e):void 0}catch(e){return}}function Q(){var e;try{return (e=localStorage.getItem(m))!=null?e:void 0}catch(t){return}}function z(e){var t;return (t=H(e))!=null?t:void 0}function X(){try{localStorage.removeItem(g);}catch(e){}try{localStorage.removeItem(Y);}catch(e){}try{localStorage.removeItem(m);}catch(e){}}var h="_ib_optout",yt="_ib_queue";function f(e){try{if(localStorage.getItem(h))return !1}catch(t){}return !(e.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||e.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function $(){try{localStorage.setItem(h,"1");}catch(e){}B(),j(),X();try{localStorage.removeItem(yt);}catch(e){}}function J(){try{localStorage.removeItem(h);}catch(e){}}function G(){try{return !!localStorage.getItem(h)}catch(e){return false}}var bt=[1e3,2e3,4e3];function It(e){return l(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function w(e,t,n=false){return l(this,null,function*(){let o=JSON.stringify(e);if(n&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([o],{type:"text/plain;charset=UTF-8"}),r=navigator.sendBeacon(t.endpoint,i);return t.debug&&console.log("[IndieBob] sendBeacon:",r,e.batch.length,"events"),r}for(let i=0;i<3;i++){try{let r=yield fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:o,keepalive:!0});if(r.ok)return t.debug&&console.log("[IndieBob] sent:",e.batch.length,"events"),!0;if(r.status>=400&&r.status<500)return t.debug&&console.warn("[IndieBob] 4xx error, not retrying:",r.status),!1}catch(r){t.debug&&console.warn("[IndieBob] fetch error (attempt",i+1,"):",r);}i<2&&(yield It(bt[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var T="_ib_queue",St=10,Et=5e3,_t=50,v=class{constructor(t){this.queue=[];this.timer=null;this.flushing=false;this.config=t,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(t){this.queue.push(t),this.queue.length>=St&&this.flush();}flush(t=false){return l(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let n=this.queue.splice(0);(yield w({batch:n},this.config,t))||this.pushToOfflineQueue(n),this.flushing=false;})}flushOfflineQueue(){return l(this,null,function*(){let t=this.getOfflineQueue();if(t.length===0)return;this.clearOfflineQueue(),yield w({batch:t},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},Et);}setupVisibilityFlush(){typeof document!="undefined"&&(document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(true);},{passive:true}),window.addEventListener("pagehide",()=>{this.flush(true);},{passive:true}));}setupOnlineFlush(){typeof window!="undefined"&&(window.addEventListener("online",()=>{this.flushOfflineQueue();}),navigator.onLine&&this.flushOfflineQueue());}pushToOfflineQueue(t){try{let i=[...this.getOfflineQueue(),...t].slice(-_t);localStorage.setItem(T,JSON.stringify(i));}catch(n){}}getOfflineQueue(){try{let t=localStorage.getItem(T);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(T);}catch(t){}}};function W(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function Z(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}var wt=/^https?:\/\/[^/]*(stripe\.com|paypal\.com|paddle\.com|lemonsqueezy\.com|gumroad\.com)(\/|$)/i;function k(e){var x,A,P,C,D,N;let t=typeof window=="undefined",n=(x=e==null?void 0:e.path)!=null?x:t?"":window.location.pathname+window.location.search,o=t?"":window.location.href,i=(A=e==null?void 0:e.title)!=null?A:t?"":document.title,r=(P=e==null?void 0:e.referrer)!=null?P:t?"":document.referrer,c=!t&&(r===""||wt.test(r))&&(C=Q())!=null?C:r,s=Z(),a=W(),u=t?void 0:(D=z(window.location.search))!=null?D:V();return {page:{path:n,url:o,title:i,referrer:c},device:L(p({},s),{type:a}),utm:u,locale:t?"en":navigator.language,timezone:t?"UTC":(N=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?N:"UTC",sdkVersion:"0.2.3"}}function tt(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),n=history.replaceState.bind(history);return history.pushState=function(...o){t(...o),e();},history.replaceState=function(...o){n(...o);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=n,window.removeEventListener("popstate",e);}}var Tt={signup:[/\/(sign-?up|register|join|create-?account|get-?started|onboard|registro|inscription|s-?inscrire|anmeldung|registrieren|cadastro|registrazione|aanmelden|inschrijven)/i],login:[/\/(log-?in|sign-?in|auth(\/login)?|iniciar-?sesion|connexion|se-?connecter|anmelden|einloggen|entrar|accesso|accedi|inloggen)/i],pricing:[/\/(pricing|plans|upgrade|subscribe|precios|tarifs|preise|precos|prezzi|prijzen)/i],checkout:[/\/(checkout|cart|basket|pay(ment)?|order|comprar|pagar|panier|caisse|warenkorb|kasse|carrinho|carrello|winkelwagen)/i],success:[/\/(success|thank-?you|thanks|confirmation|confirmed|complete[d]?|gracias|merci|danke|obrigado|grazie|bedankt)/i],onboarding:[/\/(onboarding|welcome|getting-?started|setup|bienvenido|bienvenue|willkommen|benvenuto|welkom)/i],contact:[/\/(contact|contacto|kontakt|contato|contatto|nous-?contacter)/i]},et={signup:"signup_start",login:"login_view",pricing:"pricing_view",checkout:"checkout_view",success:"success_view",onboarding:"onboarding_view",contact:"contact_view"};function kt(e,t){return e instanceof RegExp?e.test(t):t.includes(e)}function nt(e,t){var n;for(let o of Object.keys(et))if(((n=t==null?void 0:t[o])!=null?n:Tt[o]).some(r=>kt(r,e)))return et[o];return null}function ot(e){return e==="signup_start"?"signup_submit":e==="login_view"?"login_submit":e==="checkout_view"?"checkout_submit":null}function it(e,t){if(typeof document=="undefined")return ()=>{};let n=o=>{o.target instanceof HTMLFormElement&&t(e);};return document.addEventListener("submit",n,true),()=>document.removeEventListener("submit",n,true)}var R="ib_identified";function rt(){return typeof localStorage=="undefined"?true:!localStorage.getItem(R)}function st(){typeof localStorage!="undefined"&&localStorage.setItem(R,"1");}function at(){typeof localStorage!="undefined"&&localStorage.removeItem(R);}var ct="data-ib-event",ut="data-ib-";function lt(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){let i=o.getAttribute(ct);if(i){let r={auto:true};for(let c of o.attributes)if(c.name.startsWith(ut)&&c.name!==ct){let s=c.name.slice(ut.length);r[s]=c.value;}e(i,r);return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}function dt(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){if(o.tagName==="A"){let i=o.href;if(!i||!/^https?:\/\//.test(i))return;try{let r=new URL(i);r.hostname!==window.location.hostname&&e("outbound_click",{auto:!0,url:i,hostname:r.hostname});}catch(r){}return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}var y=class e{constructor(t){this.cleanupHistory=null;this.cleanupAttributes=null;this.cleanupOutbound=null;this.cleanupFormSubmit=null;if(this.config=t,this.queue=new v(t),typeof window!="undefined"&&(K(window.location.search,document.referrer),t.autoDetect!==false)){let n=typeof t.autoDetect=="object"?t.autoDetect:{};n.dataAttributes!==false&&(this.cleanupAttributes=lt((o,i)=>this.track(o,i))),n.outboundClicks!==false&&(this.cleanupOutbound=dt((o,i)=>this.track(o,i)));}}static init(t){let n=M(t);return new e(n)}page(t){var o;if(!f(this.config))return;let n=k(t);if(this.queue.push(this.buildEvent("page",{context:n})),this.config.autoDetect!==false){let i=n.page.path,r=typeof this.config.autoDetect=="object"?this.config.autoDetect:{},c={signup:r.signupPaths,login:r.loginPaths,pricing:r.pricingPaths,checkout:r.checkoutPaths,success:r.successPaths,onboarding:r.onboardingPaths,contact:r.contactPaths},s=nt(i,c);if(s&&(this.queue.push(this.buildEvent("track",{event:s,properties:{auto:true},context:n})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${s} on ${i}`),r.formSubmit!==false)){(o=this.cleanupFormSubmit)==null||o.call(this);let a=ot(s);a&&(this.cleanupFormSubmit=it(a,u=>{this.queue.push(this.buildEvent("track",{event:u,properties:{auto:true}})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${u}`);}));}}}track(t,n){f(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:n}));}identify(t,n){if(f(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:n,userId:t})),this.config.autoDetect!==false)){let o=rt(),i=o?"signup":"login";this.queue.push(this.buildEvent("track",{event:i,properties:{auto:true}})),o&&st(),this.config.debug&&console.log(`[IndieBob] auto-detected: ${i} for ${t}`);}}revenue(t){var n;f(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(n=t.currency)!=null?n:"USD",plan:t.plan,type:t.type}}));}optOut(){var t,n,o;this.queue.flush(),$(),at(),this.userId=void 0,(t=this.cleanupAttributes)==null||t.call(this),(n=this.cleanupOutbound)==null||n.call(this),(o=this.cleanupFormSubmit)==null||o.call(this),this.cleanupAttributes=null,this.cleanupOutbound=null,this.cleanupFormSubmit=null,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){J(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return G()}flush(){return l(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return I()}getSessionId(){return _()}getConfig(){return Object.freeze(p({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=tt(()=>this.page()),()=>{var n;(n=this.cleanupHistory)==null||n.call(this),this.cleanupHistory=null;}}buildEvent(t,n){var o,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:I(),userId:(o=this.userId)!=null?o:n.userId,sessionId:_(),timestamp:new Date().toISOString(),context:(i=n.context)!=null?i:k(),event:n.event,properties:n.properties,traits:n.traits,revenue:n.revenue}}};var Rt=Symbol("indiebob"),O=null,de={install(e,t){let n=y.init(t);O=n,e.provide(Rt,n),e.config.globalProperties.$bob=n;let o=e.config.globalProperties.$router;o&&o.afterEach(()=>{n.page();});}};function fe(){if(O)return O;throw new Error("[IndieBob] useTracker() called before IndieBobPlugin was installed.")}
2
+ exports.IndieBob=y;exports.IndieBobPlugin=de;exports.useTracker=fe;
@@ -1,3 +1,3 @@
1
- var IndieBob=(function(exports){'use strict';var at=Object.defineProperty,ct=Object.defineProperties;var ut=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var lt=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var D=(e,t,n)=>t in e?at(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&D(e,n,t[n]);if(P)for(var n of P(t))dt.call(t,n)&&D(e,n,t[n]);return e},N=(e,t)=>ct(e,ut(t));var l=(e,t,n)=>new Promise((o,i)=>{var r=a=>{try{s(n.next(a));}catch(u){i(u);}},c=a=>{try{s(n.throw(a));}catch(u){i(u);}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((n=n.apply(e,t)).next());});var pt="https://www.indiebob.com/api/collect";function F(e){var t,n,o,i,r;if(!e.projectId||!e.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${e.projectId}". Must start with "proj_".`);return {projectId:e.projectId,endpoint:(t=e.endpoint)!=null?t:pt,debug:(n=e.debug)!=null?n:false,respectDnt:(o=e.respectDnt)!=null?o:true,respectGpc:(i=e.respectGpc)!=null?i:true,autoDetect:(r=e.autoDetect)!=null?r:true}}var d="_ib_anon";function v(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let n=new Uint8Array(21);crypto.getRandomValues(n);for(let o of n)t+=e[o%e.length];}else for(let n=0;n<21;n++)t+=e[Math.floor(Math.random()*e.length)];return t}function y(){try{let e=localStorage.getItem(d);return e||(e=v(),localStorage.setItem(d,e)),e}catch(e){try{let t=sessionStorage.getItem(d);return t||(t=v(),sessionStorage.setItem(d,t)),t}catch(t){return v()}}}function L(){try{localStorage.removeItem(d);}catch(e){}try{sessionStorage.removeItem(d);}catch(e){}}var b="_ib_session",I="_ib_session_last";function B(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function E(){var e;try{let t=Date.now(),n=parseInt((e=sessionStorage.getItem(I))!=null?e:"0",10),o=sessionStorage.getItem(b),i=n>0&&t-n>18e5;return (!o||i)&&(o=B(),sessionStorage.setItem(b,o)),sessionStorage.setItem(I,String(t)),o}catch(t){return B()}}function M(){try{sessionStorage.removeItem(b);}catch(e){}try{sessionStorage.removeItem(I);}catch(e){}}var S="_ib_first_utm",U="_ib_last_utm",_="_ib_referrer";function j(e){let t=new URLSearchParams(e),n={},o=false;return t.has("utm_source")&&(n.source=t.get("utm_source"),o=true),t.has("utm_medium")&&(n.medium=t.get("utm_medium"),o=true),t.has("utm_campaign")&&(n.campaign=t.get("utm_campaign"),o=true),t.has("utm_term")&&(n.term=t.get("utm_term"),o=true),t.has("utm_content")&&(n.content=t.get("utm_content"),o=true),o?n:null}function q(e,t){let n=j(e);try{n&&!localStorage.getItem(S)&&localStorage.setItem(S,JSON.stringify(n)),n&&localStorage.setItem(U,JSON.stringify(n)),t&&!localStorage.getItem(_)&&localStorage.setItem(_,t);}catch(o){}}function Y(e){var t;return (t=j(e))!=null?t:void 0}function H(){try{localStorage.removeItem(S);}catch(e){}try{localStorage.removeItem(U);}catch(e){}try{localStorage.removeItem(_);}catch(e){}}var g="_ib_optout",ft="_ib_queue";function p(e){try{if(localStorage.getItem(g))return !1}catch(t){}return !(e.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||e.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function K(){try{localStorage.setItem(g,"1");}catch(e){}L(),M(),H();try{localStorage.removeItem(ft);}catch(e){}}function V(){try{localStorage.removeItem(g);}catch(e){}}function Q(){try{return !!localStorage.getItem(g)}catch(e){return false}}var gt=[1e3,2e3,4e3];function mt(e){return l(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function w(e,t,n=false){return l(this,null,function*(){let o=JSON.stringify(e);if(n&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([o],{type:"application/json"}),r=navigator.sendBeacon(t.endpoint,i);return t.debug&&console.log("[IndieBob] sendBeacon:",r,e.batch.length,"events"),r}for(let i=0;i<3;i++){try{let r=yield fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:o,keepalive:!0});if(r.ok)return t.debug&&console.log("[IndieBob] sent:",e.batch.length,"events"),!0;if(r.status>=400&&r.status<500)return t.debug&&console.warn("[IndieBob] 4xx error, not retrying:",r.status),!1}catch(r){t.debug&&console.warn("[IndieBob] fetch error (attempt",i+1,"):",r);}i<2&&(yield mt(gt[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var T="_ib_queue",ht=10,vt=5e3,yt=50,m=class{constructor(t){this.queue=[];this.timer=null;this.flushing=false;this.config=t,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(t){this.queue.push(t),this.queue.length>=ht&&this.flush();}flush(t=false){return l(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let n=this.queue.splice(0);(yield w({batch:n},this.config,t))||this.pushToOfflineQueue(n),this.flushing=false;})}flushOfflineQueue(){return l(this,null,function*(){let t=this.getOfflineQueue();if(t.length===0)return;this.clearOfflineQueue(),yield w({batch:t},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},vt);}setupVisibilityFlush(){typeof document!="undefined"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(true);},{passive:true});}setupOnlineFlush(){typeof window!="undefined"&&(window.addEventListener("online",()=>{this.flushOfflineQueue();}),navigator.onLine&&this.flushOfflineQueue());}pushToOfflineQueue(t){try{let i=[...this.getOfflineQueue(),...t].slice(-yt);localStorage.setItem(T,JSON.stringify(i));}catch(n){}}getOfflineQueue(){try{let t=localStorage.getItem(T);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(T);}catch(t){}}};function z(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function X(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}function k(e){var u,x,A,C;let t=typeof window=="undefined",n=(u=e==null?void 0:e.path)!=null?u:t?"":window.location.pathname+window.location.search,o=t?"":window.location.href,i=(x=e==null?void 0:e.title)!=null?x:t?"":document.title,r=(A=e==null?void 0:e.referrer)!=null?A:t?"":document.referrer,c=X(),s=z(),a=t?void 0:Y(window.location.search);return {page:{path:n,url:o,title:i,referrer:r},device:N(f({},c),{type:s}),utm:a,locale:t?"en":navigator.language,timezone:t?"UTC":(C=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?C:"UTC",sdkVersion:"0.2.1"}}function $(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),n=history.replaceState.bind(history);return history.pushState=function(...o){t(...o),e();},history.replaceState=function(...o){n(...o);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=n,window.removeEventListener("popstate",e);}}var bt={signup:[/\/(sign-?up|register|join|create-?account|get-?started|onboard|registro|inscription|s-?inscrire|anmeldung|registrieren|cadastro|registrazione|aanmelden|inschrijven)/i],login:[/\/(log-?in|sign-?in|auth(\/login)?|iniciar-?sesion|connexion|se-?connecter|anmelden|einloggen|entrar|accesso|accedi|inloggen)/i],pricing:[/\/(pricing|plans|upgrade|subscribe|precios|tarifs|preise|precos|prezzi|prijzen)/i],checkout:[/\/(checkout|cart|basket|pay(ment)?|order|comprar|pagar|panier|caisse|warenkorb|kasse|carrinho|carrello|winkelwagen)/i],success:[/\/(success|thank-?you|thanks|confirmation|confirmed|complete[d]?|gracias|merci|danke|obrigado|grazie|bedankt)/i],onboarding:[/\/(onboarding|welcome|getting-?started|setup|bienvenido|bienvenue|willkommen|benvenuto|welkom)/i],contact:[/\/(contact|contacto|kontakt|contato|contatto|nous-?contacter)/i]},J={signup:"signup_start",login:"login_view",pricing:"pricing_view",checkout:"checkout_view",success:"success_view",onboarding:"onboarding_view",contact:"contact_view"};function It(e,t){return e instanceof RegExp?e.test(t):t.includes(e)}function G(e,t){var n;for(let o of Object.keys(J))if(((n=t==null?void 0:t[o])!=null?n:bt[o]).some(r=>It(r,e)))return J[o];return null}function W(e){return e==="signup_start"?"signup_submit":e==="login_view"?"login_submit":e==="checkout_view"?"checkout_submit":null}function Z(e,t){if(typeof document=="undefined")return ()=>{};let n=o=>{o.target instanceof HTMLFormElement&&t(e);};return document.addEventListener("submit",n,true),()=>document.removeEventListener("submit",n,true)}var R="ib_identified";function tt(){return typeof localStorage=="undefined"?true:!localStorage.getItem(R)}function et(){typeof localStorage!="undefined"&&localStorage.setItem(R,"1");}function nt(){typeof localStorage!="undefined"&&localStorage.removeItem(R);}var ot="data-ib-event",it="data-ib-";function rt(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){let i=o.getAttribute(ot);if(i){let r={auto:true};for(let c of o.attributes)if(c.name.startsWith(it)&&c.name!==ot){let s=c.name.slice(it.length);r[s]=c.value;}e(i,r);return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}function st(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){if(o.tagName==="A"){let i=o.href;if(!i||!/^https?:\/\//.test(i))return;try{let r=new URL(i);r.hostname!==window.location.hostname&&e("outbound_click",{auto:!0,url:i,hostname:r.hostname});}catch(r){}return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}var h=class e{constructor(t){this.cleanupHistory=null;this.cleanupAttributes=null;this.cleanupOutbound=null;this.cleanupFormSubmit=null;if(this.config=t,this.queue=new m(t),typeof window!="undefined"&&(q(window.location.search,document.referrer),t.autoDetect!==false)){let n=typeof t.autoDetect=="object"?t.autoDetect:{};n.dataAttributes!==false&&(this.cleanupAttributes=rt((o,i)=>this.track(o,i))),n.outboundClicks!==false&&(this.cleanupOutbound=st((o,i)=>this.track(o,i)));}}static init(t){let n=F(t);return new e(n)}page(t){var o;if(!p(this.config))return;let n=k(t);if(this.queue.push(this.buildEvent("page",{context:n})),this.config.autoDetect!==false){let i=n.page.path,r=typeof this.config.autoDetect=="object"?this.config.autoDetect:{},c={signup:r.signupPaths,login:r.loginPaths,pricing:r.pricingPaths,checkout:r.checkoutPaths,success:r.successPaths,onboarding:r.onboardingPaths,contact:r.contactPaths},s=G(i,c);if(s&&(this.queue.push(this.buildEvent("track",{event:s,properties:{auto:true},context:n})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${s} on ${i}`),r.formSubmit!==false)){(o=this.cleanupFormSubmit)==null||o.call(this);let a=W(s);a&&(this.cleanupFormSubmit=Z(a,u=>{this.queue.push(this.buildEvent("track",{event:u,properties:{auto:true}})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${u}`);}));}}}track(t,n){p(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:n}));}identify(t,n){if(p(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:n,userId:t})),this.config.autoDetect!==false)){let o=tt(),i=o?"signup":"login";this.queue.push(this.buildEvent("track",{event:i,properties:{auto:true}})),o&&et(),this.config.debug&&console.log(`[IndieBob] auto-detected: ${i} for ${t}`);}}revenue(t){var n;p(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(n=t.currency)!=null?n:"USD",plan:t.plan,type:t.type}}));}optOut(){var t,n,o;this.queue.flush(),K(),nt(),this.userId=void 0,(t=this.cleanupAttributes)==null||t.call(this),(n=this.cleanupOutbound)==null||n.call(this),(o=this.cleanupFormSubmit)==null||o.call(this),this.cleanupAttributes=null,this.cleanupOutbound=null,this.cleanupFormSubmit=null,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){V(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return Q()}flush(){return l(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return y()}getSessionId(){return E()}getConfig(){return Object.freeze(f({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=$(()=>this.page()),()=>{var n;(n=this.cleanupHistory)==null||n.call(this),this.cleanupHistory=null;}}buildEvent(t,n){var o,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:y(),userId:(o=this.userId)!=null?o:n.userId,sessionId:E(),timestamp:new Date().toISOString(),context:(i=n.context)!=null?i:k(),event:n.event,properties:n.properties,traits:n.traits,revenue:n.revenue}}};var Et=Symbol("indiebob"),O=null,re={install(e,t){let n=h.init(t);O=n,e.provide(Et,n),e.config.globalProperties.$bob=n;let o=e.config.globalProperties.$router;o&&o.afterEach(()=>{n.page();});}};function se(){if(O)return O;throw new Error("[IndieBob] useTracker() called before IndieBobPlugin was installed.")}
2
- exports.IndieBob=h;exports.IndieBobPlugin=re;exports.useTracker=se;return exports;})({});
1
+ var IndieBob=(function(exports){'use strict';var ft=Object.defineProperty,pt=Object.defineProperties;var gt=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var mt=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable;var U=(e,t,n)=>t in e?ft(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,p=(e,t)=>{for(var n in t||(t={}))mt.call(t,n)&&U(e,n,t[n]);if(F)for(var n of F(t))ht.call(t,n)&&U(e,n,t[n]);return e},L=(e,t)=>pt(e,gt(t));var l=(e,t,n)=>new Promise((o,i)=>{var r=a=>{try{s(n.next(a));}catch(u){i(u);}},c=a=>{try{s(n.throw(a));}catch(u){i(u);}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((n=n.apply(e,t)).next());});var vt="https://www.indiebob.com/api/collect";function M(e){var t,n,o,i,r;if(!e.projectId||!e.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${e.projectId}". Must start with "proj_".`);return {projectId:e.projectId,endpoint:(t=e.endpoint)!=null?t:vt,debug:(n=e.debug)!=null?n:false,respectDnt:(o=e.respectDnt)!=null?o:true,respectGpc:(i=e.respectGpc)!=null?i:true,autoDetect:(r=e.autoDetect)!=null?r:true}}var d="_ib_anon";function b(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let n=new Uint8Array(21);crypto.getRandomValues(n);for(let o of n)t+=e[o%e.length];}else for(let n=0;n<21;n++)t+=e[Math.floor(Math.random()*e.length)];return t}function I(){try{let e=localStorage.getItem(d);return e||(e=b(),localStorage.setItem(d,e)),e}catch(e){try{let t=sessionStorage.getItem(d);return t||(t=b(),sessionStorage.setItem(d,t)),t}catch(t){return b()}}}function B(){try{localStorage.removeItem(d);}catch(e){}try{sessionStorage.removeItem(d);}catch(e){}}var S="_ib_session",E="_ib_session_last";function q(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function _(){var e;try{let t=Date.now(),n=parseInt((e=sessionStorage.getItem(E))!=null?e:"0",10),o=sessionStorage.getItem(S),i=n>0&&t-n>18e5;return (!o||i)&&(o=q(),sessionStorage.setItem(S,o)),sessionStorage.setItem(E,String(t)),o}catch(t){return q()}}function j(){try{sessionStorage.removeItem(S);}catch(e){}try{sessionStorage.removeItem(E);}catch(e){}}var g="_ib_first_utm",Y="_ib_last_utm",m="_ib_referrer";function H(e){let t=new URLSearchParams(e),n={},o=false;return t.has("utm_source")?(n.source=t.get("utm_source"),o=true):t.get("ref")&&(n.source=t.get("ref"),o=true),t.has("utm_medium")&&(n.medium=t.get("utm_medium"),o=true),t.has("utm_campaign")&&(n.campaign=t.get("utm_campaign"),o=true),t.has("utm_term")&&(n.term=t.get("utm_term"),o=true),t.has("utm_content")&&(n.content=t.get("utm_content"),o=true),o?n:null}function K(e,t){let n=H(e);try{n&&!localStorage.getItem(g)&&localStorage.setItem(g,JSON.stringify(n)),n&&localStorage.setItem(Y,JSON.stringify(n)),t&&!localStorage.getItem(m)&&localStorage.setItem(m,t);}catch(o){}}function V(){try{let e=localStorage.getItem(g);return e?JSON.parse(e):void 0}catch(e){return}}function Q(){var e;try{return (e=localStorage.getItem(m))!=null?e:void 0}catch(t){return}}function z(e){var t;return (t=H(e))!=null?t:void 0}function X(){try{localStorage.removeItem(g);}catch(e){}try{localStorage.removeItem(Y);}catch(e){}try{localStorage.removeItem(m);}catch(e){}}var h="_ib_optout",yt="_ib_queue";function f(e){try{if(localStorage.getItem(h))return !1}catch(t){}return !(e.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||e.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function $(){try{localStorage.setItem(h,"1");}catch(e){}B(),j(),X();try{localStorage.removeItem(yt);}catch(e){}}function J(){try{localStorage.removeItem(h);}catch(e){}}function G(){try{return !!localStorage.getItem(h)}catch(e){return false}}var bt=[1e3,2e3,4e3];function It(e){return l(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function w(e,t,n=false){return l(this,null,function*(){let o=JSON.stringify(e);if(n&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([o],{type:"text/plain;charset=UTF-8"}),r=navigator.sendBeacon(t.endpoint,i);return t.debug&&console.log("[IndieBob] sendBeacon:",r,e.batch.length,"events"),r}for(let i=0;i<3;i++){try{let r=yield fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:o,keepalive:!0});if(r.ok)return t.debug&&console.log("[IndieBob] sent:",e.batch.length,"events"),!0;if(r.status>=400&&r.status<500)return t.debug&&console.warn("[IndieBob] 4xx error, not retrying:",r.status),!1}catch(r){t.debug&&console.warn("[IndieBob] fetch error (attempt",i+1,"):",r);}i<2&&(yield It(bt[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var T="_ib_queue",St=10,Et=5e3,_t=50,v=class{constructor(t){this.queue=[];this.timer=null;this.flushing=false;this.config=t,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(t){this.queue.push(t),this.queue.length>=St&&this.flush();}flush(t=false){return l(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let n=this.queue.splice(0);(yield w({batch:n},this.config,t))||this.pushToOfflineQueue(n),this.flushing=false;})}flushOfflineQueue(){return l(this,null,function*(){let t=this.getOfflineQueue();if(t.length===0)return;this.clearOfflineQueue(),yield w({batch:t},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},Et);}setupVisibilityFlush(){typeof document!="undefined"&&(document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(true);},{passive:true}),window.addEventListener("pagehide",()=>{this.flush(true);},{passive:true}));}setupOnlineFlush(){typeof window!="undefined"&&(window.addEventListener("online",()=>{this.flushOfflineQueue();}),navigator.onLine&&this.flushOfflineQueue());}pushToOfflineQueue(t){try{let i=[...this.getOfflineQueue(),...t].slice(-_t);localStorage.setItem(T,JSON.stringify(i));}catch(n){}}getOfflineQueue(){try{let t=localStorage.getItem(T);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(T);}catch(t){}}};function W(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function Z(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}var wt=/^https?:\/\/[^/]*(stripe\.com|paypal\.com|paddle\.com|lemonsqueezy\.com|gumroad\.com)(\/|$)/i;function k(e){var x,A,P,C,D,N;let t=typeof window=="undefined",n=(x=e==null?void 0:e.path)!=null?x:t?"":window.location.pathname+window.location.search,o=t?"":window.location.href,i=(A=e==null?void 0:e.title)!=null?A:t?"":document.title,r=(P=e==null?void 0:e.referrer)!=null?P:t?"":document.referrer,c=!t&&(r===""||wt.test(r))&&(C=Q())!=null?C:r,s=Z(),a=W(),u=t?void 0:(D=z(window.location.search))!=null?D:V();return {page:{path:n,url:o,title:i,referrer:c},device:L(p({},s),{type:a}),utm:u,locale:t?"en":navigator.language,timezone:t?"UTC":(N=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?N:"UTC",sdkVersion:"0.2.3"}}function tt(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),n=history.replaceState.bind(history);return history.pushState=function(...o){t(...o),e();},history.replaceState=function(...o){n(...o);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=n,window.removeEventListener("popstate",e);}}var Tt={signup:[/\/(sign-?up|register|join|create-?account|get-?started|onboard|registro|inscription|s-?inscrire|anmeldung|registrieren|cadastro|registrazione|aanmelden|inschrijven)/i],login:[/\/(log-?in|sign-?in|auth(\/login)?|iniciar-?sesion|connexion|se-?connecter|anmelden|einloggen|entrar|accesso|accedi|inloggen)/i],pricing:[/\/(pricing|plans|upgrade|subscribe|precios|tarifs|preise|precos|prezzi|prijzen)/i],checkout:[/\/(checkout|cart|basket|pay(ment)?|order|comprar|pagar|panier|caisse|warenkorb|kasse|carrinho|carrello|winkelwagen)/i],success:[/\/(success|thank-?you|thanks|confirmation|confirmed|complete[d]?|gracias|merci|danke|obrigado|grazie|bedankt)/i],onboarding:[/\/(onboarding|welcome|getting-?started|setup|bienvenido|bienvenue|willkommen|benvenuto|welkom)/i],contact:[/\/(contact|contacto|kontakt|contato|contatto|nous-?contacter)/i]},et={signup:"signup_start",login:"login_view",pricing:"pricing_view",checkout:"checkout_view",success:"success_view",onboarding:"onboarding_view",contact:"contact_view"};function kt(e,t){return e instanceof RegExp?e.test(t):t.includes(e)}function nt(e,t){var n;for(let o of Object.keys(et))if(((n=t==null?void 0:t[o])!=null?n:Tt[o]).some(r=>kt(r,e)))return et[o];return null}function ot(e){return e==="signup_start"?"signup_submit":e==="login_view"?"login_submit":e==="checkout_view"?"checkout_submit":null}function it(e,t){if(typeof document=="undefined")return ()=>{};let n=o=>{o.target instanceof HTMLFormElement&&t(e);};return document.addEventListener("submit",n,true),()=>document.removeEventListener("submit",n,true)}var R="ib_identified";function rt(){return typeof localStorage=="undefined"?true:!localStorage.getItem(R)}function st(){typeof localStorage!="undefined"&&localStorage.setItem(R,"1");}function at(){typeof localStorage!="undefined"&&localStorage.removeItem(R);}var ct="data-ib-event",ut="data-ib-";function lt(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){let i=o.getAttribute(ct);if(i){let r={auto:true};for(let c of o.attributes)if(c.name.startsWith(ut)&&c.name!==ct){let s=c.name.slice(ut.length);r[s]=c.value;}e(i,r);return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}function dt(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){if(o.tagName==="A"){let i=o.href;if(!i||!/^https?:\/\//.test(i))return;try{let r=new URL(i);r.hostname!==window.location.hostname&&e("outbound_click",{auto:!0,url:i,hostname:r.hostname});}catch(r){}return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}var y=class e{constructor(t){this.cleanupHistory=null;this.cleanupAttributes=null;this.cleanupOutbound=null;this.cleanupFormSubmit=null;if(this.config=t,this.queue=new v(t),typeof window!="undefined"&&(K(window.location.search,document.referrer),t.autoDetect!==false)){let n=typeof t.autoDetect=="object"?t.autoDetect:{};n.dataAttributes!==false&&(this.cleanupAttributes=lt((o,i)=>this.track(o,i))),n.outboundClicks!==false&&(this.cleanupOutbound=dt((o,i)=>this.track(o,i)));}}static init(t){let n=M(t);return new e(n)}page(t){var o;if(!f(this.config))return;let n=k(t);if(this.queue.push(this.buildEvent("page",{context:n})),this.config.autoDetect!==false){let i=n.page.path,r=typeof this.config.autoDetect=="object"?this.config.autoDetect:{},c={signup:r.signupPaths,login:r.loginPaths,pricing:r.pricingPaths,checkout:r.checkoutPaths,success:r.successPaths,onboarding:r.onboardingPaths,contact:r.contactPaths},s=nt(i,c);if(s&&(this.queue.push(this.buildEvent("track",{event:s,properties:{auto:true},context:n})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${s} on ${i}`),r.formSubmit!==false)){(o=this.cleanupFormSubmit)==null||o.call(this);let a=ot(s);a&&(this.cleanupFormSubmit=it(a,u=>{this.queue.push(this.buildEvent("track",{event:u,properties:{auto:true}})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${u}`);}));}}}track(t,n){f(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:n}));}identify(t,n){if(f(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:n,userId:t})),this.config.autoDetect!==false)){let o=rt(),i=o?"signup":"login";this.queue.push(this.buildEvent("track",{event:i,properties:{auto:true}})),o&&st(),this.config.debug&&console.log(`[IndieBob] auto-detected: ${i} for ${t}`);}}revenue(t){var n;f(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(n=t.currency)!=null?n:"USD",plan:t.plan,type:t.type}}));}optOut(){var t,n,o;this.queue.flush(),$(),at(),this.userId=void 0,(t=this.cleanupAttributes)==null||t.call(this),(n=this.cleanupOutbound)==null||n.call(this),(o=this.cleanupFormSubmit)==null||o.call(this),this.cleanupAttributes=null,this.cleanupOutbound=null,this.cleanupFormSubmit=null,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){J(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return G()}flush(){return l(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return I()}getSessionId(){return _()}getConfig(){return Object.freeze(p({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=tt(()=>this.page()),()=>{var n;(n=this.cleanupHistory)==null||n.call(this),this.cleanupHistory=null;}}buildEvent(t,n){var o,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:I(),userId:(o=this.userId)!=null?o:n.userId,sessionId:_(),timestamp:new Date().toISOString(),context:(i=n.context)!=null?i:k(),event:n.event,properties:n.properties,traits:n.traits,revenue:n.revenue}}};var Rt=Symbol("indiebob"),O=null,de={install(e,t){let n=y.init(t);O=n,e.provide(Rt,n),e.config.globalProperties.$bob=n;let o=e.config.globalProperties.$router;o&&o.afterEach(()=>{n.page();});}};function fe(){if(O)return O;throw new Error("[IndieBob] useTracker() called before IndieBobPlugin was installed.")}
2
+ exports.IndieBob=y;exports.IndieBobPlugin=de;exports.useTracker=fe;return exports;})({});
3
3
  ;if(typeof IndieBob!=="undefined"&&IndieBob&&IndieBob.IndieBob){IndieBob=Object.assign(IndieBob.IndieBob,IndieBob);}
package/dist/vue.js CHANGED
@@ -1,2 +1,2 @@
1
- var at=Object.defineProperty,ct=Object.defineProperties;var ut=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var lt=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var D=(e,t,n)=>t in e?at(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&D(e,n,t[n]);if(P)for(var n of P(t))dt.call(t,n)&&D(e,n,t[n]);return e},N=(e,t)=>ct(e,ut(t));var l=(e,t,n)=>new Promise((o,i)=>{var r=a=>{try{s(n.next(a));}catch(u){i(u);}},c=a=>{try{s(n.throw(a));}catch(u){i(u);}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((n=n.apply(e,t)).next());});var pt="https://www.indiebob.com/api/collect";function F(e){var t,n,o,i,r;if(!e.projectId||!e.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${e.projectId}". Must start with "proj_".`);return {projectId:e.projectId,endpoint:(t=e.endpoint)!=null?t:pt,debug:(n=e.debug)!=null?n:false,respectDnt:(o=e.respectDnt)!=null?o:true,respectGpc:(i=e.respectGpc)!=null?i:true,autoDetect:(r=e.autoDetect)!=null?r:true}}var d="_ib_anon";function v(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let n=new Uint8Array(21);crypto.getRandomValues(n);for(let o of n)t+=e[o%e.length];}else for(let n=0;n<21;n++)t+=e[Math.floor(Math.random()*e.length)];return t}function y(){try{let e=localStorage.getItem(d);return e||(e=v(),localStorage.setItem(d,e)),e}catch(e){try{let t=sessionStorage.getItem(d);return t||(t=v(),sessionStorage.setItem(d,t)),t}catch(t){return v()}}}function L(){try{localStorage.removeItem(d);}catch(e){}try{sessionStorage.removeItem(d);}catch(e){}}var b="_ib_session",I="_ib_session_last";function B(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function E(){var e;try{let t=Date.now(),n=parseInt((e=sessionStorage.getItem(I))!=null?e:"0",10),o=sessionStorage.getItem(b),i=n>0&&t-n>18e5;return (!o||i)&&(o=B(),sessionStorage.setItem(b,o)),sessionStorage.setItem(I,String(t)),o}catch(t){return B()}}function M(){try{sessionStorage.removeItem(b);}catch(e){}try{sessionStorage.removeItem(I);}catch(e){}}var S="_ib_first_utm",U="_ib_last_utm",_="_ib_referrer";function j(e){let t=new URLSearchParams(e),n={},o=false;return t.has("utm_source")&&(n.source=t.get("utm_source"),o=true),t.has("utm_medium")&&(n.medium=t.get("utm_medium"),o=true),t.has("utm_campaign")&&(n.campaign=t.get("utm_campaign"),o=true),t.has("utm_term")&&(n.term=t.get("utm_term"),o=true),t.has("utm_content")&&(n.content=t.get("utm_content"),o=true),o?n:null}function q(e,t){let n=j(e);try{n&&!localStorage.getItem(S)&&localStorage.setItem(S,JSON.stringify(n)),n&&localStorage.setItem(U,JSON.stringify(n)),t&&!localStorage.getItem(_)&&localStorage.setItem(_,t);}catch(o){}}function Y(e){var t;return (t=j(e))!=null?t:void 0}function H(){try{localStorage.removeItem(S);}catch(e){}try{localStorage.removeItem(U);}catch(e){}try{localStorage.removeItem(_);}catch(e){}}var g="_ib_optout",ft="_ib_queue";function p(e){try{if(localStorage.getItem(g))return !1}catch(t){}return !(e.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||e.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function K(){try{localStorage.setItem(g,"1");}catch(e){}L(),M(),H();try{localStorage.removeItem(ft);}catch(e){}}function V(){try{localStorage.removeItem(g);}catch(e){}}function Q(){try{return !!localStorage.getItem(g)}catch(e){return false}}var gt=[1e3,2e3,4e3];function mt(e){return l(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function w(e,t,n=false){return l(this,null,function*(){let o=JSON.stringify(e);if(n&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([o],{type:"application/json"}),r=navigator.sendBeacon(t.endpoint,i);return t.debug&&console.log("[IndieBob] sendBeacon:",r,e.batch.length,"events"),r}for(let i=0;i<3;i++){try{let r=yield fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:o,keepalive:!0});if(r.ok)return t.debug&&console.log("[IndieBob] sent:",e.batch.length,"events"),!0;if(r.status>=400&&r.status<500)return t.debug&&console.warn("[IndieBob] 4xx error, not retrying:",r.status),!1}catch(r){t.debug&&console.warn("[IndieBob] fetch error (attempt",i+1,"):",r);}i<2&&(yield mt(gt[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var T="_ib_queue",ht=10,vt=5e3,yt=50,m=class{constructor(t){this.queue=[];this.timer=null;this.flushing=false;this.config=t,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(t){this.queue.push(t),this.queue.length>=ht&&this.flush();}flush(t=false){return l(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let n=this.queue.splice(0);(yield w({batch:n},this.config,t))||this.pushToOfflineQueue(n),this.flushing=false;})}flushOfflineQueue(){return l(this,null,function*(){let t=this.getOfflineQueue();if(t.length===0)return;this.clearOfflineQueue(),yield w({batch:t},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},vt);}setupVisibilityFlush(){typeof document!="undefined"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(true);},{passive:true});}setupOnlineFlush(){typeof window!="undefined"&&(window.addEventListener("online",()=>{this.flushOfflineQueue();}),navigator.onLine&&this.flushOfflineQueue());}pushToOfflineQueue(t){try{let i=[...this.getOfflineQueue(),...t].slice(-yt);localStorage.setItem(T,JSON.stringify(i));}catch(n){}}getOfflineQueue(){try{let t=localStorage.getItem(T);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(T);}catch(t){}}};function z(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function X(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}function k(e){var u,x,A,C;let t=typeof window=="undefined",n=(u=e==null?void 0:e.path)!=null?u:t?"":window.location.pathname+window.location.search,o=t?"":window.location.href,i=(x=e==null?void 0:e.title)!=null?x:t?"":document.title,r=(A=e==null?void 0:e.referrer)!=null?A:t?"":document.referrer,c=X(),s=z(),a=t?void 0:Y(window.location.search);return {page:{path:n,url:o,title:i,referrer:r},device:N(f({},c),{type:s}),utm:a,locale:t?"en":navigator.language,timezone:t?"UTC":(C=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?C:"UTC",sdkVersion:"0.2.1"}}function $(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),n=history.replaceState.bind(history);return history.pushState=function(...o){t(...o),e();},history.replaceState=function(...o){n(...o);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=n,window.removeEventListener("popstate",e);}}var bt={signup:[/\/(sign-?up|register|join|create-?account|get-?started|onboard|registro|inscription|s-?inscrire|anmeldung|registrieren|cadastro|registrazione|aanmelden|inschrijven)/i],login:[/\/(log-?in|sign-?in|auth(\/login)?|iniciar-?sesion|connexion|se-?connecter|anmelden|einloggen|entrar|accesso|accedi|inloggen)/i],pricing:[/\/(pricing|plans|upgrade|subscribe|precios|tarifs|preise|precos|prezzi|prijzen)/i],checkout:[/\/(checkout|cart|basket|pay(ment)?|order|comprar|pagar|panier|caisse|warenkorb|kasse|carrinho|carrello|winkelwagen)/i],success:[/\/(success|thank-?you|thanks|confirmation|confirmed|complete[d]?|gracias|merci|danke|obrigado|grazie|bedankt)/i],onboarding:[/\/(onboarding|welcome|getting-?started|setup|bienvenido|bienvenue|willkommen|benvenuto|welkom)/i],contact:[/\/(contact|contacto|kontakt|contato|contatto|nous-?contacter)/i]},J={signup:"signup_start",login:"login_view",pricing:"pricing_view",checkout:"checkout_view",success:"success_view",onboarding:"onboarding_view",contact:"contact_view"};function It(e,t){return e instanceof RegExp?e.test(t):t.includes(e)}function G(e,t){var n;for(let o of Object.keys(J))if(((n=t==null?void 0:t[o])!=null?n:bt[o]).some(r=>It(r,e)))return J[o];return null}function W(e){return e==="signup_start"?"signup_submit":e==="login_view"?"login_submit":e==="checkout_view"?"checkout_submit":null}function Z(e,t){if(typeof document=="undefined")return ()=>{};let n=o=>{o.target instanceof HTMLFormElement&&t(e);};return document.addEventListener("submit",n,true),()=>document.removeEventListener("submit",n,true)}var R="ib_identified";function tt(){return typeof localStorage=="undefined"?true:!localStorage.getItem(R)}function et(){typeof localStorage!="undefined"&&localStorage.setItem(R,"1");}function nt(){typeof localStorage!="undefined"&&localStorage.removeItem(R);}var ot="data-ib-event",it="data-ib-";function rt(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){let i=o.getAttribute(ot);if(i){let r={auto:true};for(let c of o.attributes)if(c.name.startsWith(it)&&c.name!==ot){let s=c.name.slice(it.length);r[s]=c.value;}e(i,r);return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}function st(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){if(o.tagName==="A"){let i=o.href;if(!i||!/^https?:\/\//.test(i))return;try{let r=new URL(i);r.hostname!==window.location.hostname&&e("outbound_click",{auto:!0,url:i,hostname:r.hostname});}catch(r){}return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}var h=class e{constructor(t){this.cleanupHistory=null;this.cleanupAttributes=null;this.cleanupOutbound=null;this.cleanupFormSubmit=null;if(this.config=t,this.queue=new m(t),typeof window!="undefined"&&(q(window.location.search,document.referrer),t.autoDetect!==false)){let n=typeof t.autoDetect=="object"?t.autoDetect:{};n.dataAttributes!==false&&(this.cleanupAttributes=rt((o,i)=>this.track(o,i))),n.outboundClicks!==false&&(this.cleanupOutbound=st((o,i)=>this.track(o,i)));}}static init(t){let n=F(t);return new e(n)}page(t){var o;if(!p(this.config))return;let n=k(t);if(this.queue.push(this.buildEvent("page",{context:n})),this.config.autoDetect!==false){let i=n.page.path,r=typeof this.config.autoDetect=="object"?this.config.autoDetect:{},c={signup:r.signupPaths,login:r.loginPaths,pricing:r.pricingPaths,checkout:r.checkoutPaths,success:r.successPaths,onboarding:r.onboardingPaths,contact:r.contactPaths},s=G(i,c);if(s&&(this.queue.push(this.buildEvent("track",{event:s,properties:{auto:true},context:n})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${s} on ${i}`),r.formSubmit!==false)){(o=this.cleanupFormSubmit)==null||o.call(this);let a=W(s);a&&(this.cleanupFormSubmit=Z(a,u=>{this.queue.push(this.buildEvent("track",{event:u,properties:{auto:true}})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${u}`);}));}}}track(t,n){p(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:n}));}identify(t,n){if(p(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:n,userId:t})),this.config.autoDetect!==false)){let o=tt(),i=o?"signup":"login";this.queue.push(this.buildEvent("track",{event:i,properties:{auto:true}})),o&&et(),this.config.debug&&console.log(`[IndieBob] auto-detected: ${i} for ${t}`);}}revenue(t){var n;p(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(n=t.currency)!=null?n:"USD",plan:t.plan,type:t.type}}));}optOut(){var t,n,o;this.queue.flush(),K(),nt(),this.userId=void 0,(t=this.cleanupAttributes)==null||t.call(this),(n=this.cleanupOutbound)==null||n.call(this),(o=this.cleanupFormSubmit)==null||o.call(this),this.cleanupAttributes=null,this.cleanupOutbound=null,this.cleanupFormSubmit=null,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){V(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return Q()}flush(){return l(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return y()}getSessionId(){return E()}getConfig(){return Object.freeze(f({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=$(()=>this.page()),()=>{var n;(n=this.cleanupHistory)==null||n.call(this),this.cleanupHistory=null;}}buildEvent(t,n){var o,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:y(),userId:(o=this.userId)!=null?o:n.userId,sessionId:E(),timestamp:new Date().toISOString(),context:(i=n.context)!=null?i:k(),event:n.event,properties:n.properties,traits:n.traits,revenue:n.revenue}}};var Et=Symbol("indiebob"),O=null,re={install(e,t){let n=h.init(t);O=n,e.provide(Et,n),e.config.globalProperties.$bob=n;let o=e.config.globalProperties.$router;o&&o.afterEach(()=>{n.page();});}};function se(){if(O)return O;throw new Error("[IndieBob] useTracker() called before IndieBobPlugin was installed.")}
2
- export{h as IndieBob,re as IndieBobPlugin,se as useTracker};
1
+ var ft=Object.defineProperty,pt=Object.defineProperties;var gt=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var mt=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable;var U=(e,t,n)=>t in e?ft(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,p=(e,t)=>{for(var n in t||(t={}))mt.call(t,n)&&U(e,n,t[n]);if(F)for(var n of F(t))ht.call(t,n)&&U(e,n,t[n]);return e},L=(e,t)=>pt(e,gt(t));var l=(e,t,n)=>new Promise((o,i)=>{var r=a=>{try{s(n.next(a));}catch(u){i(u);}},c=a=>{try{s(n.throw(a));}catch(u){i(u);}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((n=n.apply(e,t)).next());});var vt="https://www.indiebob.com/api/collect";function M(e){var t,n,o,i,r;if(!e.projectId||!e.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${e.projectId}". Must start with "proj_".`);return {projectId:e.projectId,endpoint:(t=e.endpoint)!=null?t:vt,debug:(n=e.debug)!=null?n:false,respectDnt:(o=e.respectDnt)!=null?o:true,respectGpc:(i=e.respectGpc)!=null?i:true,autoDetect:(r=e.autoDetect)!=null?r:true}}var d="_ib_anon";function b(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let n=new Uint8Array(21);crypto.getRandomValues(n);for(let o of n)t+=e[o%e.length];}else for(let n=0;n<21;n++)t+=e[Math.floor(Math.random()*e.length)];return t}function I(){try{let e=localStorage.getItem(d);return e||(e=b(),localStorage.setItem(d,e)),e}catch(e){try{let t=sessionStorage.getItem(d);return t||(t=b(),sessionStorage.setItem(d,t)),t}catch(t){return b()}}}function B(){try{localStorage.removeItem(d);}catch(e){}try{sessionStorage.removeItem(d);}catch(e){}}var S="_ib_session",E="_ib_session_last";function q(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function _(){var e;try{let t=Date.now(),n=parseInt((e=sessionStorage.getItem(E))!=null?e:"0",10),o=sessionStorage.getItem(S),i=n>0&&t-n>18e5;return (!o||i)&&(o=q(),sessionStorage.setItem(S,o)),sessionStorage.setItem(E,String(t)),o}catch(t){return q()}}function j(){try{sessionStorage.removeItem(S);}catch(e){}try{sessionStorage.removeItem(E);}catch(e){}}var g="_ib_first_utm",Y="_ib_last_utm",m="_ib_referrer";function H(e){let t=new URLSearchParams(e),n={},o=false;return t.has("utm_source")?(n.source=t.get("utm_source"),o=true):t.get("ref")&&(n.source=t.get("ref"),o=true),t.has("utm_medium")&&(n.medium=t.get("utm_medium"),o=true),t.has("utm_campaign")&&(n.campaign=t.get("utm_campaign"),o=true),t.has("utm_term")&&(n.term=t.get("utm_term"),o=true),t.has("utm_content")&&(n.content=t.get("utm_content"),o=true),o?n:null}function K(e,t){let n=H(e);try{n&&!localStorage.getItem(g)&&localStorage.setItem(g,JSON.stringify(n)),n&&localStorage.setItem(Y,JSON.stringify(n)),t&&!localStorage.getItem(m)&&localStorage.setItem(m,t);}catch(o){}}function V(){try{let e=localStorage.getItem(g);return e?JSON.parse(e):void 0}catch(e){return}}function Q(){var e;try{return (e=localStorage.getItem(m))!=null?e:void 0}catch(t){return}}function z(e){var t;return (t=H(e))!=null?t:void 0}function X(){try{localStorage.removeItem(g);}catch(e){}try{localStorage.removeItem(Y);}catch(e){}try{localStorage.removeItem(m);}catch(e){}}var h="_ib_optout",yt="_ib_queue";function f(e){try{if(localStorage.getItem(h))return !1}catch(t){}return !(e.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||e.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function $(){try{localStorage.setItem(h,"1");}catch(e){}B(),j(),X();try{localStorage.removeItem(yt);}catch(e){}}function J(){try{localStorage.removeItem(h);}catch(e){}}function G(){try{return !!localStorage.getItem(h)}catch(e){return false}}var bt=[1e3,2e3,4e3];function It(e){return l(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function w(e,t,n=false){return l(this,null,function*(){let o=JSON.stringify(e);if(n&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([o],{type:"text/plain;charset=UTF-8"}),r=navigator.sendBeacon(t.endpoint,i);return t.debug&&console.log("[IndieBob] sendBeacon:",r,e.batch.length,"events"),r}for(let i=0;i<3;i++){try{let r=yield fetch(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:o,keepalive:!0});if(r.ok)return t.debug&&console.log("[IndieBob] sent:",e.batch.length,"events"),!0;if(r.status>=400&&r.status<500)return t.debug&&console.warn("[IndieBob] 4xx error, not retrying:",r.status),!1}catch(r){t.debug&&console.warn("[IndieBob] fetch error (attempt",i+1,"):",r);}i<2&&(yield It(bt[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var T="_ib_queue",St=10,Et=5e3,_t=50,v=class{constructor(t){this.queue=[];this.timer=null;this.flushing=false;this.config=t,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(t){this.queue.push(t),this.queue.length>=St&&this.flush();}flush(t=false){return l(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let n=this.queue.splice(0);(yield w({batch:n},this.config,t))||this.pushToOfflineQueue(n),this.flushing=false;})}flushOfflineQueue(){return l(this,null,function*(){let t=this.getOfflineQueue();if(t.length===0)return;this.clearOfflineQueue(),yield w({batch:t},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},Et);}setupVisibilityFlush(){typeof document!="undefined"&&(document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(true);},{passive:true}),window.addEventListener("pagehide",()=>{this.flush(true);},{passive:true}));}setupOnlineFlush(){typeof window!="undefined"&&(window.addEventListener("online",()=>{this.flushOfflineQueue();}),navigator.onLine&&this.flushOfflineQueue());}pushToOfflineQueue(t){try{let i=[...this.getOfflineQueue(),...t].slice(-_t);localStorage.setItem(T,JSON.stringify(i));}catch(n){}}getOfflineQueue(){try{let t=localStorage.getItem(T);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(T);}catch(t){}}};function W(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function Z(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}var wt=/^https?:\/\/[^/]*(stripe\.com|paypal\.com|paddle\.com|lemonsqueezy\.com|gumroad\.com)(\/|$)/i;function k(e){var x,A,P,C,D,N;let t=typeof window=="undefined",n=(x=e==null?void 0:e.path)!=null?x:t?"":window.location.pathname+window.location.search,o=t?"":window.location.href,i=(A=e==null?void 0:e.title)!=null?A:t?"":document.title,r=(P=e==null?void 0:e.referrer)!=null?P:t?"":document.referrer,c=!t&&(r===""||wt.test(r))&&(C=Q())!=null?C:r,s=Z(),a=W(),u=t?void 0:(D=z(window.location.search))!=null?D:V();return {page:{path:n,url:o,title:i,referrer:c},device:L(p({},s),{type:a}),utm:u,locale:t?"en":navigator.language,timezone:t?"UTC":(N=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?N:"UTC",sdkVersion:"0.2.3"}}function tt(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),n=history.replaceState.bind(history);return history.pushState=function(...o){t(...o),e();},history.replaceState=function(...o){n(...o);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=n,window.removeEventListener("popstate",e);}}var Tt={signup:[/\/(sign-?up|register|join|create-?account|get-?started|onboard|registro|inscription|s-?inscrire|anmeldung|registrieren|cadastro|registrazione|aanmelden|inschrijven)/i],login:[/\/(log-?in|sign-?in|auth(\/login)?|iniciar-?sesion|connexion|se-?connecter|anmelden|einloggen|entrar|accesso|accedi|inloggen)/i],pricing:[/\/(pricing|plans|upgrade|subscribe|precios|tarifs|preise|precos|prezzi|prijzen)/i],checkout:[/\/(checkout|cart|basket|pay(ment)?|order|comprar|pagar|panier|caisse|warenkorb|kasse|carrinho|carrello|winkelwagen)/i],success:[/\/(success|thank-?you|thanks|confirmation|confirmed|complete[d]?|gracias|merci|danke|obrigado|grazie|bedankt)/i],onboarding:[/\/(onboarding|welcome|getting-?started|setup|bienvenido|bienvenue|willkommen|benvenuto|welkom)/i],contact:[/\/(contact|contacto|kontakt|contato|contatto|nous-?contacter)/i]},et={signup:"signup_start",login:"login_view",pricing:"pricing_view",checkout:"checkout_view",success:"success_view",onboarding:"onboarding_view",contact:"contact_view"};function kt(e,t){return e instanceof RegExp?e.test(t):t.includes(e)}function nt(e,t){var n;for(let o of Object.keys(et))if(((n=t==null?void 0:t[o])!=null?n:Tt[o]).some(r=>kt(r,e)))return et[o];return null}function ot(e){return e==="signup_start"?"signup_submit":e==="login_view"?"login_submit":e==="checkout_view"?"checkout_submit":null}function it(e,t){if(typeof document=="undefined")return ()=>{};let n=o=>{o.target instanceof HTMLFormElement&&t(e);};return document.addEventListener("submit",n,true),()=>document.removeEventListener("submit",n,true)}var R="ib_identified";function rt(){return typeof localStorage=="undefined"?true:!localStorage.getItem(R)}function st(){typeof localStorage!="undefined"&&localStorage.setItem(R,"1");}function at(){typeof localStorage!="undefined"&&localStorage.removeItem(R);}var ct="data-ib-event",ut="data-ib-";function lt(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){let i=o.getAttribute(ct);if(i){let r={auto:true};for(let c of o.attributes)if(c.name.startsWith(ut)&&c.name!==ct){let s=c.name.slice(ut.length);r[s]=c.value;}e(i,r);return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}function dt(e){if(typeof document=="undefined")return ()=>{};let t=n=>{let o=n.target;for(;o&&o!==document.body;){if(o.tagName==="A"){let i=o.href;if(!i||!/^https?:\/\//.test(i))return;try{let r=new URL(i);r.hostname!==window.location.hostname&&e("outbound_click",{auto:!0,url:i,hostname:r.hostname});}catch(r){}return}o=o.parentElement;}};return document.addEventListener("click",t,true),()=>document.removeEventListener("click",t,true)}var y=class e{constructor(t){this.cleanupHistory=null;this.cleanupAttributes=null;this.cleanupOutbound=null;this.cleanupFormSubmit=null;if(this.config=t,this.queue=new v(t),typeof window!="undefined"&&(K(window.location.search,document.referrer),t.autoDetect!==false)){let n=typeof t.autoDetect=="object"?t.autoDetect:{};n.dataAttributes!==false&&(this.cleanupAttributes=lt((o,i)=>this.track(o,i))),n.outboundClicks!==false&&(this.cleanupOutbound=dt((o,i)=>this.track(o,i)));}}static init(t){let n=M(t);return new e(n)}page(t){var o;if(!f(this.config))return;let n=k(t);if(this.queue.push(this.buildEvent("page",{context:n})),this.config.autoDetect!==false){let i=n.page.path,r=typeof this.config.autoDetect=="object"?this.config.autoDetect:{},c={signup:r.signupPaths,login:r.loginPaths,pricing:r.pricingPaths,checkout:r.checkoutPaths,success:r.successPaths,onboarding:r.onboardingPaths,contact:r.contactPaths},s=nt(i,c);if(s&&(this.queue.push(this.buildEvent("track",{event:s,properties:{auto:true},context:n})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${s} on ${i}`),r.formSubmit!==false)){(o=this.cleanupFormSubmit)==null||o.call(this);let a=ot(s);a&&(this.cleanupFormSubmit=it(a,u=>{this.queue.push(this.buildEvent("track",{event:u,properties:{auto:true}})),this.config.debug&&console.log(`[IndieBob] auto-detected: ${u}`);}));}}}track(t,n){f(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:n}));}identify(t,n){if(f(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:n,userId:t})),this.config.autoDetect!==false)){let o=rt(),i=o?"signup":"login";this.queue.push(this.buildEvent("track",{event:i,properties:{auto:true}})),o&&st(),this.config.debug&&console.log(`[IndieBob] auto-detected: ${i} for ${t}`);}}revenue(t){var n;f(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(n=t.currency)!=null?n:"USD",plan:t.plan,type:t.type}}));}optOut(){var t,n,o;this.queue.flush(),$(),at(),this.userId=void 0,(t=this.cleanupAttributes)==null||t.call(this),(n=this.cleanupOutbound)==null||n.call(this),(o=this.cleanupFormSubmit)==null||o.call(this),this.cleanupAttributes=null,this.cleanupOutbound=null,this.cleanupFormSubmit=null,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){J(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return G()}flush(){return l(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return I()}getSessionId(){return _()}getConfig(){return Object.freeze(p({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=tt(()=>this.page()),()=>{var n;(n=this.cleanupHistory)==null||n.call(this),this.cleanupHistory=null;}}buildEvent(t,n){var o,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:I(),userId:(o=this.userId)!=null?o:n.userId,sessionId:_(),timestamp:new Date().toISOString(),context:(i=n.context)!=null?i:k(),event:n.event,properties:n.properties,traits:n.traits,revenue:n.revenue}}};var Rt=Symbol("indiebob"),O=null,de={install(e,t){let n=y.init(t);O=n,e.provide(Rt,n),e.config.globalProperties.$bob=n;let o=e.config.globalProperties.$router;o&&o.afterEach(()=>{n.page();});}};function fe(){if(O)return O;throw new Error("[IndieBob] useTracker() called before IndieBobPlugin was installed.")}
2
+ export{y as IndieBob,de as IndieBobPlugin,fe as useTracker};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indiebob/tracker",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Privacy-first analytics SDK for web applications. <5KB gzipped. No cookies.",
5
5
  "private": false,
6
6
  "license": "MIT",
@@ -45,13 +45,6 @@
45
45
  "README.md",
46
46
  "CHANGELOG.md"
47
47
  ],
48
- "scripts": {
49
- "build": "tsup && node scripts/flatten-global.mjs",
50
- "dev": "tsup --watch",
51
- "type-check": "tsc --noEmit",
52
- "cdn:publish": "tsx scripts/publish-cdn.mts",
53
- "prepublishOnly": "pnpm run build"
54
- },
55
48
  "devDependencies": {
56
49
  "@aws-sdk/client-s3": "^3.1000.0",
57
50
  "@types/node": "^22.0.0",
@@ -73,5 +66,11 @@
73
66
  "vue-router": {
74
67
  "optional": true
75
68
  }
69
+ },
70
+ "scripts": {
71
+ "build": "tsup && node scripts/flatten-global.mjs",
72
+ "dev": "tsup --watch",
73
+ "type-check": "tsc --noEmit",
74
+ "cdn:publish": "tsx scripts/publish-cdn.mts"
76
75
  }
77
- }
76
+ }