Skip to content

feat(surveys): honor surveyPopupDelaySeconds before showing - #627

Open
o-mid wants to merge 5 commits into
PostHog:mainfrom
o-mid:fix/survey-popup-delay
Open

o-mid wants to merge 5 commits into
PostHog:mainfrom
o-mid:fix/survey-popup-delay

Conversation

@o-mid

@o-mid o-mid commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Plumbs surveyPopupDelaySeconds from Android/iOS survey payloads into PostHogDisplaySurveyAppearance.
  • SurveyService.showSurvey waits before opening the bottom sheet; zero, negative, or missing values still show immediately (same rule as native).
  • Hiding a survey (hideSurvey) or triggering another one during the wait drops the pending survey without calling onClosed, so a survey the user never saw isn't marked seen or dismissed.

Fixes #322

Test plan

  • flutter test test/survey_popup_delay_test.dart
  • flutter test test/surveys_test.dart test/survey_resume_test.dart

@turnipdabeets turnipdabeets left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @o-mid , a couple comments below.

Comment thread posthog_flutter/lib/src/surveys/survey_service.dart Outdated
Comment thread .changeset/survey-popup-delay.md Outdated
Comment thread posthog_flutter/lib/src/surveys/survey_service.dart
Comment thread posthog_flutter/lib/src/surveys/survey_service.dart Outdated
Comment thread posthog_flutter/test/survey_popup_delay_test.dart Outdated
@turnipdabeets
turnipdabeets requested a review from a team September 30, 2026 15:43
@o-mid
o-mid force-pushed the fix/survey-popup-delay branch from 9f9b7f1 to a8ba5a3 Compare October 4, 2026 11:18
o-mid and others added 2 commits October 7, 2026 11:58
Wire the appearance field through native maps and Dart models, wait in
SurveyService with cancel/replace semantics, and add widget tests.

Fixes PostHog#322
Wait out the delay on the same pending-show completer the context wait
uses, so a survey with no context after its delay waits for the next
navigation instead of being closed, and hideSurvey or a newer survey
cancels either wait. A navigation during the delay no longer cuts it
short. Cap the delay at one day so huge values can't overflow, drop the
redundant generation counter, and make the changeset a minor.

Co-authored-by: Omid Mirzaei <omidomirzaei@gmail.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@turnipdabeets
turnipdabeets force-pushed the fix/survey-popup-delay branch from a8ba5a3 to 4c8283d Compare October 7, 2026 16:01
@turnipdabeets turnipdabeets self-assigned this Oct 7, 2026
@turnipdabeets
turnipdabeets requested review from a team and removed request for a team October 7, 2026 18:00
Don't call onClosed for a survey hidden or replaced during its popup
delay. The user never saw it, so it must not be marked seen or send
`survey dismissed`, matching the wait-for-context path and the Android
surveys host. Native has already dropped that presentation by the time
Flutter cancels the delay, so nothing is left waiting for a close.

Make the replacement test fail if the replaced survey's timer keeps
running and shows the newer survey early.

Co-authored-by: Omid Mirzaei <omidomirzaei@gmail.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@turnipdabeets

Copy link
Copy Markdown
Contributor

Thanks @o-mid! I rebased this onto main and pushed a couple of follow-up commits to address the review.

@PostHog/team-client-libraries mind giving this a quick look before merging?

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI-assisted review.

One non-blocking timing-policy note inline: repeated matching Android events restart the pending delay, while the SDK spec does not define first-event versus last-event timing. This is a clarification, not a spec violation.

Comment thread posthog_flutter/lib/src/surveys/survey_service.dart
@dustinbyrne
dustinbyrne requested a review from a team October 7, 2026 18:59
@o-mid

o-mid commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews, @turnipdabeets and @dustinbyrne — the follow-up commits on the branch should cover the earlier feedback (minor changeset, delay cap, gate check, test timing, no onClosed when the sheet never showed).

I merged main into the branch so we’re current with #631’s context wait. On Dustin’s Android note: agreed with Anna’s take — track the repeat-trigger behavior in posthog-android#849 rather than adding first-deadline logic in Flutter.

Ready whenever someone with merge access wants to stamp it.

This branch has not been deployed

No deployments
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.

Implement survey popup delay (surveyPopupDelaySeconds)

3 participants