Skip to content
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

API event targeting surveys should call getActiveMatchingSurveys callback when conditions are met #1498

Open
BrunnerLivio opened this issue Oct 24, 2024 · 1 comment

Comments

@BrunnerLivio
Copy link

BrunnerLivio commented Oct 24, 2024

Description

I have created an API survey with the Display Conditions: User sends events -> my_event.

Given the following example

posthog.getActiveMatchingSurveys(console.log)
setTimeout(() => posthog.capture('my_event'), 1000)

Expected behavior

I'd expect the following console output:

[]
[{ "type": "api", "id": "...",... }]

Current behavior

The actual console output:

[]

Given the code snippet above, if posthog.getActiveMatchingSurveys(console.log) is executed again, the
callback receives the expected argument

[{ "type": "api", "id": "...",... }]

Though I am looking for a push-based mechanism from getActiveMatchingSurveys rather than a pull-based, as shown in the "Expected Behavior"

@NadiraFarhat
Copy link

@BrunnerLivio
The issue may be related to the timing of when surveys are matched against the captured events—the first call to posthog.getActiveMatchingSurveys might be executed before the my_event is fully processed by PostHog's backend.

To help debug this further:

  1. Confirm if there’s any delay in event processing by adding logs before and after posthog.capture('my_event').
  2. Test with a longer setTimeout duration to check if the issue resolves when more time is given for event propagation.
  3. Review the PostHog documentation or implementation details to confirm whether getActiveMatchingSurveys relies on specific event-processing timeframes.
  4. If this is indeed a delay issue, one solution might involve ensuring a sufficient delay between event capture and survey retrieval.

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

No branches or pull requests

3 participants