@zaplier/sdk 1.8.4 → 1.8.6

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.
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Zaplier SDK v2.0.0 - Performance Optimized
3
+ * Advanced privacy-first tracking with code splitting
4
+ * (c) 2026 Zaplier Team
5
+ */
6
+ class t{constructor(t,i,s={}){this.events=[],this.isActive=!1,this.isPaused=!1,this.lastActivityTime=Date.now(),this.sessionStartTime=Date.now(),this.sessionId=t,this.visitorId=i,this.config={enabled:!0,sampleRate:1,batchInterval:1e4,inactivityTimeout:3e4,pauseOnInactive:!0,...s}}async start(){if(!this.config.enabled||this.isActive)return!1;if(Math.random()>this.config.sampleRate)return!1;try{const{record:t}=await import("rrweb");return this.rrwebStopRecord=t({emit:t=>{this.onActivity(),this.isPaused||this.events.push(t)}}),this.isActive=!0,this.startBatchTimer(),this.startInactivityTracking(),!0}catch(t){return console.error("[Zaplier] Failed to start rrweb recording:",t),!1}}stop(){this.isActive&&(this.isActive=!1,this.rrwebStopRecord&&(this.rrwebStopRecord(),this.rrwebStopRecord=void 0),this.batchTimer&&(clearInterval(this.batchTimer),this.batchTimer=void 0),this.inactivityTimer&&(clearTimeout(this.inactivityTimer),this.inactivityTimer=void 0),this.sendBatch())}startBatchTimer(){this.batchTimer=window.setInterval(()=>{this.sendBatch()},this.config.batchInterval)}sendBatch(){if(0===this.events.length)return;const t={sessionId:this.sessionId,visitorId:this.visitorId,events:[...this.events],metadata:{userAgent:navigator.userAgent,timestamp:Date.now(),startUrl:window.location.href,duration:Date.now()-this.sessionStartTime,activeTime:this.getActiveTime(),funnelSteps:[],hasConversion:!1,eventsCount:this.events.length,isPaused:this.isPaused}};this.events=[],t.events.length,this.sendToBackend(t)}setSDKInstance(t){this.sdkInstance=t}async sendToBackend(t){try{if(!this.sdkInstance)return void console.error("[Zaplier] No SDK instance available for replay transport");const i=await this.sdkInstance.sendReplayBatch(t);i&&i.success||console.error("[Zaplier] Session replay batch failed:",i)}catch(t){console.error("[Zaplier] Session replay error:",t)}}getEventCount(){return this.events.length}isRecording(){return this.isActive}isPausedState(){return this.isPaused}startInactivityTracking(){this.config.pauseOnInactive&&(["mousedown","mousemove","keypress","scroll","touchstart","click"].forEach(t=>{document.addEventListener(t,this.onActivity.bind(this),!0)}),this.resetInactivityTimer())}onActivity(){this.lastActivityTime=Date.now(),this.isPaused&&this.resume(),this.resetInactivityTimer()}resetInactivityTimer(){this.inactivityTimer&&clearTimeout(this.inactivityTimer),this.inactivityTimer=window.setTimeout(()=>{this.pauseForInactivity()},this.config.inactivityTimeout)}pauseForInactivity(){this.isPaused||(this.isPaused=!0)}resume(){this.isPaused&&(this.isPaused=!1)}getActiveTime(){return Date.now()-this.sessionStartTime}getVisitorId(){return this.visitorId}}export{t as SessionReplayEngine};
package/dist/v2/core.d.ts CHANGED
@@ -368,4 +368,4 @@ declare class ZaplierCore {
368
368
  declare function initZaplierCore(config: CoreConfig): ZaplierCore;
369
369
 
370
370
  export { ZaplierCore, ZaplierCore as default, initZaplierCore };
371
- export type { CoreConfig };
371
+ export type { CoreConfig, UserData, VisitorHistory, VisitorInfo };
@@ -3,4 +3,4 @@
3
3
  * Advanced privacy-first tracking with code splitting
4
4
  * (c) 2026 Zaplier Team
5
5
  */
6
- class e{constructor(e){if(this.eventQueue=[],this.isInitialized=!1,this.modules=new Map,this.version="2.0.0",this.t=!1,!e.token)throw console.error('[Zaplier] Missing required "token" option. Get your token at https://app.zaplier.com/dashboard/keys'),new Error("Zaplier: token is required");if("string"!=typeof e.token||e.token.trim().length<5)throw console.error('[Zaplier] Invalid token format. Token should be a workspace API key (e.g., "ws_abc123...")'),new Error("Zaplier: invalid token format");this.config={deferAdvanced:!0,loadTimeout:5e3,debug:!1,...e},this.t=this.isDevEnvironment(),this.initializeCore()}isDevEnvironment(){if("undefined"==typeof window)return!1;const e=window.location.hostname;return"localhost"===e||"127.0.0.1"===e||"[::1]"===e||e.endsWith(".local")||e.endsWith(".test")||!0===this.config.debug}initializeCore(){try{this.config.debug&&this.version,this.sessionId=this.generateTempSessionId(),this.visitorId=this.generateTempVisitorId(),this.isInitialized=!0,this.processEventQueue(),this.config.debug,this.config.deferAdvanced||this.scheduleAdvancedLoading()}catch(e){console.error("[Zaplier Core] Initialization failed:",e)}}trackPageView(e={}){this.config.debug;const t={eventType:"page_view",eventName:"page_view",sessionId:this.sessionId,visitorId:this.visitorId,url:window.location.href,referrer:document.referrer,timestamp:(new Date).toISOString(),...e};this.sendEvent(t)}track(e,t={}){this.config.debug;const i={eventType:"custom",eventName:e,sessionId:this.sessionId,visitorId:this.visitorId,timestamp:(new Date).toISOString(),...t};this.sendEvent(i)}async enableAdvancedFeatures(){this.config.debug;try{await this.loadFingerprinting(),this.config.replay&&await this.loadReplayModule(),this.config.debug}catch(e){console.error("[Zaplier Core] Failed to load advanced features:",e)}}async loadFingerprinting(){if(!this.modules.has("fingerprint"))try{const{getCompleteFingerprint:e}=await import("./chunks/fingerprint-FfUEEIAd.min.js").then(function(e){return e.f}),t=await e();t.success&&t.data&&(this.visitorId=t.data.hash||this.visitorId,this.modules.set("fingerprint",t.data),this.config.debug)}catch(e){console.error("[Zaplier Core] Fingerprinting failed:",e)}}async loadReplayModule(){if(!this.modules.has("replay"))try{const{SessionReplayEngine:e}=await import("./chunks/session-replay-C5Tp0d16.min.js"),t=new e(this.sessionId,this.visitorId,{sampleRate:this.config.replaySampling||.1});t.start()&&(this.modules.set("replay",t),this.config.debug)}catch(e){console.error("[Zaplier Core] Replay loading failed:",e)}}scheduleAdvancedLoading(){((e,t=100)=>{"undefined"!=typeof requestIdleCallback?requestIdleCallback(e,{timeout:this.config.loadTimeout}):setTimeout(e,t)})(()=>this.enableAdvancedFeatures())}async sendEvent(e){try{const t={...e,isDev:this.t},i=await fetch(`${this.config.apiEndpoint||"https://api.zaplier.com"}/events?token=${encodeURIComponent(this.config.token)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),keepalive:!0});if(this.config.debug&&!i.ok&&console.warn(`[Zaplier Core] Event sending failed: ${i.status}`),i.ok){const e=await i.json().catch(()=>null);(null==e?void 0:e.visitorId)&&(this.backendVisitorId=e.visitorId)}}catch(t){this.eventQueue.push(e),this.config.debug&&console.warn("[Zaplier Core] Event queued for retry:",t)}}processEventQueue(){if(0===this.eventQueue.length)return;const e=[...this.eventQueue];this.eventQueue=[],e.forEach(e=>this.sendEvent(e))}generateTempSessionId(){const e=new Date,t=e.getFullYear()+(e.getMonth()+1).toString().padStart(2,"0")+e.getDate().toString().padStart(2,"0"),i=e.getHours().toString().padStart(2,"0");return`temp_${Date.now()}_${t}_${i}`}generateTempVisitorId(){return`temp_visitor_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}getVisitorId(){var e,t;return null!==(t=null!==(e=this.backendVisitorId)&&void 0!==e?e:this.visitorId)&&void 0!==t?t:null}getUserData(){var e,t,i,n,s,o,r;const a="undefined"!=typeof navigator?{userAgent:navigator.userAgent,language:navigator.language,screen:{width:null!==(t=null===(e=window.screen)||void 0===e?void 0:e.width)&&void 0!==t?t:0,height:null!==(n=null===(i=window.screen)||void 0===i?void 0:i.height)&&void 0!==n?n:0}}:{userAgent:"",language:"",screen:{width:0,height:0}};return{sessionId:null!==(s=this.sessionId)&&void 0!==s?s:"",visitorId:null!==(o=this.getVisitorId())&&void 0!==o?o:void 0,location:{},device:a,journey:[],fingerprint:null===(r=this.modules.get("fingerprint"))||void 0===r?void 0:r.hash}}async getVisitorInfo(){var e;const t=this.backendVisitorId;if(!t)return this.config.debug&&console.warn("[Zaplier Core] No backend visitor ID yet. Track an event first."),null;if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t))return null;if(this.cachedVisitorInfo)return this.cachedVisitorInfo;try{const i=null!==(e=this.config.apiEndpoint)&&void 0!==e?e:"https://api.zaplier.com",n=await fetch(`${i}/tracking/visitor/${t}?token=${encodeURIComponent(this.config.token)}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!n.ok)return null;const s=await n.json();return this.cachedVisitorInfo=s,s}catch{return null}}}function t(t){return new e(t)}if("undefined"!=typeof window){window.Zaplier={init:t,version:"2.0.0"};const e=()=>{const e=document.getElementsByTagName("script");for(const i of Array.from(e))if(i.src&&(i.src.includes("zaplier")||i.src.includes("core.min.js"))&&i.dataset.token){const e=t({token:i.dataset.token,debug:"true"===i.dataset.debug,replay:"true"===i.dataset.replay,deferAdvanced:"false"!==i.dataset.deferAdvanced});return window.Zaplier.instance=e,e.trackPageView(),void(e.config.deferAdvanced&&e.enableAdvancedFeatures())}};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()}export{e as ZaplierCore,e as default,t as initZaplierCore};
6
+ class e{constructor(e){if(this.eventQueue=[],this.isInitialized=!1,this.modules=new Map,this.version="2.0.0",this.t=!1,!e.token)throw console.error('[Zaplier] Missing required "token" option. Get your token at https://app.zaplier.com/dashboard/keys'),new Error("Zaplier: token is required");if("string"!=typeof e.token||e.token.trim().length<5)throw console.error('[Zaplier] Invalid token format. Token should be a workspace API key (e.g., "ws_abc123...")'),new Error("Zaplier: invalid token format");this.config={deferAdvanced:!0,loadTimeout:5e3,debug:!1,...e},this.t=this.isDevEnvironment(),this.initializeCore()}isDevEnvironment(){if("undefined"==typeof window)return!1;const e=window.location.hostname;return"localhost"===e||"127.0.0.1"===e||"[::1]"===e||e.endsWith(".local")||e.endsWith(".test")||!0===this.config.debug}initializeCore(){try{this.config.debug&&this.version,this.sessionId=this.generateTempSessionId(),this.visitorId=this.generateTempVisitorId(),this.isInitialized=!0,this.processEventQueue(),this.config.debug,this.config.deferAdvanced||this.scheduleAdvancedLoading()}catch(e){console.error("[Zaplier Core] Initialization failed:",e)}}trackPageView(e={}){this.config.debug;const t={eventType:"page_view",eventName:"page_view",sessionId:this.sessionId,visitorId:this.visitorId,url:window.location.href,referrer:document.referrer,timestamp:(new Date).toISOString(),...e};this.sendEvent(t)}track(e,t={}){this.config.debug;const i={eventType:"custom",eventName:e,sessionId:this.sessionId,visitorId:this.visitorId,timestamp:(new Date).toISOString(),...t};this.sendEvent(i)}async enableAdvancedFeatures(){this.config.debug;try{await this.loadFingerprinting(),this.config.replay&&await this.loadReplayModule(),this.config.debug}catch(e){console.error("[Zaplier Core] Failed to load advanced features:",e)}}async loadFingerprinting(){if(!this.modules.has("fingerprint"))try{const{getCompleteFingerprint:e}=await import("./chunks/fingerprint-FfUEEIAd.min.js").then(function(e){return e.f}),t=await e();t.success&&t.data&&(this.visitorId=t.data.hash||this.visitorId,this.modules.set("fingerprint",t.data),this.config.debug)}catch(e){console.error("[Zaplier Core] Fingerprinting failed:",e)}}async loadReplayModule(){if(!this.modules.has("replay"))try{const{SessionReplayEngine:e}=await import("./chunks/session-replay-MISzVk2N.min.js"),t=new e(this.sessionId,this.visitorId,{sampleRate:this.config.replaySampling||.1});await t.start()&&(this.modules.set("replay",t),this.config.debug)}catch(e){console.error("[Zaplier Core] Replay loading failed:",e)}}scheduleAdvancedLoading(){((e,t=100)=>{"undefined"!=typeof requestIdleCallback?requestIdleCallback(e,{timeout:this.config.loadTimeout}):setTimeout(e,t)})(()=>this.enableAdvancedFeatures())}async sendEvent(e){try{const t={...e,isDev:this.t},i=await fetch(`${this.config.apiEndpoint||"https://api.zaplier.com"}/events?token=${encodeURIComponent(this.config.token)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),keepalive:!0});if(this.config.debug&&!i.ok&&console.warn(`[Zaplier Core] Event sending failed: ${i.status}`),i.ok){const e=await i.json().catch(()=>null);(null==e?void 0:e.visitorId)&&(this.backendVisitorId=e.visitorId)}}catch(t){this.eventQueue.push(e),this.config.debug&&console.warn("[Zaplier Core] Event queued for retry:",t)}}processEventQueue(){if(0===this.eventQueue.length)return;const e=[...this.eventQueue];this.eventQueue=[],e.forEach(e=>this.sendEvent(e))}generateTempSessionId(){const e=new Date,t=e.getFullYear()+(e.getMonth()+1).toString().padStart(2,"0")+e.getDate().toString().padStart(2,"0"),i=e.getHours().toString().padStart(2,"0");return`temp_${Date.now()}_${t}_${i}`}generateTempVisitorId(){return`temp_visitor_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}getVisitorId(){var e,t;return null!==(t=null!==(e=this.backendVisitorId)&&void 0!==e?e:this.visitorId)&&void 0!==t?t:null}getUserData(){var e,t,i,n,s,o,r;const a="undefined"!=typeof navigator?{userAgent:navigator.userAgent,language:navigator.language,screen:{width:null!==(t=null===(e=window.screen)||void 0===e?void 0:e.width)&&void 0!==t?t:0,height:null!==(n=null===(i=window.screen)||void 0===i?void 0:i.height)&&void 0!==n?n:0}}:{userAgent:"",language:"",screen:{width:0,height:0}};return{sessionId:null!==(s=this.sessionId)&&void 0!==s?s:"",visitorId:null!==(o=this.getVisitorId())&&void 0!==o?o:void 0,location:{},device:a,journey:[],fingerprint:null===(r=this.modules.get("fingerprint"))||void 0===r?void 0:r.hash}}async getVisitorInfo(){var e;const t=this.backendVisitorId;if(!t)return this.config.debug&&console.warn("[Zaplier Core] No backend visitor ID yet. Track an event first."),null;if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t))return null;if(this.cachedVisitorInfo)return this.cachedVisitorInfo;try{const i=null!==(e=this.config.apiEndpoint)&&void 0!==e?e:"https://api.zaplier.com",n=await fetch(`${i}/tracking/visitor/${t}?token=${encodeURIComponent(this.config.token)}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!n.ok)return null;const s=await n.json();return this.cachedVisitorInfo=s,s}catch{return null}}}function t(t){return new e(t)}if("undefined"!=typeof window){window.Zaplier={init:t,version:"2.0.0"};const e=()=>{const e=document.getElementsByTagName("script");for(const i of Array.from(e))if(i.src&&(i.src.includes("zaplier")||i.src.includes("core.min.js"))&&i.dataset.token){const e=t({token:i.dataset.token,debug:"true"===i.dataset.debug,replay:"true"===i.dataset.replay,deferAdvanced:"false"!==i.dataset.deferAdvanced});return window.Zaplier.instance=e,e.trackPageView(),void(e.config.deferAdvanced&&e.enableAdvancedFeatures())}};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()}export{e as ZaplierCore,e as default,t as initZaplierCore};
@@ -3,4 +3,4 @@
3
3
  * Advanced privacy-first tracking with code splitting
4
4
  * (c) 2026 Zaplier Team
5
5
  */
6
- import{record as t}from"rrweb";class i{constructor(t,i,s={}){this.events=[],this.isActive=!1,this.isPaused=!1,this.lastActivityTime=Date.now(),this.sessionStartTime=Date.now(),this.sessionId=t,this.visitorId=i,this.config={enabled:!0,sampleRate:1,batchInterval:1e4,inactivityTimeout:3e4,pauseOnInactive:!0,...s}}start(){if(!this.config.enabled||this.isActive)return!1;if(Math.random()>this.config.sampleRate)return!1;try{return this.rrwebStopRecord=t({emit:t=>{this.onActivity(),this.isPaused||this.events.push(t)}}),this.isActive=!0,this.startBatchTimer(),this.startInactivityTracking(),!0}catch(t){return!1}}stop(){this.isActive&&(this.isActive=!1,this.rrwebStopRecord&&(this.rrwebStopRecord(),this.rrwebStopRecord=void 0),this.batchTimer&&(clearInterval(this.batchTimer),this.batchTimer=void 0),this.inactivityTimer&&(clearTimeout(this.inactivityTimer),this.inactivityTimer=void 0),this.sendBatch())}startBatchTimer(){this.batchTimer=window.setInterval(()=>{this.sendBatch()},this.config.batchInterval)}sendBatch(){if(0===this.events.length)return;const t={sessionId:this.sessionId,visitorId:this.visitorId,events:[...this.events],metadata:{userAgent:navigator.userAgent,timestamp:Date.now(),startUrl:window.location.href,duration:Date.now()-this.sessionStartTime,activeTime:this.getActiveTime(),funnelSteps:[],hasConversion:!1,eventsCount:this.events.length,isPaused:this.isPaused}};this.events=[],this.sendToBackend(t)}setSDKInstance(t){this.sdkInstance=t}async sendToBackend(t){try{if(!this.sdkInstance)return;const i=await this.sdkInstance.sendReplayBatch(t);i&&i.success}catch(t){}}getEventCount(){return this.events.length}isRecording(){return this.isActive}isPausedState(){return this.isPaused}startInactivityTracking(){this.config.pauseOnInactive&&(["mousedown","mousemove","keypress","scroll","touchstart","click"].forEach(t=>{document.addEventListener(t,this.onActivity.bind(this),!0)}),this.resetInactivityTimer())}onActivity(){this.lastActivityTime=Date.now(),this.isPaused&&this.resume(),this.resetInactivityTimer()}resetInactivityTimer(){this.inactivityTimer&&clearTimeout(this.inactivityTimer),this.inactivityTimer=window.setTimeout(()=>{this.pauseForInactivity()},this.config.inactivityTimeout)}pauseForInactivity(){this.isPaused||(this.isPaused=!0)}resume(){this.isPaused&&(this.isPaused=!1)}getActiveTime(){return Date.now()-this.sessionStartTime}getVisitorId(){return this.visitorId}}export{i as SessionReplayEngine};
6
+ class t{constructor(t,i,s={}){this.events=[],this.isActive=!1,this.isPaused=!1,this.lastActivityTime=Date.now(),this.sessionStartTime=Date.now(),this.sessionId=t,this.visitorId=i,this.config={enabled:!0,sampleRate:1,batchInterval:1e4,inactivityTimeout:3e4,pauseOnInactive:!0,...s}}async start(){if(!this.config.enabled||this.isActive)return!1;if(Math.random()>this.config.sampleRate)return!1;try{const{record:t}=await import("rrweb");return this.rrwebStopRecord=t({emit:t=>{this.onActivity(),this.isPaused||this.events.push(t)}}),this.isActive=!0,this.startBatchTimer(),this.startInactivityTracking(),!0}catch(t){return!1}}stop(){this.isActive&&(this.isActive=!1,this.rrwebStopRecord&&(this.rrwebStopRecord(),this.rrwebStopRecord=void 0),this.batchTimer&&(clearInterval(this.batchTimer),this.batchTimer=void 0),this.inactivityTimer&&(clearTimeout(this.inactivityTimer),this.inactivityTimer=void 0),this.sendBatch())}startBatchTimer(){this.batchTimer=window.setInterval(()=>{this.sendBatch()},this.config.batchInterval)}sendBatch(){if(0===this.events.length)return;const t={sessionId:this.sessionId,visitorId:this.visitorId,events:[...this.events],metadata:{userAgent:navigator.userAgent,timestamp:Date.now(),startUrl:window.location.href,duration:Date.now()-this.sessionStartTime,activeTime:this.getActiveTime(),funnelSteps:[],hasConversion:!1,eventsCount:this.events.length,isPaused:this.isPaused}};this.events=[],this.sendToBackend(t)}setSDKInstance(t){this.sdkInstance=t}async sendToBackend(t){try{if(!this.sdkInstance)return;const i=await this.sdkInstance.sendReplayBatch(t);i&&i.success}catch(t){}}getEventCount(){return this.events.length}isRecording(){return this.isActive}isPausedState(){return this.isPaused}startInactivityTracking(){this.config.pauseOnInactive&&(["mousedown","mousemove","keypress","scroll","touchstart","click"].forEach(t=>{document.addEventListener(t,this.onActivity.bind(this),!0)}),this.resetInactivityTimer())}onActivity(){this.lastActivityTime=Date.now(),this.isPaused&&this.resume(),this.resetInactivityTimer()}resetInactivityTimer(){this.inactivityTimer&&clearTimeout(this.inactivityTimer),this.inactivityTimer=window.setTimeout(()=>{this.pauseForInactivity()},this.config.inactivityTimeout)}pauseForInactivity(){this.isPaused||(this.isPaused=!0)}resume(){this.isPaused&&(this.isPaused=!1)}getActiveTime(){return Date.now()-this.sessionStartTime}getVisitorId(){return this.visitorId}}export{t as SessionReplayEngine};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaplier/sdk",
3
- "version": "1.8.4",
3
+ "version": "1.8.6",
4
4
  "description": "Advanced privacy-first tracking SDK with session replay, heatmaps, and anti-adblock technology",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",