@indiebob/tracker 0.1.0 → 0.1.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/dist/chunk-4IK5PET7.js +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.global.js +1 -1
- package/dist/index.js +1 -1
- package/dist/server.js +2 -2
- package/dist/server.mjs +2 -2
- package/dist/vue.cjs +1 -1
- package/dist/vue.global.js +1 -1
- package/dist/vue.js +1 -1
- package/package.json +8 -9
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var J=Object.defineProperty,z=Object.defineProperties;var G=Object.getOwnPropertyDescriptors;var k=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var A=(e,t,o)=>t in e?J(e,t,{enumerable:true,configurable:true,writable:true,value:o}):e[t]=o,d=(e,t)=>{for(var o in t||(t={}))W.call(t,o)&&A(e,o,t[o]);if(k)for(var o of k(t))Z.call(t,o)&&A(e,o,t[o]);return e},x=(e,t)=>z(e,G(t));var a=(e,t,o)=>new Promise((n,i)=>{var r=s=>{try{l(o.next(s));}catch(c){i(c);}},g=s=>{try{l(o.throw(s));}catch(c){i(c);}},l=s=>s.done?n(s.value):Promise.resolve(s.value).then(r,g);l((o=o.apply(e,t)).next());});var $="https://www.indiebob.com/api/collect";function D(e){var t,o,n,i;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:$,debug:(o=e.debug)!=null?o:false,respectDnt:(n=e.respectDnt)!=null?n:true,respectGpc:(i=e.respectGpc)!=null?i:true}}var u="_ib_anon";function h(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let o=new Uint8Array(21);crypto.getRandomValues(o);for(let n of o)t+=e[n%e.length];}else for(let o=0;o<21;o++)t+=e[Math.floor(Math.random()*e.length)];return t}function v(){try{let e=localStorage.getItem(u);return e||(e=h(),localStorage.setItem(u,e)),e}catch(e){try{let t=sessionStorage.getItem(u);return t||(t=h(),sessionStorage.setItem(u,t)),t}catch(t){return h()}}}function P(){try{localStorage.removeItem(u);}catch(e){}try{sessionStorage.removeItem(u);}catch(e){}}var y="_ib_session",I="_ib_session_last";function N(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function S(){var e;try{let t=Date.now(),o=parseInt((e=sessionStorage.getItem(I))!=null?e:"0",10),n=sessionStorage.getItem(y),i=o>0&&t-o>18e5;return (!n||i)&&(n=N(),sessionStorage.setItem(y,n)),sessionStorage.setItem(I,String(t)),n}catch(t){return N()}}function U(){try{sessionStorage.removeItem(y);}catch(e){}try{sessionStorage.removeItem(I);}catch(e){}}var b="_ib_first_utm",M="_ib_last_utm",_="_ib_referrer";function q(e){let t=new URLSearchParams(e),o={},n=false;return t.has("utm_source")&&(o.source=t.get("utm_source"),n=true),t.has("utm_medium")&&(o.medium=t.get("utm_medium"),n=true),t.has("utm_campaign")&&(o.campaign=t.get("utm_campaign"),n=true),t.has("utm_term")&&(o.term=t.get("utm_term"),n=true),t.has("utm_content")&&(o.content=t.get("utm_content"),n=true),n?o:null}function B(e,t){let o=q(e);try{o&&!localStorage.getItem(b)&&localStorage.setItem(b,JSON.stringify(o)),o&&localStorage.setItem(M,JSON.stringify(o)),t&&!localStorage.getItem(_)&&localStorage.setItem(_,t);}catch(n){}}function F(e){var t;return (t=q(e))!=null?t:void 0}function L(){try{localStorage.removeItem(b);}catch(e){}try{localStorage.removeItem(M);}catch(e){}try{localStorage.removeItem(_);}catch(e){}}var p="_ib_optout",tt="_ib_queue";function f(e){try{if(localStorage.getItem(p))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 j(){try{localStorage.setItem(p,"1");}catch(e){}P(),U(),L();try{localStorage.removeItem(tt);}catch(e){}}function Y(){try{localStorage.removeItem(p);}catch(e){}}function K(){try{return !!localStorage.getItem(p)}catch(e){return false}}var et=[1e3,2e3,4e3];function ot(e){return a(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function w(e,t,o=false){return a(this,null,function*(){let n=JSON.stringify(e);if(o&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([n],{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:n,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 ot(et[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var E="_ib_queue",nt=10,it=5e3,rt=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>=nt&&this.flush();}flush(t=false){return a(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let o=this.queue.splice(0);(yield w({batch:o},this.config,t))||this.pushToOfflineQueue(o),this.flushing=false;})}flushOfflineQueue(){return a(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();},it);}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(-rt);localStorage.setItem(E,JSON.stringify(i));}catch(o){}}getOfflineQueue(){try{let t=localStorage.getItem(E);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(E);}catch(t){}}};function Q(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function V(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}function T(e){var c,O,R,C;let t=typeof window=="undefined",o=(c=e==null?void 0:e.path)!=null?c:t?"":window.location.pathname+window.location.search,n=t?"":window.location.href,i=(O=e==null?void 0:e.title)!=null?O:t?"":document.title,r=(R=e==null?void 0:e.referrer)!=null?R:t?"":document.referrer,g=V(),l=Q(),s=t?void 0:F(window.location.search);return {page:{path:o,url:n,title:i,referrer:r},device:x(d({},g),{type:l}),utm:s,locale:t?"en":navigator.language,timezone:t?"UTC":(C=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?C:"UTC",sdkVersion:"0.1.1"}}function H(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),o=history.replaceState.bind(history);return history.pushState=function(...n){t(...n),e();},history.replaceState=function(...n){o(...n);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=o,window.removeEventListener("popstate",e);}}var X=class e{constructor(t){this.cleanupHistory=null;this.config=t,this.queue=new m(t),typeof window!="undefined"&&B(window.location.search,document.referrer);}static init(t){let o=D(t);return new e(o)}page(t){f(this.config)&&this.queue.push(this.buildEvent("page",{context:T(t)}));}track(t,o){f(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:o}));}identify(t,o){f(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:o,userId:t})));}revenue(t){var o;f(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(o=t.currency)!=null?o:"USD",plan:t.plan,type:t.type}}));}optOut(){this.queue.flush(),j(),this.userId=void 0,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){Y(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return K()}flush(){return a(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return v()}getSessionId(){return S()}getConfig(){return Object.freeze(d({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=H(()=>this.page()),()=>{var o;(o=this.cleanupHistory)==null||o.call(this),this.cleanupHistory=null;}}buildEvent(t,o){var n,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:v(),userId:(n=this.userId)!=null?n:o.userId,sessionId:S(),timestamp:new Date().toISOString(),context:(i=o.context)!=null?i:T(),event:o.event,properties:o.properties,traits:o.traits,revenue:o.revenue}}};
|
|
2
|
+
export{X as a};
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var J=Object.defineProperty,z=Object.defineProperties;var G=Object.getOwnPropertyDescriptors;var k=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var A=(e,t,o)=>t in e?J(e,t,{enumerable:true,configurable:true,writable:true,value:o}):e[t]=o,d=(e,t)=>{for(var o in t||(t={}))W.call(t,o)&&A(e,o,t[o]);if(k)for(var o of k(t))Z.call(t,o)&&A(e,o,t[o]);return e},x=(e,t)=>z(e,G(t));var a=(e,t,o)=>new Promise((n,i)=>{var r=s=>{try{l(o.next(s));}catch(c){i(c);}},g=s=>{try{l(o.throw(s));}catch(c){i(c);}},l=s=>s.done?n(s.value):Promise.resolve(s.value).then(r,g);l((o=o.apply(e,t)).next());});var $="https://indiebob.com/api/collect";function D(e){var t,o,n,i;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:$,debug:(o=e.debug)!=null?o:false,respectDnt:(n=e.respectDnt)!=null?n:true,respectGpc:(i=e.respectGpc)!=null?i:true}}var u="_ib_anon";function h(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let o=new Uint8Array(21);crypto.getRandomValues(o);for(let n of o)t+=e[n%e.length];}else for(let o=0;o<21;o++)t+=e[Math.floor(Math.random()*e.length)];return t}function v(){try{let e=localStorage.getItem(u);return e||(e=h(),localStorage.setItem(u,e)),e}catch(e){try{let t=sessionStorage.getItem(u);return t||(t=h(),sessionStorage.setItem(u,t)),t}catch(t){return h()}}}function P(){try{localStorage.removeItem(u);}catch(e){}try{sessionStorage.removeItem(u);}catch(e){}}var y="_ib_session",I="_ib_session_last";function N(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function S(){var e;try{let t=Date.now(),o=parseInt((e=sessionStorage.getItem(I))!=null?e:"0",10),n=sessionStorage.getItem(y),i=o>0&&t-o>18e5;return (!n||i)&&(n=N(),sessionStorage.setItem(y,n)),sessionStorage.setItem(I,String(t)),n}catch(t){return N()}}function U(){try{sessionStorage.removeItem(y);}catch(e){}try{sessionStorage.removeItem(I);}catch(e){}}var b="_ib_first_utm",M="_ib_last_utm",_="_ib_referrer";function q(e){let t=new URLSearchParams(e),o={},n=false;return t.has("utm_source")&&(o.source=t.get("utm_source"),n=true),t.has("utm_medium")&&(o.medium=t.get("utm_medium"),n=true),t.has("utm_campaign")&&(o.campaign=t.get("utm_campaign"),n=true),t.has("utm_term")&&(o.term=t.get("utm_term"),n=true),t.has("utm_content")&&(o.content=t.get("utm_content"),n=true),n?o:null}function B(e,t){let o=q(e);try{o&&!localStorage.getItem(b)&&localStorage.setItem(b,JSON.stringify(o)),o&&localStorage.setItem(M,JSON.stringify(o)),t&&!localStorage.getItem(_)&&localStorage.setItem(_,t);}catch(n){}}function F(e){var t;return (t=q(e))!=null?t:void 0}function L(){try{localStorage.removeItem(b);}catch(e){}try{localStorage.removeItem(M);}catch(e){}try{localStorage.removeItem(_);}catch(e){}}var p="_ib_optout",tt="_ib_queue";function f(e){try{if(localStorage.getItem(p))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 j(){try{localStorage.setItem(p,"1");}catch(e){}P(),U(),L();try{localStorage.removeItem(tt);}catch(e){}}function Y(){try{localStorage.removeItem(p);}catch(e){}}function K(){try{return !!localStorage.getItem(p)}catch(e){return false}}var et=[1e3,2e3,4e3];function ot(e){return a(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function w(e,t,o=false){return a(this,null,function*(){let n=JSON.stringify(e);if(o&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([n],{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:n,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 ot(et[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var E="_ib_queue",nt=10,it=5e3,rt=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>=nt&&this.flush();}flush(t=false){return a(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let o=this.queue.splice(0);(yield w({batch:o},this.config,t))||this.pushToOfflineQueue(o),this.flushing=false;})}flushOfflineQueue(){return a(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();},it);}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(-rt);localStorage.setItem(E,JSON.stringify(i));}catch(o){}}getOfflineQueue(){try{let t=localStorage.getItem(E);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(E);}catch(t){}}};function Q(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function V(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}function T(e){var c,O,R,C;let t=typeof window=="undefined",o=(c=e==null?void 0:e.path)!=null?c:t?"":window.location.pathname+window.location.search,n=t?"":window.location.href,i=(O=e==null?void 0:e.title)!=null?O:t?"":document.title,r=(R=e==null?void 0:e.referrer)!=null?R:t?"":document.referrer,g=V(),l=Q(),s=t?void 0:F(window.location.search);return {page:{path:o,url:n,title:i,referrer:r},device:x(d({},g),{type:l}),utm:s,locale:t?"en":navigator.language,timezone:t?"UTC":(C=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?C:"UTC",sdkVersion:"0.1.
|
|
1
|
+
'use strict';var J=Object.defineProperty,z=Object.defineProperties;var G=Object.getOwnPropertyDescriptors;var k=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var A=(e,t,o)=>t in e?J(e,t,{enumerable:true,configurable:true,writable:true,value:o}):e[t]=o,d=(e,t)=>{for(var o in t||(t={}))W.call(t,o)&&A(e,o,t[o]);if(k)for(var o of k(t))Z.call(t,o)&&A(e,o,t[o]);return e},x=(e,t)=>z(e,G(t));var a=(e,t,o)=>new Promise((n,i)=>{var r=s=>{try{l(o.next(s));}catch(c){i(c);}},g=s=>{try{l(o.throw(s));}catch(c){i(c);}},l=s=>s.done?n(s.value):Promise.resolve(s.value).then(r,g);l((o=o.apply(e,t)).next());});var $="https://www.indiebob.com/api/collect";function D(e){var t,o,n,i;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:$,debug:(o=e.debug)!=null?o:false,respectDnt:(n=e.respectDnt)!=null?n:true,respectGpc:(i=e.respectGpc)!=null?i:true}}var u="_ib_anon";function h(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let o=new Uint8Array(21);crypto.getRandomValues(o);for(let n of o)t+=e[n%e.length];}else for(let o=0;o<21;o++)t+=e[Math.floor(Math.random()*e.length)];return t}function v(){try{let e=localStorage.getItem(u);return e||(e=h(),localStorage.setItem(u,e)),e}catch(e){try{let t=sessionStorage.getItem(u);return t||(t=h(),sessionStorage.setItem(u,t)),t}catch(t){return h()}}}function P(){try{localStorage.removeItem(u);}catch(e){}try{sessionStorage.removeItem(u);}catch(e){}}var y="_ib_session",I="_ib_session_last";function N(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function S(){var e;try{let t=Date.now(),o=parseInt((e=sessionStorage.getItem(I))!=null?e:"0",10),n=sessionStorage.getItem(y),i=o>0&&t-o>18e5;return (!n||i)&&(n=N(),sessionStorage.setItem(y,n)),sessionStorage.setItem(I,String(t)),n}catch(t){return N()}}function U(){try{sessionStorage.removeItem(y);}catch(e){}try{sessionStorage.removeItem(I);}catch(e){}}var b="_ib_first_utm",M="_ib_last_utm",_="_ib_referrer";function q(e){let t=new URLSearchParams(e),o={},n=false;return t.has("utm_source")&&(o.source=t.get("utm_source"),n=true),t.has("utm_medium")&&(o.medium=t.get("utm_medium"),n=true),t.has("utm_campaign")&&(o.campaign=t.get("utm_campaign"),n=true),t.has("utm_term")&&(o.term=t.get("utm_term"),n=true),t.has("utm_content")&&(o.content=t.get("utm_content"),n=true),n?o:null}function B(e,t){let o=q(e);try{o&&!localStorage.getItem(b)&&localStorage.setItem(b,JSON.stringify(o)),o&&localStorage.setItem(M,JSON.stringify(o)),t&&!localStorage.getItem(_)&&localStorage.setItem(_,t);}catch(n){}}function F(e){var t;return (t=q(e))!=null?t:void 0}function L(){try{localStorage.removeItem(b);}catch(e){}try{localStorage.removeItem(M);}catch(e){}try{localStorage.removeItem(_);}catch(e){}}var p="_ib_optout",tt="_ib_queue";function f(e){try{if(localStorage.getItem(p))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 j(){try{localStorage.setItem(p,"1");}catch(e){}P(),U(),L();try{localStorage.removeItem(tt);}catch(e){}}function Y(){try{localStorage.removeItem(p);}catch(e){}}function K(){try{return !!localStorage.getItem(p)}catch(e){return false}}var et=[1e3,2e3,4e3];function ot(e){return a(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function w(e,t,o=false){return a(this,null,function*(){let n=JSON.stringify(e);if(o&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([n],{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:n,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 ot(et[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var E="_ib_queue",nt=10,it=5e3,rt=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>=nt&&this.flush();}flush(t=false){return a(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let o=this.queue.splice(0);(yield w({batch:o},this.config,t))||this.pushToOfflineQueue(o),this.flushing=false;})}flushOfflineQueue(){return a(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();},it);}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(-rt);localStorage.setItem(E,JSON.stringify(i));}catch(o){}}getOfflineQueue(){try{let t=localStorage.getItem(E);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(E);}catch(t){}}};function Q(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function V(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}function T(e){var c,O,R,C;let t=typeof window=="undefined",o=(c=e==null?void 0:e.path)!=null?c:t?"":window.location.pathname+window.location.search,n=t?"":window.location.href,i=(O=e==null?void 0:e.title)!=null?O:t?"":document.title,r=(R=e==null?void 0:e.referrer)!=null?R:t?"":document.referrer,g=V(),l=Q(),s=t?void 0:F(window.location.search);return {page:{path:o,url:n,title:i,referrer:r},device:x(d({},g),{type:l}),utm:s,locale:t?"en":navigator.language,timezone:t?"UTC":(C=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?C:"UTC",sdkVersion:"0.1.1"}}function H(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),o=history.replaceState.bind(history);return history.pushState=function(...n){t(...n),e();},history.replaceState=function(...n){o(...n);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=o,window.removeEventListener("popstate",e);}}var X=class e{constructor(t){this.cleanupHistory=null;this.config=t,this.queue=new m(t),typeof window!="undefined"&&B(window.location.search,document.referrer);}static init(t){let o=D(t);return new e(o)}page(t){f(this.config)&&this.queue.push(this.buildEvent("page",{context:T(t)}));}track(t,o){f(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:o}));}identify(t,o){f(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:o,userId:t})));}revenue(t){var o;f(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(o=t.currency)!=null?o:"USD",plan:t.plan,type:t.type}}));}optOut(){this.queue.flush(),j(),this.userId=void 0,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){Y(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return K()}flush(){return a(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return v()}getSessionId(){return S()}getConfig(){return Object.freeze(d({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=H(()=>this.page()),()=>{var o;(o=this.cleanupHistory)==null||o.call(this),this.cleanupHistory=null;}}buildEvent(t,o){var n,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:v(),userId:(n=this.userId)!=null?n:o.userId,sessionId:S(),timestamp:new Date().toISOString(),context:(i=o.context)!=null?i:T(),event:o.event,properties:o.properties,traits:o.traits,revenue:o.revenue}}};
|
|
2
2
|
exports.IndieBob=X;
|
package/dist/index.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var IndieBob=(function(exports){'use strict';var J=Object.defineProperty,z=Object.defineProperties;var G=Object.getOwnPropertyDescriptors;var k=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var A=(e,t,o)=>t in e?J(e,t,{enumerable:true,configurable:true,writable:true,value:o}):e[t]=o,d=(e,t)=>{for(var o in t||(t={}))W.call(t,o)&&A(e,o,t[o]);if(k)for(var o of k(t))Z.call(t,o)&&A(e,o,t[o]);return e},x=(e,t)=>z(e,G(t));var a=(e,t,o)=>new Promise((n,i)=>{var r=s=>{try{l(o.next(s));}catch(c){i(c);}},g=s=>{try{l(o.throw(s));}catch(c){i(c);}},l=s=>s.done?n(s.value):Promise.resolve(s.value).then(r,g);l((o=o.apply(e,t)).next());});var $="https://indiebob.com/api/collect";function D(e){var t,o,n,i;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:$,debug:(o=e.debug)!=null?o:false,respectDnt:(n=e.respectDnt)!=null?n:true,respectGpc:(i=e.respectGpc)!=null?i:true}}var u="_ib_anon";function h(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let o=new Uint8Array(21);crypto.getRandomValues(o);for(let n of o)t+=e[n%e.length];}else for(let o=0;o<21;o++)t+=e[Math.floor(Math.random()*e.length)];return t}function v(){try{let e=localStorage.getItem(u);return e||(e=h(),localStorage.setItem(u,e)),e}catch(e){try{let t=sessionStorage.getItem(u);return t||(t=h(),sessionStorage.setItem(u,t)),t}catch(t){return h()}}}function P(){try{localStorage.removeItem(u);}catch(e){}try{sessionStorage.removeItem(u);}catch(e){}}var y="_ib_session",I="_ib_session_last";function N(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function S(){var e;try{let t=Date.now(),o=parseInt((e=sessionStorage.getItem(I))!=null?e:"0",10),n=sessionStorage.getItem(y),i=o>0&&t-o>18e5;return (!n||i)&&(n=N(),sessionStorage.setItem(y,n)),sessionStorage.setItem(I,String(t)),n}catch(t){return N()}}function U(){try{sessionStorage.removeItem(y);}catch(e){}try{sessionStorage.removeItem(I);}catch(e){}}var b="_ib_first_utm",M="_ib_last_utm",_="_ib_referrer";function q(e){let t=new URLSearchParams(e),o={},n=false;return t.has("utm_source")&&(o.source=t.get("utm_source"),n=true),t.has("utm_medium")&&(o.medium=t.get("utm_medium"),n=true),t.has("utm_campaign")&&(o.campaign=t.get("utm_campaign"),n=true),t.has("utm_term")&&(o.term=t.get("utm_term"),n=true),t.has("utm_content")&&(o.content=t.get("utm_content"),n=true),n?o:null}function B(e,t){let o=q(e);try{o&&!localStorage.getItem(b)&&localStorage.setItem(b,JSON.stringify(o)),o&&localStorage.setItem(M,JSON.stringify(o)),t&&!localStorage.getItem(_)&&localStorage.setItem(_,t);}catch(n){}}function F(e){var t;return (t=q(e))!=null?t:void 0}function L(){try{localStorage.removeItem(b);}catch(e){}try{localStorage.removeItem(M);}catch(e){}try{localStorage.removeItem(_);}catch(e){}}var p="_ib_optout",tt="_ib_queue";function f(e){try{if(localStorage.getItem(p))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 j(){try{localStorage.setItem(p,"1");}catch(e){}P(),U(),L();try{localStorage.removeItem(tt);}catch(e){}}function Y(){try{localStorage.removeItem(p);}catch(e){}}function K(){try{return !!localStorage.getItem(p)}catch(e){return false}}var et=[1e3,2e3,4e3];function ot(e){return a(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function w(e,t,o=false){return a(this,null,function*(){let n=JSON.stringify(e);if(o&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([n],{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:n,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 ot(et[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var E="_ib_queue",nt=10,it=5e3,rt=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>=nt&&this.flush();}flush(t=false){return a(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let o=this.queue.splice(0);(yield w({batch:o},this.config,t))||this.pushToOfflineQueue(o),this.flushing=false;})}flushOfflineQueue(){return a(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();},it);}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(-rt);localStorage.setItem(E,JSON.stringify(i));}catch(o){}}getOfflineQueue(){try{let t=localStorage.getItem(E);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(E);}catch(t){}}};function Q(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function V(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}function T(e){var c,O,R,C;let t=typeof window=="undefined",o=(c=e==null?void 0:e.path)!=null?c:t?"":window.location.pathname+window.location.search,n=t?"":window.location.href,i=(O=e==null?void 0:e.title)!=null?O:t?"":document.title,r=(R=e==null?void 0:e.referrer)!=null?R:t?"":document.referrer,g=V(),l=Q(),s=t?void 0:F(window.location.search);return {page:{path:o,url:n,title:i,referrer:r},device:x(d({},g),{type:l}),utm:s,locale:t?"en":navigator.language,timezone:t?"UTC":(C=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?C:"UTC",sdkVersion:"0.1.
|
|
1
|
+
var IndieBob=(function(exports){'use strict';var J=Object.defineProperty,z=Object.defineProperties;var G=Object.getOwnPropertyDescriptors;var k=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var A=(e,t,o)=>t in e?J(e,t,{enumerable:true,configurable:true,writable:true,value:o}):e[t]=o,d=(e,t)=>{for(var o in t||(t={}))W.call(t,o)&&A(e,o,t[o]);if(k)for(var o of k(t))Z.call(t,o)&&A(e,o,t[o]);return e},x=(e,t)=>z(e,G(t));var a=(e,t,o)=>new Promise((n,i)=>{var r=s=>{try{l(o.next(s));}catch(c){i(c);}},g=s=>{try{l(o.throw(s));}catch(c){i(c);}},l=s=>s.done?n(s.value):Promise.resolve(s.value).then(r,g);l((o=o.apply(e,t)).next());});var $="https://www.indiebob.com/api/collect";function D(e){var t,o,n,i;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:$,debug:(o=e.debug)!=null?o:false,respectDnt:(n=e.respectDnt)!=null?n:true,respectGpc:(i=e.respectGpc)!=null?i:true}}var u="_ib_anon";function h(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",t="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let o=new Uint8Array(21);crypto.getRandomValues(o);for(let n of o)t+=e[n%e.length];}else for(let o=0;o<21;o++)t+=e[Math.floor(Math.random()*e.length)];return t}function v(){try{let e=localStorage.getItem(u);return e||(e=h(),localStorage.setItem(u,e)),e}catch(e){try{let t=sessionStorage.getItem(u);return t||(t=h(),sessionStorage.setItem(u,t)),t}catch(t){return h()}}}function P(){try{localStorage.removeItem(u);}catch(e){}try{sessionStorage.removeItem(u);}catch(e){}}var y="_ib_session",I="_ib_session_last";function N(){try{return crypto.randomUUID()}catch(e){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function S(){var e;try{let t=Date.now(),o=parseInt((e=sessionStorage.getItem(I))!=null?e:"0",10),n=sessionStorage.getItem(y),i=o>0&&t-o>18e5;return (!n||i)&&(n=N(),sessionStorage.setItem(y,n)),sessionStorage.setItem(I,String(t)),n}catch(t){return N()}}function U(){try{sessionStorage.removeItem(y);}catch(e){}try{sessionStorage.removeItem(I);}catch(e){}}var b="_ib_first_utm",M="_ib_last_utm",_="_ib_referrer";function q(e){let t=new URLSearchParams(e),o={},n=false;return t.has("utm_source")&&(o.source=t.get("utm_source"),n=true),t.has("utm_medium")&&(o.medium=t.get("utm_medium"),n=true),t.has("utm_campaign")&&(o.campaign=t.get("utm_campaign"),n=true),t.has("utm_term")&&(o.term=t.get("utm_term"),n=true),t.has("utm_content")&&(o.content=t.get("utm_content"),n=true),n?o:null}function B(e,t){let o=q(e);try{o&&!localStorage.getItem(b)&&localStorage.setItem(b,JSON.stringify(o)),o&&localStorage.setItem(M,JSON.stringify(o)),t&&!localStorage.getItem(_)&&localStorage.setItem(_,t);}catch(n){}}function F(e){var t;return (t=q(e))!=null?t:void 0}function L(){try{localStorage.removeItem(b);}catch(e){}try{localStorage.removeItem(M);}catch(e){}try{localStorage.removeItem(_);}catch(e){}}var p="_ib_optout",tt="_ib_queue";function f(e){try{if(localStorage.getItem(p))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 j(){try{localStorage.setItem(p,"1");}catch(e){}P(),U(),L();try{localStorage.removeItem(tt);}catch(e){}}function Y(){try{localStorage.removeItem(p);}catch(e){}}function K(){try{return !!localStorage.getItem(p)}catch(e){return false}}var et=[1e3,2e3,4e3];function ot(e){return a(this,null,function*(){return new Promise(t=>setTimeout(t,e))})}function w(e,t,o=false){return a(this,null,function*(){let n=JSON.stringify(e);if(o&&typeof navigator!="undefined"&&navigator.sendBeacon){let i=new Blob([n],{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:n,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 ot(et[i]));}return t.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var E="_ib_queue",nt=10,it=5e3,rt=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>=nt&&this.flush();}flush(t=false){return a(this,null,function*(){if(this.flushing&&!t||this.queue.length===0)return;this.flushing=true;let o=this.queue.splice(0);(yield w({batch:o},this.config,t))||this.pushToOfflineQueue(o),this.flushing=false;})}flushOfflineQueue(){return a(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();},it);}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(-rt);localStorage.setItem(E,JSON.stringify(i));}catch(o){}}getOfflineQueue(){try{let t=localStorage.getItem(E);return t?JSON.parse(t):[]}catch(t){return []}}clearOfflineQueue(){try{localStorage.removeItem(E);}catch(t){}}};function Q(){if(typeof window=="undefined")return "desktop";let e=window.innerWidth;return e<=768?"mobile":e<=1024?"tablet":"desktop"}function V(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}function T(e){var c,O,R,C;let t=typeof window=="undefined",o=(c=e==null?void 0:e.path)!=null?c:t?"":window.location.pathname+window.location.search,n=t?"":window.location.href,i=(O=e==null?void 0:e.title)!=null?O:t?"":document.title,r=(R=e==null?void 0:e.referrer)!=null?R:t?"":document.referrer,g=V(),l=Q(),s=t?void 0:F(window.location.search);return {page:{path:o,url:n,title:i,referrer:r},device:x(d({},g),{type:l}),utm:s,locale:t?"en":navigator.language,timezone:t?"UTC":(C=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?C:"UTC",sdkVersion:"0.1.1"}}function H(e){if(typeof window=="undefined")return ()=>{};let t=history.pushState.bind(history),o=history.replaceState.bind(history);return history.pushState=function(...n){t(...n),e();},history.replaceState=function(...n){o(...n);},window.addEventListener("popstate",e),()=>{history.pushState=t,history.replaceState=o,window.removeEventListener("popstate",e);}}var X=class e{constructor(t){this.cleanupHistory=null;this.config=t,this.queue=new m(t),typeof window!="undefined"&&B(window.location.search,document.referrer);}static init(t){let o=D(t);return new e(o)}page(t){f(this.config)&&this.queue.push(this.buildEvent("page",{context:T(t)}));}track(t,o){f(this.config)&&this.queue.push(this.buildEvent("track",{event:t,properties:o}));}identify(t,o){f(this.config)&&(this.userId=t,this.queue.push(this.buildEvent("identify",{traits:o,userId:t})));}revenue(t){var o;f(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:t.amount,currency:(o=t.currency)!=null?o:"USD",plan:t.plan,type:t.type}}));}optOut(){this.queue.flush(),j(),this.userId=void 0,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){Y(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return K()}flush(){return a(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return v()}getSessionId(){return S()}getConfig(){return Object.freeze(d({},this.config))}enableAutoPage(){var t;return (t=this.cleanupHistory)==null||t.call(this),this.cleanupHistory=H(()=>this.page()),()=>{var o;(o=this.cleanupHistory)==null||o.call(this),this.cleanupHistory=null;}}buildEvent(t,o){var n,i;return {v:1,projectId:this.config.projectId,type:t,anonymousId:v(),userId:(n=this.userId)!=null?n:o.userId,sessionId:S(),timestamp:new Date().toISOString(),context:(i=o.context)!=null?i:T(),event:o.event,properties:o.properties,traits:o.traits,revenue:o.revenue}}};
|
|
2
2
|
exports.IndieBob=X;return exports;})({});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as IndieBob}from'./chunk-
|
|
1
|
+
export{a as IndieBob}from'./chunk-4IK5PET7.js';
|
package/dist/server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/core/config.ts
|
|
4
|
-
var DEFAULT_ENDPOINT = "https://indiebob.com/api/collect";
|
|
4
|
+
var DEFAULT_ENDPOINT = "https://www.indiebob.com/api/collect";
|
|
5
5
|
function resolveConfig(input) {
|
|
6
6
|
if (!input.projectId || !input.projectId.startsWith("proj_")) {
|
|
7
7
|
throw new Error(
|
|
@@ -79,7 +79,7 @@ var IndieBobServer = class _IndieBobServer {
|
|
|
79
79
|
device: { width: 0, height: 0, type: "desktop" },
|
|
80
80
|
locale: "en",
|
|
81
81
|
timezone: "UTC",
|
|
82
|
-
sdkVersion: "0.1.
|
|
82
|
+
sdkVersion: "0.1.1"
|
|
83
83
|
},
|
|
84
84
|
event: extras.event,
|
|
85
85
|
properties: extras.properties,
|
package/dist/server.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/core/config.ts
|
|
2
|
-
var DEFAULT_ENDPOINT = "https://indiebob.com/api/collect";
|
|
2
|
+
var DEFAULT_ENDPOINT = "https://www.indiebob.com/api/collect";
|
|
3
3
|
function resolveConfig(input) {
|
|
4
4
|
if (!input.projectId || !input.projectId.startsWith("proj_")) {
|
|
5
5
|
throw new Error(
|
|
@@ -77,7 +77,7 @@ var IndieBobServer = class _IndieBobServer {
|
|
|
77
77
|
device: { width: 0, height: 0, type: "desktop" },
|
|
78
78
|
locale: "en",
|
|
79
79
|
timezone: "UTC",
|
|
80
|
-
sdkVersion: "0.1.
|
|
80
|
+
sdkVersion: "0.1.1"
|
|
81
81
|
},
|
|
82
82
|
event: extras.event,
|
|
83
83
|
properties: extras.properties,
|
package/dist/vue.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var z=Object.defineProperty,G=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var P=(t,e,o)=>e in t?z(t,e,{enumerable:true,configurable:true,writable:true,value:o}):t[e]=o,d=(t,e)=>{for(var o in e||(e={}))$.call(e,o)&&P(t,o,e[o]);if(x)for(var o of x(e))Z.call(e,o)&&P(t,o,e[o]);return t},D=(t,e)=>G(t,W(e));var a=(t,e,o)=>new Promise((n,r)=>{var i=s=>{try{l(o.next(s));}catch(u){r(u);}},h=s=>{try{l(o.throw(s));}catch(u){r(u);}},l=s=>s.done?n(s.value):Promise.resolve(s.value).then(i,h);l((o=o.apply(t,e)).next());});var ee="https://indiebob.com/api/collect";function N(t){var e,o,n,r;if(!t.projectId||!t.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${t.projectId}". Must start with "proj_".`);return {projectId:t.projectId,endpoint:(e=t.endpoint)!=null?e:ee,debug:(o=t.debug)!=null?o:false,respectDnt:(n=t.respectDnt)!=null?n:true,respectGpc:(r=t.respectGpc)!=null?r:true}}var c="_ib_anon";function y(){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",e="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let o=new Uint8Array(21);crypto.getRandomValues(o);for(let n of o)e+=t[n%t.length];}else for(let o=0;o<21;o++)e+=t[Math.floor(Math.random()*t.length)];return e}function v(){try{let t=localStorage.getItem(c);return t||(t=y(),localStorage.setItem(c,t)),t}catch(t){try{let e=sessionStorage.getItem(c);return e||(e=y(),sessionStorage.setItem(c,e)),e}catch(e){return y()}}}function B(){try{localStorage.removeItem(c);}catch(t){}try{sessionStorage.removeItem(c);}catch(t){}}var I="_ib_session",S="_ib_session_last";function U(){try{return crypto.randomUUID()}catch(t){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function b(){var t;try{let e=Date.now(),o=parseInt((t=sessionStorage.getItem(S))!=null?t:"0",10),n=sessionStorage.getItem(I),r=o>0&&e-o>18e5;return (!n||r)&&(n=U(),sessionStorage.setItem(I,n)),sessionStorage.setItem(S,String(e)),n}catch(e){return U()}}function M(){try{sessionStorage.removeItem(I);}catch(t){}try{sessionStorage.removeItem(S);}catch(t){}}var _="_ib_first_utm",q="_ib_last_utm",
|
|
1
|
+
'use strict';var z=Object.defineProperty,G=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var P=(t,e,o)=>e in t?z(t,e,{enumerable:true,configurable:true,writable:true,value:o}):t[e]=o,d=(t,e)=>{for(var o in e||(e={}))$.call(e,o)&&P(t,o,e[o]);if(x)for(var o of x(e))Z.call(e,o)&&P(t,o,e[o]);return t},D=(t,e)=>G(t,W(e));var a=(t,e,o)=>new Promise((n,r)=>{var i=s=>{try{l(o.next(s));}catch(u){r(u);}},h=s=>{try{l(o.throw(s));}catch(u){r(u);}},l=s=>s.done?n(s.value):Promise.resolve(s.value).then(i,h);l((o=o.apply(t,e)).next());});var ee="https://www.indiebob.com/api/collect";function N(t){var e,o,n,r;if(!t.projectId||!t.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${t.projectId}". Must start with "proj_".`);return {projectId:t.projectId,endpoint:(e=t.endpoint)!=null?e:ee,debug:(o=t.debug)!=null?o:false,respectDnt:(n=t.respectDnt)!=null?n:true,respectGpc:(r=t.respectGpc)!=null?r:true}}var c="_ib_anon";function y(){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",e="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let o=new Uint8Array(21);crypto.getRandomValues(o);for(let n of o)e+=t[n%t.length];}else for(let o=0;o<21;o++)e+=t[Math.floor(Math.random()*t.length)];return e}function v(){try{let t=localStorage.getItem(c);return t||(t=y(),localStorage.setItem(c,t)),t}catch(t){try{let e=sessionStorage.getItem(c);return e||(e=y(),sessionStorage.setItem(c,e)),e}catch(e){return y()}}}function B(){try{localStorage.removeItem(c);}catch(t){}try{sessionStorage.removeItem(c);}catch(t){}}var I="_ib_session",S="_ib_session_last";function U(){try{return crypto.randomUUID()}catch(t){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function b(){var t;try{let e=Date.now(),o=parseInt((t=sessionStorage.getItem(S))!=null?t:"0",10),n=sessionStorage.getItem(I),r=o>0&&e-o>18e5;return (!n||r)&&(n=U(),sessionStorage.setItem(I,n)),sessionStorage.setItem(S,String(e)),n}catch(e){return U()}}function M(){try{sessionStorage.removeItem(I);}catch(t){}try{sessionStorage.removeItem(S);}catch(t){}}var _="_ib_first_utm",q="_ib_last_utm",w="_ib_referrer";function F(t){let e=new URLSearchParams(t),o={},n=false;return e.has("utm_source")&&(o.source=e.get("utm_source"),n=true),e.has("utm_medium")&&(o.medium=e.get("utm_medium"),n=true),e.has("utm_campaign")&&(o.campaign=e.get("utm_campaign"),n=true),e.has("utm_term")&&(o.term=e.get("utm_term"),n=true),e.has("utm_content")&&(o.content=e.get("utm_content"),n=true),n?o:null}function L(t,e){let o=F(t);try{o&&!localStorage.getItem(_)&&localStorage.setItem(_,JSON.stringify(o)),o&&localStorage.setItem(q,JSON.stringify(o)),e&&!localStorage.getItem(w)&&localStorage.setItem(w,e);}catch(n){}}function j(t){var e;return (e=F(t))!=null?e:void 0}function Y(){try{localStorage.removeItem(_);}catch(t){}try{localStorage.removeItem(q);}catch(t){}try{localStorage.removeItem(w);}catch(t){}}var p="_ib_optout",te="_ib_queue";function f(t){try{if(localStorage.getItem(p))return !1}catch(e){}return !(t.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||t.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function K(){try{localStorage.setItem(p,"1");}catch(t){}B(),M(),Y();try{localStorage.removeItem(te);}catch(t){}}function Q(){try{localStorage.removeItem(p);}catch(t){}}function V(){try{return !!localStorage.getItem(p)}catch(t){return false}}var oe=[1e3,2e3,4e3];function ne(t){return a(this,null,function*(){return new Promise(e=>setTimeout(e,t))})}function T(t,e,o=false){return a(this,null,function*(){let n=JSON.stringify(t);if(o&&typeof navigator!="undefined"&&navigator.sendBeacon){let r=new Blob([n],{type:"application/json"}),i=navigator.sendBeacon(e.endpoint,r);return e.debug&&console.log("[IndieBob] sendBeacon:",i,t.batch.length,"events"),i}for(let r=0;r<3;r++){try{let i=yield fetch(e.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:n,keepalive:!0});if(i.ok)return e.debug&&console.log("[IndieBob] sent:",t.batch.length,"events"),!0;if(i.status>=400&&i.status<500)return e.debug&&console.warn("[IndieBob] 4xx error, not retrying:",i.status),!1}catch(i){e.debug&&console.warn("[IndieBob] fetch error (attempt",r+1,"):",i);}r<2&&(yield ne(oe[r]));}return e.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var E="_ib_queue",re=10,ie=5e3,se=50,m=class{constructor(e){this.queue=[];this.timer=null;this.flushing=false;this.config=e,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(e){this.queue.push(e),this.queue.length>=re&&this.flush();}flush(e=false){return a(this,null,function*(){if(this.flushing&&!e||this.queue.length===0)return;this.flushing=true;let o=this.queue.splice(0);(yield T({batch:o},this.config,e))||this.pushToOfflineQueue(o),this.flushing=false;})}flushOfflineQueue(){return a(this,null,function*(){let e=this.getOfflineQueue();if(e.length===0)return;this.clearOfflineQueue(),yield T({batch:e},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},ie);}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(e){try{let r=[...this.getOfflineQueue(),...e].slice(-se);localStorage.setItem(E,JSON.stringify(r));}catch(o){}}getOfflineQueue(){try{let e=localStorage.getItem(E);return e?JSON.parse(e):[]}catch(e){return []}}clearOfflineQueue(){try{localStorage.removeItem(E);}catch(e){}}};function H(){if(typeof window=="undefined")return "desktop";let t=window.innerWidth;return t<=768?"mobile":t<=1024?"tablet":"desktop"}function X(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}function R(t){var u,C,k,A;let e=typeof window=="undefined",o=(u=t==null?void 0:t.path)!=null?u:e?"":window.location.pathname+window.location.search,n=e?"":window.location.href,r=(C=t==null?void 0:t.title)!=null?C:e?"":document.title,i=(k=t==null?void 0:t.referrer)!=null?k:e?"":document.referrer,h=X(),l=H(),s=e?void 0:j(window.location.search);return {page:{path:o,url:n,title:r,referrer:i},device:D(d({},h),{type:l}),utm:s,locale:e?"en":navigator.language,timezone:e?"UTC":(A=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?A:"UTC",sdkVersion:"0.1.1"}}function J(t){if(typeof window=="undefined")return ()=>{};let e=history.pushState.bind(history),o=history.replaceState.bind(history);return history.pushState=function(...n){e(...n),t();},history.replaceState=function(...n){o(...n);},window.addEventListener("popstate",t),()=>{history.pushState=e,history.replaceState=o,window.removeEventListener("popstate",t);}}var g=class t{constructor(e){this.cleanupHistory=null;this.config=e,this.queue=new m(e),typeof window!="undefined"&&L(window.location.search,document.referrer);}static init(e){let o=N(e);return new t(o)}page(e){f(this.config)&&this.queue.push(this.buildEvent("page",{context:R(e)}));}track(e,o){f(this.config)&&this.queue.push(this.buildEvent("track",{event:e,properties:o}));}identify(e,o){f(this.config)&&(this.userId=e,this.queue.push(this.buildEvent("identify",{traits:o,userId:e})));}revenue(e){var o;f(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:e.amount,currency:(o=e.currency)!=null?o:"USD",plan:e.plan,type:e.type}}));}optOut(){this.queue.flush(),K(),this.userId=void 0,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){Q(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return V()}flush(){return a(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return v()}getSessionId(){return b()}getConfig(){return Object.freeze(d({},this.config))}enableAutoPage(){var e;return (e=this.cleanupHistory)==null||e.call(this),this.cleanupHistory=J(()=>this.page()),()=>{var o;(o=this.cleanupHistory)==null||o.call(this),this.cleanupHistory=null;}}buildEvent(e,o){var n,r;return {v:1,projectId:this.config.projectId,type:e,anonymousId:v(),userId:(n=this.userId)!=null?n:o.userId,sessionId:b(),timestamp:new Date().toISOString(),context:(r=o.context)!=null?r:R(),event:o.event,properties:o.properties,traits:o.traits,revenue:o.revenue}}};var ae=Symbol("indiebob"),O=null,Fe={install(t,e){let o=g.init(e);O=o,t.provide(ae,o),t.config.globalProperties.$bob=o;let n=t.config.globalProperties.$router;n&&n.afterEach(()=>{o.page();});}};function Le(){if(O)return O;throw new Error("[IndieBob] useTracker() called before IndieBobPlugin was installed.")}
|
|
2
2
|
exports.IndieBob=g;exports.IndieBobPlugin=Fe;exports.useTracker=Le;
|
package/dist/vue.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var IndieBob=(function(exports){'use strict';var z=Object.defineProperty,G=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var P=(t,e,o)=>e in t?z(t,e,{enumerable:true,configurable:true,writable:true,value:o}):t[e]=o,d=(t,e)=>{for(var o in e||(e={}))$.call(e,o)&&P(t,o,e[o]);if(x)for(var o of x(e))Z.call(e,o)&&P(t,o,e[o]);return t},D=(t,e)=>G(t,W(e));var a=(t,e,o)=>new Promise((n,r)=>{var i=s=>{try{l(o.next(s));}catch(u){r(u);}},h=s=>{try{l(o.throw(s));}catch(u){r(u);}},l=s=>s.done?n(s.value):Promise.resolve(s.value).then(i,h);l((o=o.apply(t,e)).next());});var ee="https://indiebob.com/api/collect";function N(t){var e,o,n,r;if(!t.projectId||!t.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${t.projectId}". Must start with "proj_".`);return {projectId:t.projectId,endpoint:(e=t.endpoint)!=null?e:ee,debug:(o=t.debug)!=null?o:false,respectDnt:(n=t.respectDnt)!=null?n:true,respectGpc:(r=t.respectGpc)!=null?r:true}}var c="_ib_anon";function y(){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",e="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let o=new Uint8Array(21);crypto.getRandomValues(o);for(let n of o)e+=t[n%t.length];}else for(let o=0;o<21;o++)e+=t[Math.floor(Math.random()*t.length)];return e}function v(){try{let t=localStorage.getItem(c);return t||(t=y(),localStorage.setItem(c,t)),t}catch(t){try{let e=sessionStorage.getItem(c);return e||(e=y(),sessionStorage.setItem(c,e)),e}catch(e){return y()}}}function B(){try{localStorage.removeItem(c);}catch(t){}try{sessionStorage.removeItem(c);}catch(t){}}var I="_ib_session",S="_ib_session_last";function U(){try{return crypto.randomUUID()}catch(t){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function b(){var t;try{let e=Date.now(),o=parseInt((t=sessionStorage.getItem(S))!=null?t:"0",10),n=sessionStorage.getItem(I),r=o>0&&e-o>18e5;return (!n||r)&&(n=U(),sessionStorage.setItem(I,n)),sessionStorage.setItem(S,String(e)),n}catch(e){return U()}}function M(){try{sessionStorage.removeItem(I);}catch(t){}try{sessionStorage.removeItem(S);}catch(t){}}var _="_ib_first_utm",q="_ib_last_utm",
|
|
1
|
+
var IndieBob=(function(exports){'use strict';var z=Object.defineProperty,G=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var P=(t,e,o)=>e in t?z(t,e,{enumerable:true,configurable:true,writable:true,value:o}):t[e]=o,d=(t,e)=>{for(var o in e||(e={}))$.call(e,o)&&P(t,o,e[o]);if(x)for(var o of x(e))Z.call(e,o)&&P(t,o,e[o]);return t},D=(t,e)=>G(t,W(e));var a=(t,e,o)=>new Promise((n,r)=>{var i=s=>{try{l(o.next(s));}catch(u){r(u);}},h=s=>{try{l(o.throw(s));}catch(u){r(u);}},l=s=>s.done?n(s.value):Promise.resolve(s.value).then(i,h);l((o=o.apply(t,e)).next());});var ee="https://www.indiebob.com/api/collect";function N(t){var e,o,n,r;if(!t.projectId||!t.projectId.startsWith("proj_"))throw new Error(`[IndieBob] Invalid projectId "${t.projectId}". Must start with "proj_".`);return {projectId:t.projectId,endpoint:(e=t.endpoint)!=null?e:ee,debug:(o=t.debug)!=null?o:false,respectDnt:(n=t.respectDnt)!=null?n:true,respectGpc:(r=t.respectGpc)!=null?r:true}}var c="_ib_anon";function y(){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",e="";if(typeof crypto!="undefined"&&crypto.getRandomValues){let o=new Uint8Array(21);crypto.getRandomValues(o);for(let n of o)e+=t[n%t.length];}else for(let o=0;o<21;o++)e+=t[Math.floor(Math.random()*t.length)];return e}function v(){try{let t=localStorage.getItem(c);return t||(t=y(),localStorage.setItem(c,t)),t}catch(t){try{let e=sessionStorage.getItem(c);return e||(e=y(),sessionStorage.setItem(c,e)),e}catch(e){return y()}}}function B(){try{localStorage.removeItem(c);}catch(t){}try{sessionStorage.removeItem(c);}catch(t){}}var I="_ib_session",S="_ib_session_last";function U(){try{return crypto.randomUUID()}catch(t){return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}}function b(){var t;try{let e=Date.now(),o=parseInt((t=sessionStorage.getItem(S))!=null?t:"0",10),n=sessionStorage.getItem(I),r=o>0&&e-o>18e5;return (!n||r)&&(n=U(),sessionStorage.setItem(I,n)),sessionStorage.setItem(S,String(e)),n}catch(e){return U()}}function M(){try{sessionStorage.removeItem(I);}catch(t){}try{sessionStorage.removeItem(S);}catch(t){}}var _="_ib_first_utm",q="_ib_last_utm",w="_ib_referrer";function F(t){let e=new URLSearchParams(t),o={},n=false;return e.has("utm_source")&&(o.source=e.get("utm_source"),n=true),e.has("utm_medium")&&(o.medium=e.get("utm_medium"),n=true),e.has("utm_campaign")&&(o.campaign=e.get("utm_campaign"),n=true),e.has("utm_term")&&(o.term=e.get("utm_term"),n=true),e.has("utm_content")&&(o.content=e.get("utm_content"),n=true),n?o:null}function L(t,e){let o=F(t);try{o&&!localStorage.getItem(_)&&localStorage.setItem(_,JSON.stringify(o)),o&&localStorage.setItem(q,JSON.stringify(o)),e&&!localStorage.getItem(w)&&localStorage.setItem(w,e);}catch(n){}}function j(t){var e;return (e=F(t))!=null?e:void 0}function Y(){try{localStorage.removeItem(_);}catch(t){}try{localStorage.removeItem(q);}catch(t){}try{localStorage.removeItem(w);}catch(t){}}var p="_ib_optout",te="_ib_queue";function f(t){try{if(localStorage.getItem(p))return !1}catch(e){}return !(t.respectDnt&&typeof navigator!="undefined"&&(navigator.doNotTrack==="1"||navigator.msDoNotTrack==="1")||t.respectGpc&&typeof navigator!="undefined"&&navigator.globalPrivacyControl===true)}function K(){try{localStorage.setItem(p,"1");}catch(t){}B(),M(),Y();try{localStorage.removeItem(te);}catch(t){}}function Q(){try{localStorage.removeItem(p);}catch(t){}}function V(){try{return !!localStorage.getItem(p)}catch(t){return false}}var oe=[1e3,2e3,4e3];function ne(t){return a(this,null,function*(){return new Promise(e=>setTimeout(e,t))})}function T(t,e,o=false){return a(this,null,function*(){let n=JSON.stringify(t);if(o&&typeof navigator!="undefined"&&navigator.sendBeacon){let r=new Blob([n],{type:"application/json"}),i=navigator.sendBeacon(e.endpoint,r);return e.debug&&console.log("[IndieBob] sendBeacon:",i,t.batch.length,"events"),i}for(let r=0;r<3;r++){try{let i=yield fetch(e.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:n,keepalive:!0});if(i.ok)return e.debug&&console.log("[IndieBob] sent:",t.batch.length,"events"),!0;if(i.status>=400&&i.status<500)return e.debug&&console.warn("[IndieBob] 4xx error, not retrying:",i.status),!1}catch(i){e.debug&&console.warn("[IndieBob] fetch error (attempt",r+1,"):",i);}r<2&&(yield ne(oe[r]));}return e.debug&&console.warn("[IndieBob] failed to send after",3,"attempts"),false})}var E="_ib_queue",re=10,ie=5e3,se=50,m=class{constructor(e){this.queue=[];this.timer=null;this.flushing=false;this.config=e,this.startTimer(),this.setupVisibilityFlush(),this.setupOnlineFlush();}push(e){this.queue.push(e),this.queue.length>=re&&this.flush();}flush(e=false){return a(this,null,function*(){if(this.flushing&&!e||this.queue.length===0)return;this.flushing=true;let o=this.queue.splice(0);(yield T({batch:o},this.config,e))||this.pushToOfflineQueue(o),this.flushing=false;})}flushOfflineQueue(){return a(this,null,function*(){let e=this.getOfflineQueue();if(e.length===0)return;this.clearOfflineQueue(),yield T({batch:e},this.config);})}destroy(){this.timer&&clearInterval(this.timer);}startTimer(){this.timer=setInterval(()=>{this.queue.length>0&&this.flush();},ie);}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(e){try{let r=[...this.getOfflineQueue(),...e].slice(-se);localStorage.setItem(E,JSON.stringify(r));}catch(o){}}getOfflineQueue(){try{let e=localStorage.getItem(E);return e?JSON.parse(e):[]}catch(e){return []}}clearOfflineQueue(){try{localStorage.removeItem(E);}catch(e){}}};function H(){if(typeof window=="undefined")return "desktop";let t=window.innerWidth;return t<=768?"mobile":t<=1024?"tablet":"desktop"}function X(){return typeof window=="undefined"?{width:0,height:0}:{width:window.innerWidth,height:window.innerHeight}}function R(t){var u,C,k,A;let e=typeof window=="undefined",o=(u=t==null?void 0:t.path)!=null?u:e?"":window.location.pathname+window.location.search,n=e?"":window.location.href,r=(C=t==null?void 0:t.title)!=null?C:e?"":document.title,i=(k=t==null?void 0:t.referrer)!=null?k:e?"":document.referrer,h=X(),l=H(),s=e?void 0:j(window.location.search);return {page:{path:o,url:n,title:r,referrer:i},device:D(d({},h),{type:l}),utm:s,locale:e?"en":navigator.language,timezone:e?"UTC":(A=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?A:"UTC",sdkVersion:"0.1.1"}}function J(t){if(typeof window=="undefined")return ()=>{};let e=history.pushState.bind(history),o=history.replaceState.bind(history);return history.pushState=function(...n){e(...n),t();},history.replaceState=function(...n){o(...n);},window.addEventListener("popstate",t),()=>{history.pushState=e,history.replaceState=o,window.removeEventListener("popstate",t);}}var g=class t{constructor(e){this.cleanupHistory=null;this.config=e,this.queue=new m(e),typeof window!="undefined"&&L(window.location.search,document.referrer);}static init(e){let o=N(e);return new t(o)}page(e){f(this.config)&&this.queue.push(this.buildEvent("page",{context:R(e)}));}track(e,o){f(this.config)&&this.queue.push(this.buildEvent("track",{event:e,properties:o}));}identify(e,o){f(this.config)&&(this.userId=e,this.queue.push(this.buildEvent("identify",{traits:o,userId:e})));}revenue(e){var o;f(this.config)&&this.queue.push(this.buildEvent("revenue",{revenue:{amount:e.amount,currency:(o=e.currency)!=null?o:"USD",plan:e.plan,type:e.type}}));}optOut(){this.queue.flush(),K(),this.userId=void 0,this.config.debug&&console.log("[IndieBob] opted out");}optIn(){Q(),this.config.debug&&console.log("[IndieBob] opted in");}isOptedOut(){return V()}flush(){return a(this,null,function*(){yield this.queue.flush();})}getAnonymousId(){return v()}getSessionId(){return b()}getConfig(){return Object.freeze(d({},this.config))}enableAutoPage(){var e;return (e=this.cleanupHistory)==null||e.call(this),this.cleanupHistory=J(()=>this.page()),()=>{var o;(o=this.cleanupHistory)==null||o.call(this),this.cleanupHistory=null;}}buildEvent(e,o){var n,r;return {v:1,projectId:this.config.projectId,type:e,anonymousId:v(),userId:(n=this.userId)!=null?n:o.userId,sessionId:b(),timestamp:new Date().toISOString(),context:(r=o.context)!=null?r:R(),event:o.event,properties:o.properties,traits:o.traits,revenue:o.revenue}}};var ae=Symbol("indiebob"),O=null,Fe={install(t,e){let o=g.init(e);O=o,t.provide(ae,o),t.config.globalProperties.$bob=o;let n=t.config.globalProperties.$router;n&&n.afterEach(()=>{o.page();});}};function Le(){if(O)return O;throw new Error("[IndieBob] useTracker() called before IndieBobPlugin was installed.")}
|
|
2
2
|
exports.IndieBob=g;exports.IndieBobPlugin=Fe;exports.useTracker=Le;return exports;})({});
|
package/dist/vue.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a}from'./chunk-
|
|
1
|
+
import {a}from'./chunk-4IK5PET7.js';export{a as IndieBob}from'./chunk-4IK5PET7.js';var l=Symbol("indiebob"),r=null,b={install(o,n){let e=a.init(n);r=e,o.provide(l,e),o.config.globalProperties.$bob=e;let t=o.config.globalProperties.$router;t&&t.afterEach(()=>{e.page();});}};function p(){if(r)return r;throw new Error("[IndieBob] useTracker() called before IndieBobPlugin was installed.")}export{b as IndieBobPlugin,p as useTracker};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indiebob/tracker",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Privacy-first analytics SDK for web applications. <5KB gzipped. No cookies.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,13 +50,6 @@
|
|
|
50
50
|
"README.md",
|
|
51
51
|
"CHANGELOG.md"
|
|
52
52
|
],
|
|
53
|
-
"scripts": {
|
|
54
|
-
"build": "tsup",
|
|
55
|
-
"dev": "tsup --watch",
|
|
56
|
-
"type-check": "tsc --noEmit",
|
|
57
|
-
"cdn:publish": "tsx scripts/publish-cdn.mts",
|
|
58
|
-
"prepublishOnly": "pnpm run build"
|
|
59
|
-
},
|
|
60
53
|
"devDependencies": {
|
|
61
54
|
"@aws-sdk/client-s3": "^3.1000.0",
|
|
62
55
|
"@types/node": "^22.0.0",
|
|
@@ -78,5 +71,11 @@
|
|
|
78
71
|
"vue-router": {
|
|
79
72
|
"optional": true
|
|
80
73
|
}
|
|
74
|
+
},
|
|
75
|
+
"scripts": {
|
|
76
|
+
"build": "tsup",
|
|
77
|
+
"dev": "tsup --watch",
|
|
78
|
+
"type-check": "tsc --noEmit",
|
|
79
|
+
"cdn:publish": "tsx scripts/publish-cdn.mts"
|
|
81
80
|
}
|
|
82
|
-
}
|
|
81
|
+
}
|