posthog-js
posthog-js copied to clipboard
Popover surveys not showing up when serving bundled posthog with disable_external_dependency_loading set to true
Bug description
When using the JavaScript Web SDK and bundling the posthog dependencies as described in the docs, the popover surveys are not showing up when they should.
The survey is correctly configured in Posthog without any display conditions, and it was also never dismissed by the user (or shown).
As far as I could debug this issue, the problem seems to be that the line https://github.com/PostHog/posthog-js/blob/0b40e5af5381c7d356de31fc0458e91afbfa9a6b/src/posthog-surveys.ts#L82 is never executed because of the check for the surveysGenerator
on line https://github.com/PostHog/posthog-js/blob/0b40e5af5381c7d356de31fc0458e91afbfa9a6b/src/posthog-surveys.ts#L73, which is set here https://github.com/PostHog/posthog-js/blob/864169ca3f862b57819f26af2aacf8c0a67ee928/src/entrypoints/surveys.ts#L9 and executed when the bundled file is loaded in the browser.
I could workaround the issue by patching the surveys.instance._surveyManager
variable with:
posthog.surveys._surveyManager = window.extendPostHogWithSurveys(posthog.surveys.instance);
After the above line is executed, the survey popover immediatelly shows up.
If this affects the front-end, screenshots would be of great help.
--
If you are on PostHog Cloud it would be really valuable if you can share any links where the problem occurs. This speeds up our ability to troubleshoot tremendously.
--
How to reproduce
- Create popover survey and launch it
- Create an frontend application using the bundled posthog as described in the docs.
- Call
posthog.init
passingtrue
todisable_external_dependency_loading
Environment
- [ ] PostHog Cloud US, project ID: [please provide from https://us.posthog.com/settings/project-details#variables]
- [X] PostHog Cloud EU, project ID: [please provide from https://eu.posthog.com/settings/project-details#variables]
- [ ] PostHog Hobby self-hosted with
docker compose
, version/commit: [please provide] - [ ] PostHog self-hosted with Kubernetes (deprecated, see "Sunsetting Kubernetes support"), version/commit: [please provide]
Additional context
We are using posthog in our frontend application built using Nuxt