@tracelog/lib 2.5.1 → 2.6.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
@@ -131,6 +131,7 @@ tracelog.destroy();
131
131
  | `setCustomHeaders(provider)` | Add custom HTTP headers to requests (see [Custom Headers](#custom-headers)) |
132
132
  | `removeCustomHeaders()` | Remove custom headers provider |
133
133
  | `isInitialized()` | Check initialization status |
134
+ | `getSessionId()` | Get current session ID (or null) |
134
135
  | `setQaMode(enabled)` | Enable/disable QA mode (console logging) |
135
136
  | `destroy()` | Stop tracking and cleanup |
136
137
 
@@ -879,6 +880,24 @@ await tracelog.init({ /* same config */ });
879
880
 
880
881
  **→ [Full Error Handling Reference](./API_REFERENCE.md#error-handling)**
881
882
 
883
+ ### Session Continuity (External Redirects)
884
+
885
+ TraceLog automatically preserves sessions across external redirects (payment processors, OAuth flows, etc.) with zero developer action. Session data is mirrored to `sessionStorage` alongside `localStorage`, so when a user returns from an external site and `localStorage` is empty, the session is recovered from `sessionStorage` transparently.
886
+
887
+ ```typescript
888
+ // No special handling needed before redirect
889
+ window.location.href = paymentUrl;
890
+
891
+ // On the confirmation page, init() automatically recovers the session
892
+ const { sessionId } = await tracelog.init({ /* same config */ });
893
+ tracelog.event('purchase', { orderId: '12345', amount: 99.99 });
894
+ // Same session as before the redirect
895
+ ```
896
+
897
+ - Automatic: no API calls or developer action required
898
+ - `sessionStorage` mirror survives same-tab navigation (cleared on tab close)
899
+ - Session timeout still applies (expired sessions are not recovered)
900
+
882
901
  ---
883
902
 
884
903
  ## Privacy & Security
@@ -290,7 +290,7 @@ const Ot = () => {
290
290
  default:
291
291
  return We;
292
292
  }
293
- }, Bt = 1e3, Wt = 50, Gt = "2.5.0", Xt = Gt, nt = () => typeof window < "u" && typeof sessionStorage < "u", Qt = () => {
293
+ }, Bt = 1e3, Wt = 50, Gt = "2.5.1", Xt = Gt, nt = () => typeof window < "u" && typeof sessionStorage < "u", Qt = () => {
294
294
  try {
295
295
  const s = new URLSearchParams(window.location.search);
296
296
  s.delete(Je);
@@ -2857,18 +2857,28 @@ class Er extends w {
2857
2857
  }
2858
2858
  loadStoredSession() {
2859
2859
  const e = this.getSessionStorageKey(), t = this.storageManager.getItem(e);
2860
- if (!t)
2861
- return null;
2862
- try {
2863
- const r = JSON.parse(t);
2864
- return !r.id || typeof r.lastActivity != "number" ? null : r;
2865
- } catch {
2866
- return this.storageManager.removeItem(e), null;
2867
- }
2860
+ if (t !== null)
2861
+ try {
2862
+ const n = JSON.parse(t);
2863
+ if (n.id && typeof n.lastActivity == "number")
2864
+ return n;
2865
+ } catch {
2866
+ this.storageManager.removeItem(e);
2867
+ }
2868
+ const r = this.storageManager.getSessionItem(e);
2869
+ if (r !== null)
2870
+ try {
2871
+ const n = JSON.parse(r);
2872
+ if (n.id && typeof n.lastActivity == "number")
2873
+ return n;
2874
+ } catch {
2875
+ this.storageManager.removeSessionItem(e);
2876
+ }
2877
+ return null;
2868
2878
  }
2869
2879
  saveStoredSession(e) {
2870
- const t = this.getSessionStorageKey();
2871
- this.storageManager.setItem(t, JSON.stringify(e));
2880
+ const t = this.getSessionStorageKey(), r = JSON.stringify(e);
2881
+ this.storageManager.setItem(t, r), this.storageManager.setSessionItem(t, r);
2872
2882
  }
2873
2883
  getSessionStorageKey() {
2874
2884
  return wt(this.getProjectId());
@@ -2896,7 +2906,8 @@ class Er extends w {
2896
2906
  * 11. Sets up lifecycle listeners (visibilitychange, beforeunload)
2897
2907
  *
2898
2908
  * **Session Recovery**:
2899
- * - Checks localStorage for existing session
2909
+ * - Checks localStorage for existing session (primary)
2910
+ * - Falls back to sessionStorage mirror (survives external redirects)
2900
2911
  * - Recovers if session exists and is recent (within timeout window)
2901
2912
  * - NO SESSION_START event if session recovered
2902
2913
  *