posthog-js
posthog-js copied to clipboard
/decide endpoint gets called twice
On a normal pageload on app.posthog.com, /decide endpoint gets called twice in a row.
I believe it's because:
- We call /decide immediately on boot
- We call /decide on reloadFeatureFlags that happens after
.identify()
This causes extra load and traffic in an unneeded way
Related open issue: We reload flags immediately after we change identity or props.
Reloading as identity changes makes sense. However for props:
- The $identify or properties setting message gets put into a queue in posthog-js
- Once it hits out servers it will get put into another queue
- Only after some latency will plugin server pick it up and process it
All this means is that user property changes won't be reflected in a new /decide response that's made immediately after reloadFeatureFlags
.
Is this issue rly fixed? It still happens to me... Without identify()
, everything works as expected, 1 call to /decide and good. But whenever identify()
is called, another call to /decide is fired.
Hey @patricsteiner , this is by design, as when you call identify the identity changes.
If you always call identify right after load, then you can pass in the advanced_disable_feature_flags_on_first_load
setting, which will ensure no flags are loaded on first call to decide, effectively making things much faster.
@neilkakkar Oh, I didn't know that, thank you very much :) ...But the problem is when the user is logged in, then I immediately call identify, but i first need to check if he's logged in, and by that time posthog is already initialized. So when I pass the setting you mentioned and then the user is not logged in, i dont have any featureflags. 😅