Skip to content

feat(surveys): support survey popup delay#520

Open
adboio wants to merge 2 commits intomainfrom
03-10-feat_surveys_support_survey_popup_delay
Open

feat(surveys): support survey popup delay#520
adboio wants to merge 2 commits intomainfrom
03-10-feat_surveys_support_survey_popup_delay

Conversation

@adboio
Copy link
Copy Markdown
Contributor

@adboio adboio commented Mar 10, 2026

💡 Motivation and Context

ios does not support survey popup delay

closes #499

💚 How did you test it?

unit test / manual testing

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file
  • Added the release label to the PR

Copy link
Copy Markdown
Contributor Author

adboio commented Mar 10, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@adboio adboio added the release label Mar 10, 2026 — with Graphite App
@adboio adboio requested a review from a team March 10, 2026 23:52
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 11, 2026

posthog-ios Compliance Report

Date: 2026-04-07 17:18:14 UTC
Duration: 433ms

✅ All Tests Passed!

0/0 tests passed


@adboio adboio force-pushed the 03-10-feat_surveys_support_survey_popup_delay branch 2 times, most recently from 8caa460 to eaaf956 Compare March 11, 2026 18:21
@adboio adboio force-pushed the 03-10-feat_surveys_support_event_property_filters branch from a334421 to 81c5433 Compare March 11, 2026 18:21
@adboio adboio changed the base branch from 03-10-feat_surveys_support_event_property_filters to graphite-base/520 March 11, 2026 19:32
@adboio adboio force-pushed the graphite-base/520 branch from 81c5433 to a9366ad Compare March 11, 2026 19:32
@adboio adboio force-pushed the 03-10-feat_surveys_support_survey_popup_delay branch from eaaf956 to b7c6843 Compare March 11, 2026 19:32
@graphite-app graphite-app bot changed the base branch from graphite-base/520 to main March 11, 2026 19:32
@adboio adboio force-pushed the 03-10-feat_surveys_support_survey_popup_delay branch from b7c6843 to 268e6e5 Compare March 11, 2026 19:32
@adboio adboio force-pushed the 03-10-feat_surveys_support_survey_popup_delay branch from 268e6e5 to 9e7acb3 Compare March 12, 2026 17:27
@marandaneto
Copy link
Copy Markdown
Member

@adboio @ioannisj what is missing here? no reviews and still draft

@marandaneto marandaneto reopened this Mar 24, 2026
@ioannisj ioannisj marked this pull request as ready for review April 7, 2026 17:06
]

let sorted = surveys.sorted {
($0.appearance?.surveyPopupDelaySeconds ?? 0) < ($1.appearance?.surveyPopupDelaySeconds ?? 0)
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.

nit: I think this could be flaky cause .sorted is not guaranteed to be stable for equal keys I think. Maybe add tie-breaker as well or remove the scenario where there are equal keys (no-delay and delayed-0)

Also, this just duplicates production code, so if we change sorting at some point, this will still pass. I think we just need to test what getActiveMatchingSurveys returns instead

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.

On first point above, actually it seems that it's guaranteed, so never mind

https://developer.apple.com/documentation/swift/array/sorted()

The sorting algorithm is guaranteed to be stable. A stable sort preserves the relative order of elements that compare as equal.

Comment on lines +296 to +297
let delay = survey.appearance?.surveyPopupDelaySeconds ?? 0
let deadline: DispatchTime = delay > 0 ? .now() + delay : .now()
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.

I think this may be a bit unecessary and just adds noise. We could just do this?

Suggested change
let delay = survey.appearance?.surveyPopupDelaySeconds ?? 0
let deadline: DispatchTime = delay > 0 ? .now() + delay : .now()
let delay = max(survey.appearance?.surveyPopupDelaySeconds ?? 0, 0)
let deadline: DispatchTime = .now() + delay

Comment on lines +288 to +290
let sortedSurveys = activeSurveys.sorted {
($0.appearance?.surveyPopupDelaySeconds ?? 0) < ($1.appearance?.surveyPopupDelaySeconds ?? 0)
}
Copy link
Copy Markdown
Contributor

@ioannisj ioannisj Apr 7, 2026

Choose a reason for hiding this comment

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

Does web sdk behave similar to this? This feels like the wrong approach to me cause it changes the whole survey selection behavior, right? Now surveys with a smaller delay are given display priority, whereas before, selection was simply by first(where:) to a list returned by the server/config

I feel that the delay should actually be handled in the UI layer, in PostHogSurveysDefaultDelegate where the delegate will delay the presentation of a survey (and handle the dismissal scenario before delay like we do in L302) after the survey has been selected by getActiveMatchingSurveys()

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.

Yes, looks like js SDK is performing this delay logic in display layer in handlePopoverSurvey

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement survey popup delay (surveyPopupDelaySeconds)

3 participants