-
Notifications
You must be signed in to change notification settings - Fork 78
feat(surveys): add displaySurvey to show a survey on demand #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bs1180
wants to merge
2
commits into
main
Choose a base branch
from
posthog-code/display-survey-manual-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "posthog_flutter": minor | ||
| --- | ||
|
|
||
| Add `Posthog().displaySurvey(surveyId)` to display a survey on demand, bypassing display conditions (targeting flags, event triggers, and seen/wait-period checks). This is the counterpart of the web SDK's `posthog.displaySurvey()` and also enables API-type surveys, which are never auto-displayed. On Android and iOS the survey is displayed by the native SDK (requires posthog-android >= 3.56.0 / posthog-ios >= 3.67.0); on Web it is displayed by the JS SDK as a popover. |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
displaySurvey is completely non-functional on Flutter Web: PosthogFlutterWeb never forwards to the new handler case
Why we think it's a valid issue
posthog.dart:783-784(displaySurveyβ_posthog.displaySurvey), the platform-instance wiring inposthog_flutter_web.dart:40(registerWithsetsinstance = PosthogFlutterWeb()), the fullposthog_flutter_web.dart(lines 1-431), the abstract base inposthog_flutter_platform_interface.dart, the IO override, and the test files.PosthogFlutterWeboverrides every supported method to route throughhandleWebMethodCall(e.g.registerat web.dart:237,captureat 122) and even explicitly no-opsopenUrl/showSurvey(web.dart:358-365), but has NOdisplaySurveyoverride βgrepfordisplaySurveyreturns zero hits inposthog_flutter_web.dart. So on Web the call falls through to the abstract defaultFuture<void> displaySurvey(String surveyId) { throw UnimplementedError(...); }at platform_interface.dart:168-170. By contrastPosthogFlutterIO.displaySurvey(io.dart:515) does override and forward over the method channel.handleWebMethodCall(MethodCall('displaySurvey', ...)), which nothing invokes given the missing override β dead code on Web.posthog_flutter_io_test.dart:286exercises only the method-channel/IO path, andposthog_test.dart:693drives a hand-written fake (posthog_flutter_platform_interface_fake.dart:194) β neither instantiatesPosthogFlutterWebnor callshandleWebMethodCallwith'displaySurvey'.await Posthog().displaySurvey('id')on Flutter Web throwsUnimplementedErrorinstead of forwarding toposthog.displaySurvey(surveyId, {displayType: 'popover'}), so the Web behavior the PR adds and documents (doc-comment at posthog.dart:779-780: 'on Web it is rendered by the JS SDK as a popover') is entirely non-functional. This is a real, directly-introduced correctness/contract defect with a named trigger and consequence, and the fix (add the override mirroring the other methods + a Web test) is concrete and actionable.Issue description
The new
case 'displaySurvey':branch added tohandleWebMethodCall(lines 425-435) correctly builds and issues the JS SDK callposthog.displaySurvey(surveyId, {displayType: 'popover'}), but this code path is unreachable in practice. On Flutter Web,PosthogFlutterWeb.registerWithsetsPosthogFlutterPlatformInterface.instance = instance(lib/posthog_flutter_web.dart:40), andPosthog()._posthog(posthog.dart:22-23) calls methods directly on that instance rather than through the method channel. Every other platform-interface method thatPosthogFlutterWebsupports (setup, identify, capture, register, addExceptionStep, etc.) is explicitly overridden inposthog_flutter_web.dartto callhandleWebMethodCall(MethodCall(...))β butdisplaySurveyis not overridden there at all (confirmed by reading the full, currentlib/posthog_flutter_web.dart, which has nodisplaySurveyoverride). BecausePosthogFlutterPlatformInterfaceis abstract andPosthogFlutterWeb extendsit directly, callingPosthog().displaySurvey('survey-123')on Web resolves to the base class's default inposthog_flutter_platform_interface.dart:168-171:Future<void> displaySurvey(String surveyId) { throw UnimplementedError('displaySurvey() has not been implemented.'); }. That method is notasync, so theUnimplementedErroris thrown synchronously the moment the call is made, before the added JS-forwarding logic in this file ever runs. In other words, the entire Web implementation added by this PR (the extern JS binding at lines 69-70 and the switch case at 425-435) is dead code, and the feature the PR title/changeset/doc-comments advertise for Web ('on Web it is displayed by the JS SDK as a popover') is completely broken. This gap is not caught by the PR's new tests:posthog_flutter_io_test.dartonly exercises the IO/method-channel path (mobile), andposthog_test.dartonly exercises a hand-written fakePosthogFlutterPlatformInterfaceβ neither test instantiatesPosthogFlutterWebor invokeshandleWebMethodCallwith'displaySurvey', so nothing exercises the actual Web code path added here.Suggested fix
Add the missing override in
lib/posthog_flutter_web.dart(mirroring the pattern used for every other supported method, e.g.unregister/register) so calls are actually forwarded to this handler:Without this override, the switch case added in
posthog_flutter_web_handler.dartcan never execute. After adding the override, add a test that exercisesPosthogFlutterWeb().displaySurvey(...)(or at least callshandleWebMethodCallwith a'displaySurvey'MethodCall directly) so this regression is caught in CI, consistent with how the mobile path is tested inposthog_flutter_io_test.dart.Prompt to fix with AI (copy-paste)
Without this override, the switch case added in
posthog_flutter_web_handler.dartcan never execute. After adding the override, add a test that exercisesPosthogFlutterWeb().displaySurvey(...)(or at least callshandleWebMethodCallwith a'displaySurvey'MethodCall directly) so this regression is caught in CI, consistent with how the mobile path is tested inposthog_flutter_io_test.dart.</potential_solution>