Repository navigation
fix(surveys): start the wait period on show and ignore closes before display - #1049
Merged
turnipdabeets merged 2 commits intoNov 9, 2026
Merged
Conversation
…display Port of #1046 to 3.x. Submitting or dismissing a survey no longer moves the last-seen survey date; it is written when the survey is shown (or on the first answer for delegates that never report it shown). A close before the survey is shown only releases the reservation, and reset() cancels a survey still waiting out its popup delay. getNextSurveyStep and its helper move unchanged into PostHogSurveyMatching.swift to keep PostHogSurveyIntegration.swift under SwiftLint's file-length error limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eset `surveysConfig` is iOS 15+ on 3.x, so the reset hook failed to compile for iOS 13. Use `_surveysConfig` like the integration's other call sites. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR overviewNo security issues were found in this pull request. Reviews
|
Contributor
posthog-ios Compliance ReportDate: 2026-11-09T18:32:05.045645+00:00
|
| Test | Status | Duration |
|---|---|---|
| Format Validation.Event Has Required Fields | ✅ | 2921ms |
| Format Validation.Event Has Uuid | ✅ | 2755ms |
| Format Validation.Event Has Lib Properties | ✅ | 2797ms |
| Format Validation.Distinct Id Is String | ✅ | 445ms |
| Format Validation.Token Is Present | ✅ | 2720ms |
| Format Validation.Custom Properties Preserved | ✅ | 2646ms |
| Format Validation.Event Has Timestamp | ✅ | 2719ms |
| Format Validation.Non Utc Event Timestamp Is Converted To Utc | ✅ | 2781ms |
| Retry Behavior.Retries On 503 | ✅ | 12017ms |
| Retry Behavior.Does Not Retry On 400 | ✅ | 4725ms |
| Retry Behavior.Does Not Retry On 401 | ✅ | 4768ms |
| Retry Behavior.Respects Retry After Header | ✅ | 7708ms |
| Retry Behavior.Implements Backoff | ✅ | 21295ms |
| Retry Behavior.Retries On 500 | ✅ | 9252ms |
| Retry Behavior.Retries On 502 | ✅ | 9294ms |
| Retry Behavior.Retries On 504 | ✅ | 5243ms |
| Retry Behavior.Max Retries Respected | ❌ | 21808ms |
| Deduplication.Generates Unique Uuids | ✅ | 2873ms |
| Deduplication.Preserves Uuid On Retry | ✅ | 9124ms |
| Deduplication.Preserves Uuid And Timestamp On Retry | ✅ | 10392ms |
| Deduplication.Preserves Uuid And Timestamp On Batch Retry | ✅ | 7803ms |
| Deduplication.No Duplicate Events In Batch | ✅ | 2861ms |
| Deduplication.Different Events Have Different Uuids | ✅ | 2717ms |
| Compression.Sends Gzip When Enabled | ✅ | 2715ms |
| Batch Format.Uses Proper Batch Structure | ✅ | 2698ms |
| Batch Format.Flush With No Events Sends Nothing | ✅ | 212ms |
| Batch Format.Multiple Events Batched Together | ✅ | 2877ms |
| Error Handling.Does Not Retry On 403 | ✅ | 5085ms |
| Error Handling.Does Not Retry On 413 | ✅ | 2392ms |
| Error Handling.Retries On 408 | ✅ | 8779ms |
Failures
retry_behavior.max_retries_respected
Expected 4 requests, got 6
Feature_Flags Tests
✅ 17/17 tests passed
View Details
| Test | Status | Duration |
|---|---|---|
| Request Payload.Request With Person Properties Device Id | ✅ | 2744ms |
| Request Payload.Flags Request Uses V2 Query Param | ✅ | 2779ms |
| Request Payload.Flags Request Hits Flags Path Not Decide | ✅ | 2700ms |
| Request Payload.Flags Request Omits Authorization Header | ✅ | 2767ms |
| Request Payload.Token In Flags Body Matches Init | ✅ | 2765ms |
| Request Payload.Groups Round Trip | ✅ | 2769ms |
| Request Payload.Groups Default To Empty Object | ✅ | 2720ms |
| Request Payload.Disable Geoip False Propagates As Geoip Disable False | ✅ | 2758ms |
| Request Payload.Disable Geoip Omitted Defaults To False | ✅ | 2702ms |
| Request Payload.Flag Keys To Evaluate Contains Only Requested Key | ✅ | 2803ms |
| Request Lifecycle.No Flags Request On Init Alone | ✅ | 108ms |
| Request Lifecycle.No Flags Request On Normal Capture | ✅ | 2752ms |
| Request Lifecycle.Two Flag Calls Produce Two Remote Requests | ✅ | 5499ms |
| Request Lifecycle.Mock Response Value Is Returned To Caller | ✅ | 2847ms |
| Retry Behavior.Retries Flags On 502 | ✅ | 2909ms |
| Retry Behavior.Retries Flags On 504 | ✅ | 2743ms |
| Side Effect Events.Get Feature Flag Captures Feature Flag Called Event | ✅ | 3158ms |
dustinbyrne
approved these changes
Nov 9, 2026
turnipdabeets
enabled auto-merge (squash)
November 9, 2026 20:53
turnipdabeets
deleted the
fix/survey-wait-period-and-closes-before-display
branch
November 9, 2026 20:58
6 of 18 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
These fix two Surveys gaps against the surveys spec:
setSurveySeenwrote it again on submit and dismiss, soseenSurveyWaitPeriodInDayscounted from the close. A survey shown on day 0 and dismissed on day 2 kept a 7-day-wait survey hidden until day 9.surveyPopupDelaySecondsin the default delegate (feat(surveys): support survey popup delay #520), and a customPostHogSurveysDelegatecan also delay. Two gaps:survey dismissed.reset()didn't cancel a survey waiting out its popup delay, so the previous user's survey still appeared after the delay, without asurvey shownevent.Changes
setSurveySeenno longer writes the last-seen date. Seen keys are unchanged.Each survey attempt records whether it was shown. The shown callback sets it, and so does the first answer, since an answer means the survey is on screen. The first answer also writes the date, but only for custom delegates that never call
onSurveyShown.A close before the survey is shown releases the reservation and does nothing else: no seen key, no date, no
survey dismissed, saved progress kept. It doesn't queue the next survey right away, so a delegate that can't display a survey doesn't get it re-rendered in a tight loop. The next normal trigger picks it up.reset()cancels a pending attempt from before the reset. With the default delegate it cancels the delayed display and leaves any survey already on screen alone. A custom delegate getscleanupSurveys(). A survey already on screen keeps its current behavior.getNextSurveyStepand its helper move unchanged intoPostHogSurveyMatching.swift. Without the move,PostHogSurveyIntegration.swiftwould be about 1,237 lines, over SwiftLint's 1,200-line error limit (it's 1,145 now).Patch changeset added.
The reset hook is guarded with
#if os(iOS) || TESTINGand reads the delegate through_surveysConfig, because 3.x still supports iOS 13.Not done: the spec's optional (SHOULD) eligibility re-check when the delay ends. The default delegate owns the timer, so it isn't a small change.
Merging into 4.0
When
mainis next merged intochore/v4-remove-deprecated, use the 4.0(!SWIFT_PACKAGE || Surveys)guard andsurveysConfigfor the reset hook, and add the behavior change to.changeset/v4-major-release.mdandMIGRATION.md.Behavior change
survey dismissedor marks the survey seen.💚 How did you test it?
New tests in
PostHogSurveyEventsTest:reset()releases a survey that hasn't been shown, and the old attempt's callbacks report nothing.reset()during a 0.2 s popup delay means the survey is never displayed.One existing test (
resumed completion and dismissal preserve seen history) closed a resumed survey without ever showing it. It now calls the shown callback first, the way a real UI would.macOS (SPM)
make test filter=Survey: 173 tests in 27 suites passed.main(no fix),make test filter=PostHogSurveyEventsTestfails the three macOS tests with 9 issues.make lint: 0 serious violations, no files need formatting. The warnings are already onmain.iOS simulator (iPhone 17e, iOS 26.4.1)
xcodebuild testhung before the runner connected, so I built the test bundle and ran it inside the simulator withxctest:PostHogSurveyEventsTest, this branchPostHogSurveyEventsTest,mainwith only the test file applied-XCTest All, this branchchanged beforeSend output is captured after relaunchandadd() racing with flush(). They ran while I was compiling the example app on the same machine. Rerun alone,PostHogIdentityTests(44) andPostHogLogsQueueTests(31) both passed. Every survey test passed.The first simulator build also caught an iOS 13 compile error:
surveysConfigis iOS 15+ on 3.x, so the reset hook reads_surveysConfig.Example app on the same simulator
I pointed
PostHogExampleat a local mock server that serves one popover survey and logs survey events. A launch argument either dismissed the survey 12 s after launch (throughcleanupSurveys(), which goes through the sameonSurveyClosedpath as the close button) or calledreset()6 s after launch. I didn't commit those changes. I ran each scenario againstmainand this branch:mainlastSeenSurveyDatewas18:39:14.726Z, the dismiss timelastSeenSurveyDatewas18:39:25.805Z, the show timereset()6 s after launchsurvey shownevent. The new user's attempt was then skipped ("Already displaying a survey"). No survey events were sent in 22 sreset()ran and was shown 8.4 s later, withsurvey shownsent under the new distinct ID📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code (Opus) wrote this with Bash, Read and Edit. The iOS simulator build caught
surveysConfigbeing iOS 15+ on 3.x, hence the_surveysConfigread. Every new test was checked to fail without the fix.🤖 Generated with Claude Code