@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/sdk.js
CHANGED
|
@@ -7287,37 +7287,28 @@
|
|
|
7287
7287
|
this.sendToBackend(payload);
|
|
7288
7288
|
}
|
|
7289
7289
|
/**
|
|
7290
|
-
* Set
|
|
7290
|
+
* Set SDK instance for transport
|
|
7291
7291
|
*/
|
|
7292
|
-
|
|
7293
|
-
this.
|
|
7292
|
+
setSDKInstance(sdk) {
|
|
7293
|
+
this.sdkInstance = sdk;
|
|
7294
7294
|
}
|
|
7295
7295
|
/**
|
|
7296
|
-
* Send
|
|
7296
|
+
* Send replay batch via SDK's transport system
|
|
7297
7297
|
*/
|
|
7298
7298
|
async sendToBackend(payload) {
|
|
7299
7299
|
try {
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
const result = await this.antiAdblockManager.send(payload, "/replays/record");
|
|
7304
|
-
if (result.success) {
|
|
7305
|
-
console.log("[Zaplier] Session replay sent via WebRTC");
|
|
7306
|
-
return; // Success via WebRTC
|
|
7307
|
-
}
|
|
7308
|
-
console.log("[Zaplier] WebRTC failed, falling back to fetch");
|
|
7300
|
+
if (!this.sdkInstance) {
|
|
7301
|
+
console.error("[Zaplier] No SDK instance available for replay transport");
|
|
7302
|
+
return;
|
|
7309
7303
|
}
|
|
7310
|
-
|
|
7311
|
-
const apiEndpoint = window.zaplier_config?.apiEndpoint || "http://localhost:3001";
|
|
7312
|
-
const token = window.zaplier_config?.token || "ws_demo_token";
|
|
7313
|
-
const url = `${apiEndpoint}/replays/record?token=${token}`;
|
|
7314
|
-
console.log(`[Zaplier] Sending replay batch to ${url}`);
|
|
7304
|
+
console.log(`[Zaplier] Sending replay batch via SDK transport`);
|
|
7315
7305
|
console.log(`[Zaplier] Payload:`, {
|
|
7316
7306
|
sessionId: payload.sessionId,
|
|
7317
7307
|
eventCount: payload.events.length,
|
|
7318
7308
|
hasMetadata: !!payload.metadata,
|
|
7319
7309
|
});
|
|
7320
|
-
|
|
7310
|
+
// Use SDK's sendReplayBatch method
|
|
7311
|
+
const result = await this.sdkInstance.sendReplayBatch({
|
|
7321
7312
|
sessionId: payload.sessionId,
|
|
7322
7313
|
events: payload.events,
|
|
7323
7314
|
metadata: {
|
|
@@ -7327,23 +7318,12 @@
|
|
|
7327
7318
|
hasConversion: false,
|
|
7328
7319
|
...payload.metadata,
|
|
7329
7320
|
},
|
|
7330
|
-
};
|
|
7331
|
-
// Fallback to standard fetch
|
|
7332
|
-
const response = await fetch(url, {
|
|
7333
|
-
method: "POST",
|
|
7334
|
-
headers: { "Content-Type": "application/json" },
|
|
7335
|
-
body: JSON.stringify(requestBody),
|
|
7336
7321
|
});
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
console.error("[Zaplier] Session replay batch failed:", {
|
|
7340
|
-
status: response.status,
|
|
7341
|
-
statusText: response.statusText,
|
|
7342
|
-
response: responseText,
|
|
7343
|
-
});
|
|
7322
|
+
if (result && result.success) {
|
|
7323
|
+
console.log("[Zaplier] Session replay batch sent successfully");
|
|
7344
7324
|
}
|
|
7345
7325
|
else {
|
|
7346
|
-
console.
|
|
7326
|
+
console.error("[Zaplier] Session replay batch failed:", result);
|
|
7347
7327
|
}
|
|
7348
7328
|
}
|
|
7349
7329
|
catch (error) {
|
|
@@ -7395,7 +7375,7 @@
|
|
|
7395
7375
|
*/
|
|
7396
7376
|
class ZaplierSDK {
|
|
7397
7377
|
constructor(userConfig) {
|
|
7398
|
-
this.version = "3.0
|
|
7378
|
+
this.version = "1.3.0";
|
|
7399
7379
|
this.isInitialized = false;
|
|
7400
7380
|
this.eventQueue = [];
|
|
7401
7381
|
/**
|
|
@@ -7473,7 +7453,7 @@
|
|
|
7473
7453
|
});
|
|
7474
7454
|
// Connect to anti-adblock manager
|
|
7475
7455
|
if (this.antiAdblockManager) {
|
|
7476
|
-
this.replayEngine.
|
|
7456
|
+
this.replayEngine.setSDKInstance(this);
|
|
7477
7457
|
}
|
|
7478
7458
|
const started = this.replayEngine.start();
|
|
7479
7459
|
if (this.config.debug) {
|
|
@@ -7484,10 +7464,35 @@
|
|
|
7484
7464
|
}
|
|
7485
7465
|
}
|
|
7486
7466
|
else if (this.replayEngine) {
|
|
7487
|
-
// If engine already exists
|
|
7488
|
-
|
|
7489
|
-
|
|
7490
|
-
|
|
7467
|
+
// If engine already exists but isn't recording, recreate it with 100% sample rate
|
|
7468
|
+
if (!this.replayEngine.isRecording()) {
|
|
7469
|
+
// Stop and recreate with 100% sample rate
|
|
7470
|
+
this.replayEngine.stop();
|
|
7471
|
+
this.replayEngine = undefined;
|
|
7472
|
+
// Recreate with 100% sample rate
|
|
7473
|
+
if (!this.sessionId) {
|
|
7474
|
+
this.sessionId = this.generateSessionId();
|
|
7475
|
+
}
|
|
7476
|
+
const sessionId = this.sessionId;
|
|
7477
|
+
this.replayEngine = new SessionReplayEngine(sessionId, {
|
|
7478
|
+
sampleRate: 1.0, // Force 100% when explicitly enabled
|
|
7479
|
+
maskSensitiveFields: this.config.replayMaskInputs,
|
|
7480
|
+
compressionEnabled: true,
|
|
7481
|
+
});
|
|
7482
|
+
// Connect to anti-adblock manager
|
|
7483
|
+
if (this.antiAdblockManager) {
|
|
7484
|
+
this.replayEngine.setSDKInstance(this);
|
|
7485
|
+
}
|
|
7486
|
+
const started = this.replayEngine.start();
|
|
7487
|
+
if (this.config.debug) {
|
|
7488
|
+
console.log("[Zaplier] Replay engine recreated with 100% sample rate", { started, isRecording: this.replayEngine.isRecording() });
|
|
7489
|
+
}
|
|
7490
|
+
}
|
|
7491
|
+
else {
|
|
7492
|
+
// Already recording, just log
|
|
7493
|
+
if (this.config.debug) {
|
|
7494
|
+
console.log("[Zaplier] Replay already recording");
|
|
7495
|
+
}
|
|
7491
7496
|
}
|
|
7492
7497
|
}
|
|
7493
7498
|
if (this.config.debug && !this.replayEngine) {
|
|
@@ -7518,7 +7523,7 @@
|
|
|
7518
7523
|
});
|
|
7519
7524
|
// Connect to anti-adblock manager
|
|
7520
7525
|
if (this.antiAdblockManager) {
|
|
7521
|
-
this.replayEngine.
|
|
7526
|
+
this.replayEngine.setSDKInstance(this);
|
|
7522
7527
|
}
|
|
7523
7528
|
return this.replayEngine.start();
|
|
7524
7529
|
}
|
|
@@ -7622,10 +7627,8 @@
|
|
|
7622
7627
|
maskSensitiveFields: this.config.replayMaskInputs,
|
|
7623
7628
|
compressionEnabled: true,
|
|
7624
7629
|
});
|
|
7625
|
-
// Connect
|
|
7626
|
-
|
|
7627
|
-
this.replayEngine.setAntiAdblockManager(this.antiAdblockManager);
|
|
7628
|
-
}
|
|
7630
|
+
// Connect SDK instance for transport
|
|
7631
|
+
this.replayEngine.setSDKInstance(this);
|
|
7629
7632
|
const started = this.replayEngine.start();
|
|
7630
7633
|
if (this.config.debug) {
|
|
7631
7634
|
console.log("[Zaplier] Session Replay started", {
|
|
@@ -7911,6 +7914,46 @@
|
|
|
7911
7914
|
}
|
|
7912
7915
|
}
|
|
7913
7916
|
}
|
|
7917
|
+
/**
|
|
7918
|
+
* Send session replay batch to backend
|
|
7919
|
+
*/
|
|
7920
|
+
async sendReplayBatch(replayData) {
|
|
7921
|
+
if (!this.isInitialized) {
|
|
7922
|
+
console.error("[Zaplier] SDK not initialized for replay batch sending");
|
|
7923
|
+
return { success: false, error: "SDK not initialized" };
|
|
7924
|
+
}
|
|
7925
|
+
try {
|
|
7926
|
+
const payload = {
|
|
7927
|
+
sessionId: replayData.sessionId,
|
|
7928
|
+
userId: this.backendVisitorId,
|
|
7929
|
+
events: replayData.events,
|
|
7930
|
+
metadata: {
|
|
7931
|
+
...replayData.metadata,
|
|
7932
|
+
visitorId: this.backendVisitorId,
|
|
7933
|
+
fingerprintHash: this.fingerprint?.hash,
|
|
7934
|
+
},
|
|
7935
|
+
};
|
|
7936
|
+
if (this.config.debug) {
|
|
7937
|
+
console.log("[Zaplier] Sending replay batch:", {
|
|
7938
|
+
sessionId: payload.sessionId,
|
|
7939
|
+
eventCount: payload.events.length,
|
|
7940
|
+
hasMetadata: !!payload.metadata,
|
|
7941
|
+
});
|
|
7942
|
+
}
|
|
7943
|
+
// Use anti-adblock transport or standard HTTP
|
|
7944
|
+
const result = await this.makeRequest(`/replays/record?token=${encodeURIComponent(this.config.token)}`, payload, "POST");
|
|
7945
|
+
if (this.config.debug) {
|
|
7946
|
+
console.log("[Zaplier] Replay batch result:", result);
|
|
7947
|
+
}
|
|
7948
|
+
return result;
|
|
7949
|
+
}
|
|
7950
|
+
catch (error) {
|
|
7951
|
+
if (this.config.debug) {
|
|
7952
|
+
console.error("[Zaplier] Replay batch sending failed:", error);
|
|
7953
|
+
}
|
|
7954
|
+
return { success: false, error: error instanceof Error ? error.message : "Unknown error" };
|
|
7955
|
+
}
|
|
7956
|
+
}
|
|
7914
7957
|
/**
|
|
7915
7958
|
* Make HTTP request to backend using anti-adblock system
|
|
7916
7959
|
*/
|