posthog-js icon indicating copy to clipboard operation
posthog-js copied to clipboard

/decide endpoint gets called twice

Open macobo opened this issue 3 years ago • 1 comments

On a normal pageload on app.posthog.com, /decide endpoint gets called twice in a row.

I believe it's because:

  1. We call /decide immediately on boot
  2. We call /decide on reloadFeatureFlags that happens after .identify()

This causes extra load and traffic in an unneeded way

macobo avatar Nov 18 '21 12:11 macobo

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.

macobo avatar Nov 18 '21 12:11 macobo

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.

patricsteiner avatar Aug 10 '23 11:08 patricsteiner

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 avatar Aug 10 '23 12:08 neilkakkar

@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. 😅

patricsteiner avatar Aug 13 '23 09:08 patricsteiner