@magicfeedback/popup-sdk 1.8.5 → 1.10.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/README.md CHANGED
@@ -123,6 +123,10 @@ Config fields:
123
123
  - `analytics?: { publicKey: string; integration: string }` — enables the real analytics
124
124
  delivery. Without it the analytics channel stays in dry-run: nothing is sent, and the
125
125
  payload is only logged when `debug` is on.
126
+ - `onFeedbackSession?: (session: { sessionId: string; status: 'open' | 'closed' }) => void` —
127
+ called when an analytics session opens or closes, with the id the Deepdots API stores as
128
+ `sdkSessionId` on the feedback the session becomes. See
129
+ [Linking your backend to a session](#linking-your-backend-to-a-session).
126
130
  - `geolocation?: boolean` — IP geolocation (country/city) for analytics, default `true`. It
127
131
  calls third-party services (`ipapi.co`, then `ipwho.is`, then `ipinfo.io` as fallbacks, 3 s
128
132
  timeout each, stopping at the first answer). It only runs when `analytics` is set, tracking
@@ -281,6 +285,42 @@ session start/end and unhandled errors are automatic. The rest is instrumented b
281
285
  | `setTrackingEnabled(enabled)` | Kill switch (consent) |
282
286
  | `reportError(error, options?)` | A handled error |
283
287
  | `previewAnalytics()` / `flushAnalytics()` | Inspect the pending payload / send it now |
288
+ | `getFeedbackSessionId()` / `init({ onFeedbackSession })` | The id of the feedback the current session becomes |
289
+
290
+ ### Linking your backend to a session
291
+
292
+ Every analytics session becomes one feedback in Deepdots, and the API stores the session's id
293
+ on it as `sdkSessionId`. Send that id to your backend and it can find the feedback
294
+ (`GET /feedbacks?filter={"where":{"sdkSessionId":"<id>"}}`) and add data to it later, such as
295
+ the push deliveries the app never sees. A session keeps that one feedback even when it closes
296
+ again (the app retries a closing batch whose response it lost, or a late batch lands after the
297
+ close): the API updates the feedback instead of creating another one.
298
+
299
+ ```ts
300
+ popups.init({
301
+ apiKey: 'YOUR_PUBLIC_API_KEY',
302
+ analytics: { publicKey: 'YOUR_PUBLIC_API_KEY', integration: 'YOUR_INTEGRATION_ID' },
303
+ onFeedbackSession: ({ sessionId, status }) => {
304
+ // 'open': first batch accepted. 'closed': the feedback exists within seconds.
305
+ myBackend.reportSession(sessionId, status);
306
+ },
307
+ });
308
+ ```
309
+
310
+ - `open` comes when the API accepts the session's first batch, `closed` when it accepts the
311
+ closing one (`completed: true`). A session whose only batch is the closing one reports just
312
+ `closed`.
313
+ - `closed` does not come when the page unloads before the closing request returns, for a
314
+ session dropped after 30 minutes hidden, nor when the closing request fails (network error,
315
+ 5xx): its events are re-sent with the next session and the API closes the old record itself,
316
+ later. In all three cases the id already came with `open`.
317
+ - Key what you store by `sessionId`, not by arrival order: the closing request and the next
318
+ session's first one go out in parallel, so the new session's `open` can arrive before the
319
+ previous one's `closed`.
320
+ - `getFeedbackSessionId()` returns the open session's id, or `null` before its first batch is
321
+ accepted and after it closes.
322
+ - This is not `getSessionId()`, the SDK's own session id. That one travels in the metadata as
323
+ `deepdots_session_id`, and the feedback can't be looked up by it.
284
324
 
285
325
  ### Messaging — `trackMessage(stage, options)`
286
326