Event filtering does not work with posthog surveys
Bug description
The survey display conditions do not respect the "User sends events" filter. When its set to X event, and from application using posthog-js SDK, the method "canRenderSurveyAsync" is returning visible property to true always, even when user has not sent X event yet.
How to reproduce
- Create a survey and set Event filters to an event
- Send any event using SDK
- Call "canRenderSurveyAsync" method
- {visible: true} returned, regardless of the event that was being sent
Related sub-libraries
- [ ] All of them
- [x] posthog-js (web)
- [ ] posthog-js-lite (web lite)
- [ ] posthog-node
- [ ] posthog-react-native
- [x] @posthog/react
- [ ] @posthog/ai
- [ ] @posthog/nextjs-config
Additional context
Posthog host: https://eu.i.posthog.com
Thank you for your bug report – we love squashing them!
@PostHog/team-surveys
hey @AmmarKhalid123 thanks for the bug report
can you tell me more about your use case? do you intend to render surveys manually? did that issue cause any trouble for you?
I'll fix the issue, as it's indeed an unintended behavior, but let me first just explain how it works:
- each second, we check if a survey can be rendered (this is the
canRenderSurveymethod`). It checks if the survey was already rendered, if it's tied to a feature flag, and anything related to display conditions in general - if the survey has an event attached to it, it also means checking if this event was checked recently
So, the canRenderSurvey method indeed skip the event check logic. However, this check is added on the rendering logic. Because, if the event was fired, we need to check it right away.
I'll prob unify the logic so the canRenderSurvey method incorporates the event testing directly, this way we have one unique function for that.
Hi @lucasheriques , thanks for getting back. In my use case:
After event X is fired by the user, I call canRenderSurveyAsync to decide whether to display the survey manually based on its response. Since I want to show the form only once per user (which I’ve set in the completion condition), I expected canRenderSurveyAsync to return:
- false by default, or when the user triggers event “X” but the survey has already been rendered
- true when the user triggers event “X” and the survey has not yet been rendered
However, it currently always returns true by default. Overall, I believe canRenderSurveyAsync (as the name implies) should respect checks for events and their properties, feature flags, person properties and all other filters. That would resolve the issue for me. Let me know if you have any follow-up questions or if my understanding is off. Thank you. :))