Skip to content

Conversation

@nan-li
Copy link
Contributor

@nan-li nan-li commented Jan 20, 2026

Description

One Line Summary

Display IAMs with triggers added before first fetch on cold start.

Details

On subsequent cold starts, if triggers were added very early in the app lifecycle (before the first IAM fetch completed), in-app messages matching those triggers would not display even though they should have been eligible for redisplay.

Root cause: When the trigger is added, evaluateRedisplayedInAppMessages was called when the messages were empty, so message.isTriggerChanged was never set for messages that arrived later from the server.

Solution: Track trigger keys added before the first fetch completes in earlySessionTriggers, then apply isTriggerChanged to matching redisplay messages when they arrive from the server. This ensures the redisplay logic correctly identifies that triggers have changed and clears the message from seenInAppMessages.

Motivation

Provide feature that is requested

Scope

This only affects cold starts (process restarts) and does not impact warm starts from backgrounding, where existing redisplay behavior is preserved.

Testing

Unit testing

WIP

Manual testing

Tested on iOS 18.5 simulator
Add trigger immediately after initialization, and confirm the IAM now displays after the changes in this PR.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

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

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

@nan-li nan-li changed the base branch from main to fix/format_purchase_price_with_commas January 22, 2026 07:53
- Addresses issue where in-app messages wouldn't display on cold starts if their triggers were added very early (before IAM fetch completed).
- Tracks triggers added before first fetch completes, then applies the isTriggerChanged flag to matching messages when they are received from the server, ensuring redisplay logic works correctly.
Add comprehensive test coverage for the early trigger tracking feature that enables IAMs to display when triggers are added before the first fetch completes on cold start.
@nan-li nan-li force-pushed the feat/iam_trigger_latency branch from 6b3b1a9 to 4cd7760 Compare January 22, 2026 08:21
@nan-li nan-li requested a review from a team January 22, 2026 16:52
[self evaluateRedisplayedInAppMessages:triggers.allKeys];

// Track triggers added early on cold start (before first fetch completes) for redisplay logic
if (!self.hasCompletedFirstFetch) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we make sure there are no duplicates in this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we make sure this is thread safe?

[self evaluateRedisplayedInAppMessages:triggers.allKeys];

// Track triggers added early on cold start (before first fetch completes) for redisplay logic
if (!self.hasCompletedFirstFetch) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicates? Unsure what you mean, earlySessionTriggers is a set.

If clients are concurrently calling addTrigger from 2 threads, then the existing code would already be an issue?

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.

3 participants