@zaplier/sdk 1.2.5 → 1.2.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.
package/dist/index.esm.js CHANGED
@@ -7247,10 +7247,13 @@ class SessionReplayEngine {
7247
7247
  * Send batch of events
7248
7248
  */
7249
7249
  sendBatch() {
7250
- if (this.events.length === 0)
7250
+ if (this.events.length === 0) {
7251
+ console.log('[Zaplier] No events to send in batch');
7251
7252
  return;
7253
+ }
7252
7254
  const batch = [...this.events];
7253
7255
  this.events = [];
7256
+ console.log(`[Zaplier] Sending batch with ${batch.length} events for session ${this.sessionId}`);
7254
7257
  const payload = {
7255
7258
  sessionId: this.sessionId,
7256
7259
  events: batch,
@@ -7276,39 +7279,55 @@ class SessionReplayEngine {
7276
7279
  try {
7277
7280
  // Try WebRTC first if anti-adblock manager is available
7278
7281
  if (this.antiAdblockManager) {
7282
+ console.log('[Zaplier] Trying WebRTC transport...');
7279
7283
  const result = await this.antiAdblockManager.send(payload, '/replays/record');
7280
7284
  if (result.success) {
7285
+ console.log('[Zaplier] Session replay sent via WebRTC');
7281
7286
  return; // Success via WebRTC
7282
7287
  }
7288
+ console.log('[Zaplier] WebRTC failed, falling back to fetch');
7283
7289
  }
7284
7290
  // Get API endpoint from global config
7285
7291
  const apiEndpoint = window.zaplier_config?.apiEndpoint || 'http://localhost:3001';
7286
- const token = window.zaplier_config?.token || '';
7292
+ const token = window.zaplier_config?.token || 'ws_demo_token';
7293
+ const url = `${apiEndpoint}/replays/record?token=${token}`;
7294
+ console.log(`[Zaplier] Sending replay batch to ${url}`);
7295
+ console.log(`[Zaplier] Payload:`, {
7296
+ sessionId: payload.sessionId,
7297
+ eventCount: payload.events.length,
7298
+ hasMetadata: !!payload.metadata
7299
+ });
7300
+ const requestBody = {
7301
+ sessionId: payload.sessionId,
7302
+ events: payload.events,
7303
+ metadata: {
7304
+ startUrl: window.location.href,
7305
+ duration: Date.now() - (performance.timeOrigin || Date.now()),
7306
+ funnelSteps: [],
7307
+ hasConversion: false,
7308
+ ...payload.metadata
7309
+ }
7310
+ };
7287
7311
  // Fallback to standard fetch
7288
- const response = await fetch(`${apiEndpoint}/replays/record?token=${token}`, {
7312
+ const response = await fetch(url, {
7289
7313
  method: 'POST',
7290
7314
  headers: { 'Content-Type': 'application/json' },
7291
- body: JSON.stringify({
7292
- sessionId: payload.sessionId,
7293
- events: payload.events,
7294
- metadata: {
7295
- startUrl: window.location.href,
7296
- duration: Date.now() - (performance.timeOrigin || Date.now()),
7297
- funnelSteps: [],
7298
- hasConversion: false,
7299
- ...payload.metadata
7300
- }
7301
- })
7315
+ body: JSON.stringify(requestBody)
7302
7316
  });
7317
+ const responseText = await response.text();
7303
7318
  if (!response.ok) {
7304
- console.warn('[Zaplier] Session replay batch failed to send:', response.status);
7319
+ console.error('[Zaplier] Session replay batch failed:', {
7320
+ status: response.status,
7321
+ statusText: response.statusText,
7322
+ response: responseText
7323
+ });
7305
7324
  }
7306
7325
  else {
7307
- console.log('[Zaplier] Session replay batch sent successfully');
7326
+ console.log('[Zaplier] Session replay batch sent successfully:', responseText);
7308
7327
  }
7309
7328
  }
7310
7329
  catch (error) {
7311
- console.warn('[Zaplier] Session replay error:', error);
7330
+ console.error('[Zaplier] Session replay error:', error);
7312
7331
  }
7313
7332
  }
7314
7333
  /**