@temps-sdk/react-analytics 0.0.1-beta.23 → 0.0.1-beta.25

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.
@@ -1 +1 @@
1
- {"version":3,"file":"SessionRecorder.d.ts","sourceRoot":"","sources":["../src/SessionRecorder.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,yBAAyB,mBAAmB,CAAC;AAE1D,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AA+CD,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EAAG,uBAAuB;AAClC,MAAM,EACN,OAAe,EACf,aAAkB,EAClB,iBAAuB,EACvB,aAAoB,EACpB,gBAAgC,EAChC,UAAuB,EACvB,WAAyB,EACzB,aAAyB,EACzB,YAAoB,EACpB,YAAoB,EACpB,cAUC,EACD,SAAe,EACf,aAAoB,GACrB,EAAE,oBAAoB,QA4XtB"}
1
+ {"version":3,"file":"SessionRecorder.d.ts","sourceRoot":"","sources":["../src/SessionRecorder.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,yBAAyB,mBAAmB,CAAC;AAE1D,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AA2CD,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EAAG,uBAAuB;AAClC,MAAM,EACN,OAAe,EACf,aAAkB,EAClB,iBAAuB,EACvB,aAAoB,EACpB,gBAAgC,EAChC,UAAuB,EACvB,WAAyB,EACzB,aAAyB,EACzB,YAAoB,EACpB,YAAoB,EACpB,cAUC,EACD,SAAe,EACf,aAAoB,GACrB,EAAE,oBAAoB,QAoZtB"}
@@ -28,21 +28,17 @@ function getSessionMetadata(domain) {
28
28
  const screen = window.screen || {};
29
29
  const navigator = window.navigator || {};
30
30
  return {
31
- visitor_id: generateVisitorId(),
32
- domain: domain || window.location.hostname,
33
- request_path: window.location.pathname,
34
- request_query: window.location.search,
35
- referrer: document.referrer,
36
- user_agent: navigator.userAgent,
37
- screen_width: screen.width,
38
- screen_height: screen.height,
39
- viewport_width: window.innerWidth,
40
- viewport_height: window.innerHeight,
41
- device_pixel_ratio: window.devicePixelRatio || 1,
31
+ visitorId: generateVisitorId(),
32
+ userAgent: navigator.userAgent,
42
33
  language: navigator.language,
43
- platform: navigator.platform,
44
34
  timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
45
- started_at: new Date().toISOString(),
35
+ screenWidth: screen.width,
36
+ screenHeight: screen.height,
37
+ colorDepth: screen.colorDepth || 24,
38
+ viewportWidth: window.innerWidth,
39
+ viewportHeight: window.innerHeight,
40
+ url: window.location.href,
41
+ timestamp: new Date().toISOString(),
46
42
  };
47
43
  }
48
44
  export function SessionRecorder({ basePath, // Required, no default
@@ -110,7 +106,7 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
110
106
  sessionIdRef.current = sessionId;
111
107
  try {
112
108
  const metadata = {
113
- session_id: sessionId,
109
+ sessionId: sessionId,
114
110
  ...getSessionMetadata(domain),
115
111
  };
116
112
  const response = await fetch(`${basePath}/${SESSION_RECORDER_ENDPOINT}/init`, {
@@ -163,14 +159,15 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
163
159
  if (events.length === 0)
164
160
  return;
165
161
  const eventsToSend = [...events];
166
- eventsRef.current = [];
162
+ // Don't clear the array immediately - clear only after successful send
163
+ // eventsRef.current = [];
167
164
  try {
168
165
  // Pack the events for more efficient transmission
169
166
  const packedEvents = pack(eventsToSend);
170
167
  // Base64 encode the packed string for safe JSON transmission
171
168
  const encodedEvents = btoa(packedEvents);
172
169
  const payload = {
173
- session_id: sessionIdRef.current,
170
+ sessionId: sessionIdRef.current,
174
171
  events: encodedEvents,
175
172
  };
176
173
  const url = `${basePath}/${SESSION_RECORDER_ENDPOINT}/events`;
@@ -188,6 +185,9 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
188
185
  keepalive: true,
189
186
  });
190
187
  }
188
+ // For reliable sends, we don't clear events as they're sent via beacon
189
+ // which doesn't provide response feedback
190
+ eventsRef.current = [];
191
191
  }
192
192
  else {
193
193
  // Fallback to fetch with keepalive
@@ -197,6 +197,8 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
197
197
  body: JSON.stringify(payload),
198
198
  keepalive: true,
199
199
  });
200
+ // Clear events after successful send
201
+ eventsRef.current = [];
200
202
  }
201
203
  }
202
204
  else {
@@ -220,27 +222,42 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
220
222
  stopFnRef.current = null;
221
223
  }
222
224
  // Don't restore events - they're lost
225
+ eventsRef.current = [];
223
226
  }
224
227
  else if (!response.ok) {
225
228
  console.error("[SessionRecorder] Failed to send events:", response.status);
226
- // Restore events on failure
227
- eventsRef.current.unshift(...eventsToSend);
229
+ // Don't restore events - keep them for next attempt
230
+ // eventsRef.current.unshift(...eventsToSend);
231
+ }
232
+ else {
233
+ // Clear events after successful send
234
+ eventsRef.current = [];
228
235
  }
229
236
  }
230
237
  }
231
238
  catch (error) {
232
239
  console.error("[SessionRecorder] Failed to send session events:", error);
233
- // Restore events on failure
234
- eventsRef.current.unshift(...eventsToSend);
240
+ // Don't restore events - keep them for next attempt
241
+ // eventsRef.current.unshift(...eventsToSend);
235
242
  }
236
- }, [basePath, initializeSession]);
243
+ }, [basePath]);
237
244
  const scheduleFlush = useCallback(() => {
238
245
  if (flushTimeoutRef.current) {
239
246
  clearTimeout(flushTimeoutRef.current);
240
247
  }
241
- flushTimeoutRef.current = setTimeout(() => {
248
+ const flushAndReschedule = () => {
242
249
  sendEvents(false);
243
- }, flushInterval);
250
+ // Always schedule the next flush, even if the current send fails
251
+ // This ensures continuous retry attempts
252
+ scheduleNextFlush();
253
+ };
254
+ const scheduleNextFlush = () => {
255
+ if (flushTimeoutRef.current) {
256
+ clearTimeout(flushTimeoutRef.current);
257
+ }
258
+ flushTimeoutRef.current = setTimeout(flushAndReschedule, flushInterval);
259
+ };
260
+ scheduleNextFlush();
244
261
  }, [sendEvents, flushInterval]);
245
262
  const startRecording = useCallback(async () => {
246
263
  if (stopFnRef.current)
@@ -265,7 +282,7 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
265
282
  // Batch send when we reach the batch size
266
283
  if (eventsRef.current.length >= batchSize) {
267
284
  sendEvents(false);
268
- scheduleFlush();
285
+ // scheduleFlush() is now called automatically after each send
269
286
  }
270
287
  },
271
288
  sampling: {
@@ -273,6 +290,8 @@ domain, enabled = false, excludedPaths = [], sessionSampleRate = 1.0, maskAllInp
273
290
  media: 800,
274
291
  input: "last"
275
292
  },
293
+ blockSelector: "[data-private]",
294
+ ignoreSelector: "[data-ignore]",
276
295
  recordCanvas,
277
296
  collectFonts,
278
297
  maskAllInputs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temps-sdk/react-analytics",
3
- "version": "0.0.1-beta.23",
3
+ "version": "0.0.1-beta.25",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",