PostHog / posthog-js

Send usage data from your web app or site to PostHog, with autocapture.
https://posthog.com/docs/libraries/js
Other
280 stars 118 forks source link

Posthog event->properties once set using posthog sdk register API has inconsistent fallback mechanisms. #1234

Closed brijeshbv closed 2 months ago

brijeshbv commented 4 months ago

Bug Description

Setting any properties to event during registration using the posthog.register() API has unexpected fallback mechanisms for users. Expectation: Any event set using posthog.register() should last only for the current browser session. If this is wrong, then my bug is invalid.

The flag from a previous browser session, is remembered for future sessions even if the event is not set at all in future sessions.

Removing browser cache/history does not solve the issue. I'm assuming the event is remembered based on some backend logic.

How to reproduce

  1. set event property using posthog.register() conditionally on the front-end.
  2. for future sessions where the event property is not set, the event property is still remembered and injected into the analytics event.
  3. Using a different browser solves the issue. Not setting a flag and leaving it empty has unexpected fallback mechanisms from out of current session history.

Additional context

Client version: "posthog-js": "^1.91.1",

pauldambra commented 3 months ago

hey @brijeshbv

that version of posthog-js is from 2023-11-15, can you update and check if the problem still exists.

posthog.register stores the property in whatever persistence mechanism you have set for the browser. so, it depends what you mean by "browser session". if you're using localstorage+cookie or cookie persistence then registered properties will persist longer than an instance of a browser window or tab