Skip to content

refactor(live-notifications): emit lifecycle as CDP track events#745

Draft
mahmoud-elmorabea wants to merge 2 commits into
feature/live-notificationsfrom
live-notifications-cdp-track-contract
Draft

refactor(live-notifications): emit lifecycle as CDP track events#745
mahmoud-elmorabea wants to merge 2 commits into
feature/live-notificationsfrom
live-notifications-cdp-track-contract

Conversation

@mahmoud-elmorabea

Copy link
Copy Markdown
Contributor

What

Moves the Android live-notification lifecycle off the bespoke /v1/live_activities/* REST API and onto CDP track events, matching the agreed SDK→CDP contract.

Edge op Event Key properties
start Live Notification eventType=start, instanceUUID, deviceId, platform=android, activityType, payload?
end Live Notification eventType=end, instanceUUID, deviceId, platform, activityType
register_push_to_start Live Notification Token registrationType=push_to_start, activityType, platform, deviceId, pushToStartToken

Decisions baked in (confirmed with backend)

  • All fields live under properties — the Segment TrackEvent envelope is fixed, so the edge reads them there (verified the same constraint holds on iOS).
  • deviceId = FCM token, and doubles as pushToStartToken (Android has no separate push-to-start token).
  • instanceUUID = client-generated activity id for local starts.
  • Instance-token registration dropped — no per-instance push token on Android.
  • Events are auth-only: dropped (debug-logged) while the user is anonymous; dedup signature is only stored once emitted, so registration re-fires after identify.

Mechanics

  • LiveNotificationLifecycleClient is now a thin mapper over DataPipeline.track; HTTP client, retry/backoff and registerInstance removed (the pipeline owns batching/retry/flush).
  • The delete PendingIntent now carries instanceUUID + activityType; the dismiss receiver reads the FCM token and emits end.

Testing

  • :messagingpush:testDebugUnitTest + :messagingpush:lintDebug green.
  • On emulator (java_layout, random login → workspace 122175), verified in logcat:
    • register_push_to_start per enabled type, with deviceId == pushToStartToken.
    • start with full payload and platform=android.
    • end covered by unit test (reportEnd) — see note below.

⚠️ Note for reviewers

Live notifications are rendered with setOngoing(true), so Android blocks swipe-to-dismiss — the dismiss receiver (our end trigger) won't fire from a user swipe in practice. This predates this PR but is in direct tension with the contract's "SDK sends end only when the user cancels the notification." Worth a follow-up decision (drop setOngoing, or trigger end another way).

🤖 Generated with Claude Code

Replace the bespoke /v1/live_activities REST client with two CDP track
events per the SDK→CDP contract:

- "Live Notification"        eventType=start  (local start via public API)
- "Live Notification"        eventType=end    (user dismissal)
- "Live Notification Token"  registrationType=push_to_start (per enabled type)

All contract fields ride under `properties` (the Segment track envelope is
fixed; the edge reads them there). `deviceId` is the FCM token and doubles as
`pushToStartToken`; `instanceUUID` is the client-generated activity id.
Events are gated on an identified user (auth-only). The instance-token flow is
dropped — Android has no per-instance push token.

The dismiss receiver now carries instanceUUID + activityType on the delete
PendingIntent and reads the FCM token to emit `end`. Retry/flush is handled by
the data pipeline, so the HTTP client, backoff and instance registration are
removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

Sample app builds 📱

Below you will find the list of the latest versions of the sample apps. It's recommended to always download the latest builds of the sample apps to accurately test the pull request.


@mahmoud-elmorabea mahmoud-elmorabea changed the title Live notifications: emit lifecycle as CDP track events refactor(live-notifications): emit lifecycle as CDP track events Jun 18, 2026
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 53.62319% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.70%. Comparing base (050f431) to head (0df98ab).

Files with missing lines Patch % Lines
...ngpush/livenotification/LiveNotificationManager.kt 0.00% 18 Missing ⚠️
...ivenotification/LiveNotificationDismissReceiver.kt 0.00% 10 Missing ⚠️
...push/livenotification/LiveNotificationRegistrar.kt 0.00% 3 Missing ⚠️
.../customer/messagingpush/di/DiGraphMessagingPush.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                       Coverage Diff                        @@
##             feature/live-notifications     #745      +/-   ##
================================================================
- Coverage                         66.80%   66.70%   -0.10%     
  Complexity                         1041     1041              
================================================================
  Files                               177      177              
  Lines                              5711     5713       +2     
  Branches                            786      785       -1     
================================================================
- Hits                               3815     3811       -4     
- Misses                             1607     1617      +10     
+ Partials                            289      285       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
  • java_layout: live-notifications-cdp-track-contract (1781803179)

@github-actions

Copy link
Copy Markdown
  • kotlin_compose: live-notifications-cdp-track-contract (1781803176)

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

📏 SDK Binary Size Comparison Report

Module Last Recorded Size Current Size Change in Size
core 34.07 KB 34.07 KB ✅ No Change
datapipelines 43.29 KB 43.29 KB ✅ No Change
messagingpush 70.20 KB 69.21 KB ⬇️ -0.99KB
messaginginapp 121.84 KB 121.84 KB ✅ No Change
tracking-migration 22.89 KB 22.89 KB ✅ No Change

@github-actions

Copy link
Copy Markdown

Build available to test
Version: live-notifications-cdp-track-contract-SNAPSHOT
Repository: https://central.sonatype.com/repository/maven-snapshots/

@github-actions

Copy link
Copy Markdown
  • java_layout: live-notifications-cdp-track-contract (1781803599)

@github-actions

Copy link
Copy Markdown
  • kotlin_compose: live-notifications-cdp-track-contract (1781803605)

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