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

Feature flag value changes after identify, `Flag persistence` is enabled

Open O4epegb opened this issue 1 month ago • 1 comments

Bug description

Feature flag value changes after identify, Flag persistence is enabled

How to reproduce

Demo: https://stackblitz.com/edit/vitejs-vite-61subwxi?file=index.html

Steps:

  • visit the page, it will display in what branch current anon user is.
  • click identify to identify as test user and to see in what branch you are - control or show
  • you might see the issue right away if there is a mismatch, if not - continue with next step
  • If you didn't encounter the issue - now open new incognito page or press reset button until initial anonymous user gets into a different brach (e.g. if the test user is in control then reset until you initial user lands into show)
  • press identify
  • you will see that feature flag has changed, even though it's a persistent flag with person_profiles: 'always' etc

Quote from docs:

Feature flag values are calculated based on a user's properties. Since it's possible for a user to have different properties before and after login, they may receive different feature flag values before and after logging in.

By enabling the option to persist feature flags across authentication, you ensure that the flag value remains the same.

As far as I understand, this situation should not happen, at least with fresh session, if the fresh anon user saw show it should not change to control after identify. Otherwise I don't see a point of persistence flags at all, if they don't work in this case then I don't quite understand when they work at all, maybe I'm still missing some crucial info though 😅

Related sub-libraries

  • [ ] All of them
  • [x] posthog-js (web)
  • [ ] posthog-js-lite (web lite)
  • [ ] posthog-node
  • [ ] posthog-react-native
  • [ ] @posthog/react
  • [ ] @posthog/ai
  • [ ] @posthog/nextjs-config
  • [ ] @posthog/nuxt
  • [ ] @posthog/rollup-plugin
  • [ ] @posthog/webpack-plugin

Additional context

Project info

Session: https://us.posthog.com/project/sTMFPsFhdP1Ssg/replay/0197201d-88ae-76a0-9c20-7acc32fb6a27?t=2598
Admin: http://go/adminOrgEU/0197201e-8a1e-0000-1b08-3d3706945667 (project ID 69186)

O4epegb avatar Nov 24 '25 12:11 O4epegb

cc @PostHog/team-feature-flags

marandaneto avatar Nov 24 '25 17:11 marandaneto