Skip to content

feat: [SDK-5381] enqueue a session create when a new session starts - #1580

Open
fadi-george wants to merge 1 commit into
new-session-eventsfrom
fadi/sdk-5381
Open

fadi-george wants to merge 1 commit into
new-session-eventsfrom
fadi/sdk-5381

Conversation

@fadi-george

Copy link
Copy Markdown
Contributor

Description

1 Line Summary

When the sessions API flag is on, the service worker enqueues a session create when a new session starts.

Details

Part of the Web SDK Sessions stack (SDK-5381), on top of the SDK-5377 queue (#1571 to #1574). Android counterpart: OneSignal/OneSignal-Android-SDK#2797. iOS: OneSignal/OneSignal-iOS-SDK#1779.

  • upsertSession enqueues one create on the new-session path (no stored session, or the previous one is past the threshold) when the session's captured usesSessionsApi is true. It carries the local session ID, pinned OneSignal and subscription IDs, the subscription type, and start_time. The worker then sends the legacy on_session and drains the queue in parallel.
  • One create per session across tabs: upserts from other tabs, or a return within the session threshold, find the stored session and enqueue nothing. Threshold and multi-tab handling are unchanged.
  • No create is enqueued while an ID is still local, since queued records are never rewritten.
  • The page shim now loads the SDK only when navigator.locks exists, since the queue serializes IndexedDB work with Web Locks. This drops Chrome 61 to 68, Firefox 57 to 95, and legacy Safari push before 15.4.
  • Flag off: no create. The legacy session start is unchanged in both cases.
  • Size limits raised: SW 15.03 kB to 15.28 kB (queue enqueue code now in the worker), shim 405 B to 417 B.
  • Sessions still require a push subscription, as today; no product decision yet.
  • Not included: direct_attribution_id (SDK-5399), session end (SDK-5392).

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

Added ServiceWorker tests: create fields and drain with the flag on, one create across repeated upserts, no create on resume within the threshold, a new create after the threshold, no create with the flag off, and no create with a local ID. Added a shim loader test for a browser without Web Locks.

vp run lint, vp test run, and vp run build:prod pass locally. Not tested in a browser yet.

Checklist

  • All the automated tests pass or I explained why that is not possible
  • I have personally tested this on my machine or explained why that is not possible
  • I have included test coverage for these changes or explained why they are not needed

Programming Checklist
Interfaces:

  • Don't use default export
  • New interfaces are in model files

Functions:

  • Don't use default export
  • All function signatures have return types
  • Helpers should not access any data but rather be given the data to operate on.

Typescript:

  • No Typescript warnings
  • Avoid silencing null/undefined warnings with the exclamation point

Other:

  • Iteration: refrain from using elem of array syntax. Prefer forEach or use map
  • Avoid using global OneSignal accessor for context if possible. Instead, we can pass it to function/constructor so that we don't call OneSignal.context

Screenshots

Info

Not needed; no UI changes.

Checklist

  • I have included screenshots/recordings of the intended results or explained why they are not needed

Related Tickets

SDK-5381


🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant