@zaplier/sdk 1.2.7 → 1.3.0
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 +87 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.esm.js +87 -44
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk.js +87 -44
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.min.js +1 -1
- package/dist/src/modules/session-replay.d.ts +4 -4
- package/dist/src/modules/session-replay.d.ts.map +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.d.ts
CHANGED
|
@@ -769,6 +769,14 @@ declare class ZaplierSDK implements ZaplierSDK$1 {
|
|
|
769
769
|
* Send event to backend
|
|
770
770
|
*/
|
|
771
771
|
private sendEvent;
|
|
772
|
+
/**
|
|
773
|
+
* Send session replay batch to backend
|
|
774
|
+
*/
|
|
775
|
+
sendReplayBatch(replayData: {
|
|
776
|
+
sessionId: string;
|
|
777
|
+
events: any[];
|
|
778
|
+
metadata: any;
|
|
779
|
+
}): Promise<any>;
|
|
772
780
|
/**
|
|
773
781
|
* Make HTTP request to backend using anti-adblock system
|
|
774
782
|
*/
|
package/dist/index.esm.js
CHANGED
|
@@ -7281,37 +7281,28 @@ class SessionReplayEngine {
|
|
|
7281
7281
|
this.sendToBackend(payload);
|
|
7282
7282
|
}
|
|
7283
7283
|
/**
|
|
7284
|
-
* Set
|
|
7284
|
+
* Set SDK instance for transport
|
|
7285
7285
|
*/
|
|
7286
|
-
|
|
7287
|
-
this.
|
|
7286
|
+
setSDKInstance(sdk) {
|
|
7287
|
+
this.sdkInstance = sdk;
|
|
7288
7288
|
}
|
|
7289
7289
|
/**
|
|
7290
|
-
* Send
|
|
7290
|
+
* Send replay batch via SDK's transport system
|
|
7291
7291
|
*/
|
|
7292
7292
|
async sendToBackend(payload) {
|
|
7293
7293
|
try {
|
|
7294
|
-
|
|
7295
|
-
|
|
7296
|
-
|
|
7297
|
-
const result = await this.antiAdblockManager.send(payload, "/replays/record");
|
|
7298
|
-
if (result.success) {
|
|
7299
|
-
console.log("[Zaplier] Session replay sent via WebRTC");
|
|
7300
|
-
return; // Success via WebRTC
|
|
7301
|
-
}
|
|
7302
|
-
console.log("[Zaplier] WebRTC failed, falling back to fetch");
|
|
7294
|
+
if (!this.sdkInstance) {
|
|
7295
|
+
console.error("[Zaplier] No SDK instance available for replay transport");
|
|
7296
|
+
return;
|
|
7303
7297
|
}
|
|
7304
|
-
|
|
7305
|
-
const apiEndpoint = window.zaplier_config?.apiEndpoint || "http://localhost:3001";
|
|
7306
|
-
const token = window.zaplier_config?.token || "ws_demo_token";
|
|
7307
|
-
const url = `${apiEndpoint}/replays/record?token=${token}`;
|
|
7308
|
-
console.log(`[Zaplier] Sending replay batch to ${url}`);
|
|
7298
|
+
console.log(`[Zaplier] Sending replay batch via SDK transport`);
|
|
7309
7299
|
console.log(`[Zaplier] Payload:`, {
|
|
7310
7300
|
sessionId: payload.sessionId,
|
|
7311
7301
|
eventCount: payload.events.length,
|
|
7312
7302
|
hasMetadata: !!payload.metadata,
|
|
7313
7303
|
});
|
|
7314
|
-
|
|
7304
|
+
// Use SDK's sendReplayBatch method
|
|
7305
|
+
const result = await this.sdkInstance.sendReplayBatch({
|
|
7315
7306
|
sessionId: payload.sessionId,
|
|
7316
7307
|
events: payload.events,
|
|
7317
7308
|
metadata: {
|
|
@@ -7321,23 +7312,12 @@ class SessionReplayEngine {
|
|
|
7321
7312
|
hasConversion: false,
|
|
7322
7313
|
...payload.metadata,
|
|
7323
7314
|
},
|
|
7324
|
-
};
|
|
7325
|
-
// Fallback to standard fetch
|
|
7326
|
-
const response = await fetch(url, {
|
|
7327
|
-
method: "POST",
|
|
7328
|
-
headers: { "Content-Type": "application/json" },
|
|
7329
|
-
body: JSON.stringify(requestBody),
|
|
7330
7315
|
});
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
console.error("[Zaplier] Session replay batch failed:", {
|
|
7334
|
-
status: response.status,
|
|
7335
|
-
statusText: response.statusText,
|
|
7336
|
-
response: responseText,
|
|
7337
|
-
});
|
|
7316
|
+
if (result && result.success) {
|
|
7317
|
+
console.log("[Zaplier] Session replay batch sent successfully");
|
|
7338
7318
|
}
|
|
7339
7319
|
else {
|
|
7340
|
-
console.
|
|
7320
|
+
console.error("[Zaplier] Session replay batch failed:", result);
|
|
7341
7321
|
}
|
|
7342
7322
|
}
|
|
7343
7323
|
catch (error) {
|
|
@@ -7389,7 +7369,7 @@ const DEFAULT_CONFIG = {
|
|
|
7389
7369
|
*/
|
|
7390
7370
|
class ZaplierSDK {
|
|
7391
7371
|
constructor(userConfig) {
|
|
7392
|
-
this.version = "3.0
|
|
7372
|
+
this.version = "1.3.0";
|
|
7393
7373
|
this.isInitialized = false;
|
|
7394
7374
|
this.eventQueue = [];
|
|
7395
7375
|
/**
|
|
@@ -7467,7 +7447,7 @@ class ZaplierSDK {
|
|
|
7467
7447
|
});
|
|
7468
7448
|
// Connect to anti-adblock manager
|
|
7469
7449
|
if (this.antiAdblockManager) {
|
|
7470
|
-
this.replayEngine.
|
|
7450
|
+
this.replayEngine.setSDKInstance(this);
|
|
7471
7451
|
}
|
|
7472
7452
|
const started = this.replayEngine.start();
|
|
7473
7453
|
if (this.config.debug) {
|
|
@@ -7478,10 +7458,35 @@ class ZaplierSDK {
|
|
|
7478
7458
|
}
|
|
7479
7459
|
}
|
|
7480
7460
|
else if (this.replayEngine) {
|
|
7481
|
-
// If engine already exists
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7461
|
+
// If engine already exists but isn't recording, recreate it with 100% sample rate
|
|
7462
|
+
if (!this.replayEngine.isRecording()) {
|
|
7463
|
+
// Stop and recreate with 100% sample rate
|
|
7464
|
+
this.replayEngine.stop();
|
|
7465
|
+
this.replayEngine = undefined;
|
|
7466
|
+
// Recreate with 100% sample rate
|
|
7467
|
+
if (!this.sessionId) {
|
|
7468
|
+
this.sessionId = this.generateSessionId();
|
|
7469
|
+
}
|
|
7470
|
+
const sessionId = this.sessionId;
|
|
7471
|
+
this.replayEngine = new SessionReplayEngine(sessionId, {
|
|
7472
|
+
sampleRate: 1.0, // Force 100% when explicitly enabled
|
|
7473
|
+
maskSensitiveFields: this.config.replayMaskInputs,
|
|
7474
|
+
compressionEnabled: true,
|
|
7475
|
+
});
|
|
7476
|
+
// Connect to anti-adblock manager
|
|
7477
|
+
if (this.antiAdblockManager) {
|
|
7478
|
+
this.replayEngine.setSDKInstance(this);
|
|
7479
|
+
}
|
|
7480
|
+
const started = this.replayEngine.start();
|
|
7481
|
+
if (this.config.debug) {
|
|
7482
|
+
console.log("[Zaplier] Replay engine recreated with 100% sample rate", { started, isRecording: this.replayEngine.isRecording() });
|
|
7483
|
+
}
|
|
7484
|
+
}
|
|
7485
|
+
else {
|
|
7486
|
+
// Already recording, just log
|
|
7487
|
+
if (this.config.debug) {
|
|
7488
|
+
console.log("[Zaplier] Replay already recording");
|
|
7489
|
+
}
|
|
7485
7490
|
}
|
|
7486
7491
|
}
|
|
7487
7492
|
if (this.config.debug && !this.replayEngine) {
|
|
@@ -7512,7 +7517,7 @@ class ZaplierSDK {
|
|
|
7512
7517
|
});
|
|
7513
7518
|
// Connect to anti-adblock manager
|
|
7514
7519
|
if (this.antiAdblockManager) {
|
|
7515
|
-
this.replayEngine.
|
|
7520
|
+
this.replayEngine.setSDKInstance(this);
|
|
7516
7521
|
}
|
|
7517
7522
|
return this.replayEngine.start();
|
|
7518
7523
|
}
|
|
@@ -7616,10 +7621,8 @@ class ZaplierSDK {
|
|
|
7616
7621
|
maskSensitiveFields: this.config.replayMaskInputs,
|
|
7617
7622
|
compressionEnabled: true,
|
|
7618
7623
|
});
|
|
7619
|
-
// Connect
|
|
7620
|
-
|
|
7621
|
-
this.replayEngine.setAntiAdblockManager(this.antiAdblockManager);
|
|
7622
|
-
}
|
|
7624
|
+
// Connect SDK instance for transport
|
|
7625
|
+
this.replayEngine.setSDKInstance(this);
|
|
7623
7626
|
const started = this.replayEngine.start();
|
|
7624
7627
|
if (this.config.debug) {
|
|
7625
7628
|
console.log("[Zaplier] Session Replay started", {
|
|
@@ -7905,6 +7908,46 @@ class ZaplierSDK {
|
|
|
7905
7908
|
}
|
|
7906
7909
|
}
|
|
7907
7910
|
}
|
|
7911
|
+
/**
|
|
7912
|
+
* Send session replay batch to backend
|
|
7913
|
+
*/
|
|
7914
|
+
async sendReplayBatch(replayData) {
|
|
7915
|
+
if (!this.isInitialized) {
|
|
7916
|
+
console.error("[Zaplier] SDK not initialized for replay batch sending");
|
|
7917
|
+
return { success: false, error: "SDK not initialized" };
|
|
7918
|
+
}
|
|
7919
|
+
try {
|
|
7920
|
+
const payload = {
|
|
7921
|
+
sessionId: replayData.sessionId,
|
|
7922
|
+
userId: this.backendVisitorId,
|
|
7923
|
+
events: replayData.events,
|
|
7924
|
+
metadata: {
|
|
7925
|
+
...replayData.metadata,
|
|
7926
|
+
visitorId: this.backendVisitorId,
|
|
7927
|
+
fingerprintHash: this.fingerprint?.hash,
|
|
7928
|
+
},
|
|
7929
|
+
};
|
|
7930
|
+
if (this.config.debug) {
|
|
7931
|
+
console.log("[Zaplier] Sending replay batch:", {
|
|
7932
|
+
sessionId: payload.sessionId,
|
|
7933
|
+
eventCount: payload.events.length,
|
|
7934
|
+
hasMetadata: !!payload.metadata,
|
|
7935
|
+
});
|
|
7936
|
+
}
|
|
7937
|
+
// Use anti-adblock transport or standard HTTP
|
|
7938
|
+
const result = await this.makeRequest(`/replays/record?token=${encodeURIComponent(this.config.token)}`, payload, "POST");
|
|
7939
|
+
if (this.config.debug) {
|
|
7940
|
+
console.log("[Zaplier] Replay batch result:", result);
|
|
7941
|
+
}
|
|
7942
|
+
return result;
|
|
7943
|
+
}
|
|
7944
|
+
catch (error) {
|
|
7945
|
+
if (this.config.debug) {
|
|
7946
|
+
console.error("[Zaplier] Replay batch sending failed:", error);
|
|
7947
|
+
}
|
|
7948
|
+
return { success: false, error: error instanceof Error ? error.message : "Unknown error" };
|
|
7949
|
+
}
|
|
7950
|
+
}
|
|
7908
7951
|
/**
|
|
7909
7952
|
* Make HTTP request to backend using anti-adblock system
|
|
7910
7953
|
*/
|