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