@indiebob/tracker 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -1
- package/README.md +10 -10
- package/dist/index.cjs +1 -1
- package/dist/index.d.mts +14 -14
- package/dist/index.d.ts +14 -14
- package/dist/index.global.js +3 -2
- package/dist/index.js +1 -1
- package/dist/server.d.mts +7 -7
- package/dist/server.d.ts +7 -7
- package/dist/server.js +1 -1
- package/dist/server.mjs +1 -1
- package/dist/vue.cjs +2 -2
- package/dist/vue.global.js +3 -2
- package/dist/vue.js +2 -2
- package/package.json +9 -8
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,19 @@ This project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [0.2.1] — 2026-08-24
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- **Script-tag global is the class again.** The IIFE bundles wrapped exports
|
|
13
|
+
in a namespace — `window.IndieBob` was `{ IndieBob: class }` — while the
|
|
14
|
+
documented snippet calls `IndieBob.init(...)`. Every script-tag user
|
|
15
|
+
following the docs got a `TypeError` on page load; found live on
|
|
16
|
+
maimu.app, where the tracker had silently never initialized. The global
|
|
17
|
+
is now the class itself (verified: `typeof window.IndieBob === 'function'`,
|
|
18
|
+
`IndieBob.init` callable).
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
9
22
|
## [0.2.0] — 2026-03-09
|
|
10
23
|
|
|
11
24
|
### Added
|
|
@@ -25,7 +38,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
25
38
|
|
|
26
39
|
---
|
|
27
40
|
|
|
28
|
-
## [1.0
|
|
41
|
+
## [0.1.0] — 2026-02-24
|
|
42
|
+
|
|
43
|
+
> (This heading previously mislabeled the release as 1.0.0 — npm history is 0.1.0 → 0.1.1 → 0.2.0.)
|
|
29
44
|
|
|
30
45
|
### Added
|
|
31
46
|
- `IndieBob.init()` factory — creates a tracker instance with config validation
|
package/README.md
CHANGED
|
@@ -208,9 +208,9 @@ Override the default URL patterns or disable specific features:
|
|
|
208
208
|
const bob = IndieBob.init({
|
|
209
209
|
projectId: 'proj_abc123',
|
|
210
210
|
autoDetect: {
|
|
211
|
-
// Custom URL patterns (override defaults)
|
|
212
|
-
signupPaths: [
|
|
213
|
-
checkoutPaths: [/\/buy|\/purchase/i],
|
|
211
|
+
// Custom URL patterns — strings or RegExp (override defaults)
|
|
212
|
+
signupPaths: ['/my-signup-page'], // string: matched via path.includes()
|
|
213
|
+
checkoutPaths: [/\/buy|\/purchase/i], // RegExp: matched via .test()
|
|
214
214
|
|
|
215
215
|
// Disable specific features
|
|
216
216
|
outboundClicks: false,
|
|
@@ -224,13 +224,13 @@ Set `autoDetect: false` to disable all auto-detection entirely.
|
|
|
224
224
|
|
|
225
225
|
| Option | Type | Default | Description |
|
|
226
226
|
|---|---|---|---|
|
|
227
|
-
| `signupPaths` | `RegExp[]` | built-in i18n | URL patterns for signup pages |
|
|
228
|
-
| `loginPaths` | `RegExp[]` | built-in i18n | URL patterns for login pages |
|
|
229
|
-
| `pricingPaths` | `RegExp[]` | built-in i18n | URL patterns for pricing pages |
|
|
230
|
-
| `checkoutPaths` | `RegExp[]` | built-in i18n | URL patterns for checkout/cart pages |
|
|
231
|
-
| `successPaths` | `RegExp[]` | built-in i18n | URL patterns for success/thank-you pages |
|
|
232
|
-
| `onboardingPaths` | `RegExp[]` | built-in i18n | URL patterns for onboarding pages |
|
|
233
|
-
| `contactPaths` | `RegExp[]` | built-in i18n | URL patterns for contact pages |
|
|
227
|
+
| `signupPaths` | `(string \| RegExp)[]` | built-in i18n | URL patterns for signup pages |
|
|
228
|
+
| `loginPaths` | `(string \| RegExp)[]` | built-in i18n | URL patterns for login pages |
|
|
229
|
+
| `pricingPaths` | `(string \| RegExp)[]` | built-in i18n | URL patterns for pricing pages |
|
|
230
|
+
| `checkoutPaths` | `(string \| RegExp)[]` | built-in i18n | URL patterns for checkout/cart pages |
|
|
231
|
+
| `successPaths` | `(string \| RegExp)[]` | built-in i18n | URL patterns for success/thank-you pages |
|
|
232
|
+
| `onboardingPaths` | `(string \| RegExp)[]` | built-in i18n | URL patterns for onboarding pages |
|
|
233
|
+
| `contactPaths` | `(string \| RegExp)[]` | built-in i18n | URL patterns for contact pages |
|
|
234
234
|
| `dataAttributes` | `boolean` | `true` | Track clicks on `data-ib-event` elements |
|
|
235
235
|
| `formSubmit` | `boolean` | `true` | Track form submissions on intent pages |
|
|
236
236
|
| `outboundClicks` | `boolean` | `true` | Track clicks on external links |
|
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.0"}}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 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=>r.test(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}}};
|
|
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
2
|
exports.IndieBob=rt;
|
package/dist/index.d.mts
CHANGED
|
@@ -29,13 +29,13 @@ interface TrackerConfig {
|
|
|
29
29
|
* }
|
|
30
30
|
*/
|
|
31
31
|
autoDetect?: boolean | {
|
|
32
|
-
signupPaths?: RegExp[];
|
|
33
|
-
loginPaths?: RegExp[];
|
|
34
|
-
pricingPaths?: RegExp[];
|
|
35
|
-
checkoutPaths?: RegExp[];
|
|
36
|
-
successPaths?: RegExp[];
|
|
37
|
-
onboardingPaths?: RegExp[];
|
|
38
|
-
contactPaths?: RegExp[];
|
|
32
|
+
signupPaths?: (string | RegExp)[];
|
|
33
|
+
loginPaths?: (string | RegExp)[];
|
|
34
|
+
pricingPaths?: (string | RegExp)[];
|
|
35
|
+
checkoutPaths?: (string | RegExp)[];
|
|
36
|
+
successPaths?: (string | RegExp)[];
|
|
37
|
+
onboardingPaths?: (string | RegExp)[];
|
|
38
|
+
contactPaths?: (string | RegExp)[];
|
|
39
39
|
/** Track clicks on elements with data-ib-event attribute. Default: true */
|
|
40
40
|
dataAttributes?: boolean;
|
|
41
41
|
/** Track form submissions on intent pages (signup/login/checkout). Default: true */
|
|
@@ -52,13 +52,13 @@ interface ResolvedConfig {
|
|
|
52
52
|
respectDnt: boolean;
|
|
53
53
|
respectGpc: boolean;
|
|
54
54
|
autoDetect: boolean | {
|
|
55
|
-
signupPaths?: RegExp[];
|
|
56
|
-
loginPaths?: RegExp[];
|
|
57
|
-
pricingPaths?: RegExp[];
|
|
58
|
-
checkoutPaths?: RegExp[];
|
|
59
|
-
successPaths?: RegExp[];
|
|
60
|
-
onboardingPaths?: RegExp[];
|
|
61
|
-
contactPaths?: RegExp[];
|
|
55
|
+
signupPaths?: (string | RegExp)[];
|
|
56
|
+
loginPaths?: (string | RegExp)[];
|
|
57
|
+
pricingPaths?: (string | RegExp)[];
|
|
58
|
+
checkoutPaths?: (string | RegExp)[];
|
|
59
|
+
successPaths?: (string | RegExp)[];
|
|
60
|
+
onboardingPaths?: (string | RegExp)[];
|
|
61
|
+
contactPaths?: (string | RegExp)[];
|
|
62
62
|
dataAttributes?: boolean;
|
|
63
63
|
formSubmit?: boolean;
|
|
64
64
|
outboundClicks?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -29,13 +29,13 @@ interface TrackerConfig {
|
|
|
29
29
|
* }
|
|
30
30
|
*/
|
|
31
31
|
autoDetect?: boolean | {
|
|
32
|
-
signupPaths?: RegExp[];
|
|
33
|
-
loginPaths?: RegExp[];
|
|
34
|
-
pricingPaths?: RegExp[];
|
|
35
|
-
checkoutPaths?: RegExp[];
|
|
36
|
-
successPaths?: RegExp[];
|
|
37
|
-
onboardingPaths?: RegExp[];
|
|
38
|
-
contactPaths?: RegExp[];
|
|
32
|
+
signupPaths?: (string | RegExp)[];
|
|
33
|
+
loginPaths?: (string | RegExp)[];
|
|
34
|
+
pricingPaths?: (string | RegExp)[];
|
|
35
|
+
checkoutPaths?: (string | RegExp)[];
|
|
36
|
+
successPaths?: (string | RegExp)[];
|
|
37
|
+
onboardingPaths?: (string | RegExp)[];
|
|
38
|
+
contactPaths?: (string | RegExp)[];
|
|
39
39
|
/** Track clicks on elements with data-ib-event attribute. Default: true */
|
|
40
40
|
dataAttributes?: boolean;
|
|
41
41
|
/** Track form submissions on intent pages (signup/login/checkout). Default: true */
|
|
@@ -52,13 +52,13 @@ interface ResolvedConfig {
|
|
|
52
52
|
respectDnt: boolean;
|
|
53
53
|
respectGpc: boolean;
|
|
54
54
|
autoDetect: boolean | {
|
|
55
|
-
signupPaths?: RegExp[];
|
|
56
|
-
loginPaths?: RegExp[];
|
|
57
|
-
pricingPaths?: RegExp[];
|
|
58
|
-
checkoutPaths?: RegExp[];
|
|
59
|
-
successPaths?: RegExp[];
|
|
60
|
-
onboardingPaths?: RegExp[];
|
|
61
|
-
contactPaths?: RegExp[];
|
|
55
|
+
signupPaths?: (string | RegExp)[];
|
|
56
|
+
loginPaths?: (string | RegExp)[];
|
|
57
|
+
pricingPaths?: (string | RegExp)[];
|
|
58
|
+
checkoutPaths?: (string | RegExp)[];
|
|
59
|
+
successPaths?: (string | RegExp)[];
|
|
60
|
+
onboardingPaths?: (string | RegExp)[];
|
|
61
|
+
contactPaths?: (string | RegExp)[];
|
|
62
62
|
dataAttributes?: boolean;
|
|
63
63
|
formSubmit?: boolean;
|
|
64
64
|
outboundClicks?: boolean;
|
package/dist/index.global.js
CHANGED
|
@@ -1,2 +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.0"}}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 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=>r.test(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 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;})({});
|
|
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.0"}}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 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=>r.test(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}}};
|
|
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
2
|
export{rt as IndieBob};
|
package/dist/server.d.mts
CHANGED
|
@@ -29,13 +29,13 @@ interface TrackerConfig {
|
|
|
29
29
|
* }
|
|
30
30
|
*/
|
|
31
31
|
autoDetect?: boolean | {
|
|
32
|
-
signupPaths?: RegExp[];
|
|
33
|
-
loginPaths?: RegExp[];
|
|
34
|
-
pricingPaths?: RegExp[];
|
|
35
|
-
checkoutPaths?: RegExp[];
|
|
36
|
-
successPaths?: RegExp[];
|
|
37
|
-
onboardingPaths?: RegExp[];
|
|
38
|
-
contactPaths?: RegExp[];
|
|
32
|
+
signupPaths?: (string | RegExp)[];
|
|
33
|
+
loginPaths?: (string | RegExp)[];
|
|
34
|
+
pricingPaths?: (string | RegExp)[];
|
|
35
|
+
checkoutPaths?: (string | RegExp)[];
|
|
36
|
+
successPaths?: (string | RegExp)[];
|
|
37
|
+
onboardingPaths?: (string | RegExp)[];
|
|
38
|
+
contactPaths?: (string | RegExp)[];
|
|
39
39
|
/** Track clicks on elements with data-ib-event attribute. Default: true */
|
|
40
40
|
dataAttributes?: boolean;
|
|
41
41
|
/** Track form submissions on intent pages (signup/login/checkout). Default: true */
|
package/dist/server.d.ts
CHANGED
|
@@ -29,13 +29,13 @@ interface TrackerConfig {
|
|
|
29
29
|
* }
|
|
30
30
|
*/
|
|
31
31
|
autoDetect?: boolean | {
|
|
32
|
-
signupPaths?: RegExp[];
|
|
33
|
-
loginPaths?: RegExp[];
|
|
34
|
-
pricingPaths?: RegExp[];
|
|
35
|
-
checkoutPaths?: RegExp[];
|
|
36
|
-
successPaths?: RegExp[];
|
|
37
|
-
onboardingPaths?: RegExp[];
|
|
38
|
-
contactPaths?: RegExp[];
|
|
32
|
+
signupPaths?: (string | RegExp)[];
|
|
33
|
+
loginPaths?: (string | RegExp)[];
|
|
34
|
+
pricingPaths?: (string | RegExp)[];
|
|
35
|
+
checkoutPaths?: (string | RegExp)[];
|
|
36
|
+
successPaths?: (string | RegExp)[];
|
|
37
|
+
onboardingPaths?: (string | RegExp)[];
|
|
38
|
+
contactPaths?: (string | RegExp)[];
|
|
39
39
|
/** Track clicks on elements with data-ib-event attribute. Default: true */
|
|
40
40
|
dataAttributes?: boolean;
|
|
41
41
|
/** Track form submissions on intent pages (signup/login/checkout). Default: true */
|
package/dist/server.js
CHANGED
package/dist/server.mjs
CHANGED
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.0"}}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 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=>r.test(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 It=Symbol("indiebob"),O=null,ie={install(e,t){let n=h.init(t);O=n,e.provide(It,n),e.config.globalProperties.$bob=n;let o=e.config.globalProperties.$router;o&&o.afterEach(()=>{n.page();});}};function re(){if(O)return O;throw new Error("[IndieBob] useTracker() called before IndieBobPlugin was installed.")}
|
|
2
|
-
exports.IndieBob=h;exports.IndieBobPlugin=
|
|
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;
|
package/dist/vue.global.js
CHANGED
|
@@ -1,2 +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.0"}}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 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=>r.test(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 It=Symbol("indiebob"),O=null,ie={install(e,t){let n=h.init(t);O=n,e.provide(It,n),e.config.globalProperties.$bob=n;let o=e.config.globalProperties.$router;o&&o.afterEach(()=>{n.page();});}};function re(){if(O)return O;throw new Error("[IndieBob] useTracker() called before IndieBobPlugin was installed.")}
|
|
2
|
-
exports.IndieBob=h;exports.IndieBobPlugin=
|
|
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;})({});
|
|
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.0"}}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 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=>r.test(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 It=Symbol("indiebob"),O=null,ie={install(e,t){let n=h.init(t);O=n,e.provide(It,n),e.config.globalProperties.$bob=n;let o=e.config.globalProperties.$router;o&&o.afterEach(()=>{n.page();});}};function re(){if(O)return O;throw new Error("[IndieBob] useTracker() called before IndieBobPlugin was installed.")}
|
|
2
|
-
export{h as IndieBob,
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indiebob/tracker",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Privacy-first analytics SDK for web applications. <5KB gzipped. No cookies.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,6 +45,13 @@
|
|
|
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
|
+
},
|
|
48
55
|
"devDependencies": {
|
|
49
56
|
"@aws-sdk/client-s3": "^3.1000.0",
|
|
50
57
|
"@types/node": "^22.0.0",
|
|
@@ -66,11 +73,5 @@
|
|
|
66
73
|
"vue-router": {
|
|
67
74
|
"optional": true
|
|
68
75
|
}
|
|
69
|
-
},
|
|
70
|
-
"scripts": {
|
|
71
|
-
"build": "tsup",
|
|
72
|
-
"dev": "tsup --watch",
|
|
73
|
-
"type-check": "tsc --noEmit",
|
|
74
|
-
"cdn:publish": "tsx scripts/publish-cdn.mts"
|
|
75
76
|
}
|
|
76
|
-
}
|
|
77
|
+
}
|