@zaplier/sdk 1.7.6 → 1.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +127 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.esm.js +127 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk.js +127 -2
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.min.js +1 -1
- package/dist/src/sdk.d.ts +8 -0
- package/dist/src/sdk.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21517,6 +21517,52 @@ class ZaplierSDK {
|
|
|
21517
21517
|
const tempVisitorId = this.visitorId || 'temp-' + Date.now().toString(36);
|
|
21518
21518
|
return generateCurrentSessionId(tempVisitorId);
|
|
21519
21519
|
}
|
|
21520
|
+
/**
|
|
21521
|
+
* Update tracking engines with new session ID to maintain consistency
|
|
21522
|
+
*/
|
|
21523
|
+
updateTrackingEnginesSessionId(newSessionId) {
|
|
21524
|
+
try {
|
|
21525
|
+
// Update replay engine session ID if it exists and is recording
|
|
21526
|
+
if (this.replayEngine && this.replayEngine.isRecording()) {
|
|
21527
|
+
if (this.config.debug) {
|
|
21528
|
+
console.log("[Zaplier] Updating replay engine session ID:", newSessionId);
|
|
21529
|
+
}
|
|
21530
|
+
// Stop current recording and restart with new session ID
|
|
21531
|
+
this.replayEngine.stop();
|
|
21532
|
+
this.replayEngine = new SessionReplayEngine(newSessionId, this.backendVisitorId || 'unknown', {
|
|
21533
|
+
sampleRate: 1.0, // Keep recording active
|
|
21534
|
+
inactivityTimeout: 30000,
|
|
21535
|
+
pauseOnInactive: true,
|
|
21536
|
+
});
|
|
21537
|
+
this.replayEngine.setSDKInstance(this);
|
|
21538
|
+
this.replayEngine.start();
|
|
21539
|
+
}
|
|
21540
|
+
// Update heatmap engine session ID if it exists and is recording
|
|
21541
|
+
if (this.heatmapEngine && this.heatmapEngine.isRecording()) {
|
|
21542
|
+
if (this.config.debug) {
|
|
21543
|
+
console.log("[Zaplier] Updating heatmap engine session ID:", newSessionId);
|
|
21544
|
+
}
|
|
21545
|
+
// Stop current recording and restart with new session ID
|
|
21546
|
+
this.heatmapEngine.stop();
|
|
21547
|
+
this.heatmapEngine = new HeatmapEngine(newSessionId, {
|
|
21548
|
+
trackClicks: true,
|
|
21549
|
+
trackScrollDepth: true,
|
|
21550
|
+
trackRageClicks: true,
|
|
21551
|
+
trackMouseMoves: false,
|
|
21552
|
+
});
|
|
21553
|
+
if (this.antiAdblockManager) {
|
|
21554
|
+
this.heatmapEngine.setAntiAdblockManager(this.antiAdblockManager);
|
|
21555
|
+
}
|
|
21556
|
+
this.heatmapEngine.start();
|
|
21557
|
+
}
|
|
21558
|
+
if (this.config.debug) {
|
|
21559
|
+
console.log("[Zaplier] Tracking engines updated with session ID:", newSessionId);
|
|
21560
|
+
}
|
|
21561
|
+
}
|
|
21562
|
+
catch (error) {
|
|
21563
|
+
console.error("[Zaplier] Failed to update tracking engines session ID:", error);
|
|
21564
|
+
}
|
|
21565
|
+
}
|
|
21520
21566
|
/**
|
|
21521
21567
|
* Initialize Anti-Adblock Manager
|
|
21522
21568
|
*/
|
|
@@ -21685,6 +21731,70 @@ class ZaplierSDK {
|
|
|
21685
21731
|
window.location.hostname.startsWith("10.") ||
|
|
21686
21732
|
window.location.hostname.includes("local"));
|
|
21687
21733
|
}
|
|
21734
|
+
/**
|
|
21735
|
+
* Extract UTM parameters from current URL
|
|
21736
|
+
*/
|
|
21737
|
+
extractUTMParameters() {
|
|
21738
|
+
const utmParams = {};
|
|
21739
|
+
if (typeof window === "undefined" || !window.location) {
|
|
21740
|
+
return utmParams;
|
|
21741
|
+
}
|
|
21742
|
+
try {
|
|
21743
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
21744
|
+
// Extract UTM parameters (camelCase for consistency with backend)
|
|
21745
|
+
const utmSource = urlParams.get('utm_source');
|
|
21746
|
+
const utmMedium = urlParams.get('utm_medium');
|
|
21747
|
+
const utmCampaign = urlParams.get('utm_campaign');
|
|
21748
|
+
const utmContent = urlParams.get('utm_content');
|
|
21749
|
+
const utmTerm = urlParams.get('utm_term');
|
|
21750
|
+
// Extract click IDs
|
|
21751
|
+
const fbclid = urlParams.get('fbclid');
|
|
21752
|
+
const gclid = urlParams.get('gclid');
|
|
21753
|
+
const ttclid = urlParams.get('ttclid');
|
|
21754
|
+
// Extract ad platform parameters
|
|
21755
|
+
const creativeId = urlParams.get('creative_id');
|
|
21756
|
+
const adId = urlParams.get('ad_id');
|
|
21757
|
+
const adsetId = urlParams.get('adset_id');
|
|
21758
|
+
const campaignId = urlParams.get('campaign_id');
|
|
21759
|
+
const platform = urlParams.get('platform');
|
|
21760
|
+
// Add to result object (only non-null values)
|
|
21761
|
+
if (utmSource)
|
|
21762
|
+
utmParams.utmSource = utmSource;
|
|
21763
|
+
if (utmMedium)
|
|
21764
|
+
utmParams.utmMedium = utmMedium;
|
|
21765
|
+
if (utmCampaign)
|
|
21766
|
+
utmParams.utmCampaign = utmCampaign;
|
|
21767
|
+
if (utmContent)
|
|
21768
|
+
utmParams.utmContent = utmContent;
|
|
21769
|
+
if (utmTerm)
|
|
21770
|
+
utmParams.utmTerm = utmTerm;
|
|
21771
|
+
if (fbclid)
|
|
21772
|
+
utmParams.fbclid = fbclid;
|
|
21773
|
+
if (gclid)
|
|
21774
|
+
utmParams.gclid = gclid;
|
|
21775
|
+
if (ttclid)
|
|
21776
|
+
utmParams.ttclid = ttclid;
|
|
21777
|
+
if (creativeId)
|
|
21778
|
+
utmParams.creativeId = creativeId;
|
|
21779
|
+
if (adId)
|
|
21780
|
+
utmParams.adId = adId;
|
|
21781
|
+
if (adsetId)
|
|
21782
|
+
utmParams.adsetId = adsetId;
|
|
21783
|
+
if (campaignId)
|
|
21784
|
+
utmParams.campaignId = campaignId;
|
|
21785
|
+
if (platform)
|
|
21786
|
+
utmParams.platform = platform;
|
|
21787
|
+
if (this.config.debug && Object.keys(utmParams).length > 0) {
|
|
21788
|
+
console.log("[Zaplier] UTM parameters extracted from URL:", utmParams);
|
|
21789
|
+
}
|
|
21790
|
+
}
|
|
21791
|
+
catch (error) {
|
|
21792
|
+
if (this.config.debug) {
|
|
21793
|
+
console.warn("[Zaplier] Failed to extract UTM parameters:", error);
|
|
21794
|
+
}
|
|
21795
|
+
}
|
|
21796
|
+
return utmParams;
|
|
21797
|
+
}
|
|
21688
21798
|
/**
|
|
21689
21799
|
* Send event to backend
|
|
21690
21800
|
*/
|
|
@@ -21726,7 +21836,9 @@ class ZaplierSDK {
|
|
|
21726
21836
|
}
|
|
21727
21837
|
: undefined,
|
|
21728
21838
|
fingerprintComponents: this.fingerprint?.components || {},
|
|
21729
|
-
|
|
21839
|
+
// CRITICAL: Auto-extract UTM parameters from URL, but allow eventData to override
|
|
21840
|
+
...this.extractUTMParameters(), // Auto-extracted UTM parameters (background)
|
|
21841
|
+
...eventData, // User-provided event data (can override UTM parameters)
|
|
21730
21842
|
timestamp: new Date().toISOString(),
|
|
21731
21843
|
url: typeof window !== "undefined" && window.location
|
|
21732
21844
|
? window.location.href
|
|
@@ -21771,12 +21883,25 @@ class ZaplierSDK {
|
|
|
21771
21883
|
console.log("[Zaplier] Backend visitor ID received and processed:", response.visitorId);
|
|
21772
21884
|
}
|
|
21773
21885
|
}
|
|
21774
|
-
if
|
|
21886
|
+
// CRITICAL: Only update session ID if we don't have one yet or if it's temporary
|
|
21887
|
+
// Once a session ID is established and tracking engines are started, keep it consistent
|
|
21888
|
+
// to prevent replay/event session ID mismatches
|
|
21889
|
+
if (response.sessionId && (!this.sessionId || this.sessionId.includes('temp-'))) {
|
|
21890
|
+
const oldSessionId = this.sessionId;
|
|
21775
21891
|
this.sessionId = response.sessionId;
|
|
21892
|
+
// Update tracking engines with new session ID if they exist
|
|
21893
|
+
if (oldSessionId !== this.sessionId && this.sessionId) {
|
|
21894
|
+
this.updateTrackingEnginesSessionId(this.sessionId);
|
|
21895
|
+
}
|
|
21776
21896
|
}
|
|
21777
21897
|
else if (this.backendVisitorId && (!this.sessionId || this.sessionId.includes('temp-'))) {
|
|
21778
21898
|
// Generate new session ID now that we have the proper visitor ID
|
|
21899
|
+
const oldSessionId = this.sessionId;
|
|
21779
21900
|
this.sessionId = generateCurrentSessionId(this.backendVisitorId);
|
|
21901
|
+
// Update tracking engines with new session ID if they exist
|
|
21902
|
+
if (oldSessionId !== this.sessionId && this.sessionId) {
|
|
21903
|
+
this.updateTrackingEnginesSessionId(this.sessionId);
|
|
21904
|
+
}
|
|
21780
21905
|
}
|
|
21781
21906
|
return response;
|
|
21782
21907
|
}
|