Closed marandaneto closed 1 month ago
See this comment before implementing https://github.com/PostHog/posthog/issues/10659#issuecomment-2142256209
Hi, can I take up this issue? I think adding the is_identified
property to the PostHog
class with a get()
getter that checks if the anonymousId
is not equal to the distinctId
, will solve this.
Hi, can I take up this issue? I think adding the
is_identified
property to thePostHog
class with aget()
getter that checks if theanonymousId
is equal to thedistinctId
, will solve this.
Hello, sure, feel free to open a Draft PR and I can guide you, I'd link at https://github.com/PostHog/posthog-js/blob/7022ab69505959fb065d41870d2bceeb69145916/src/posthog-core.ts#L912 instead since its more reliable than just comparing the distinctId and anonymousId.
Thanks for guiding me. Can you explain me why will it be more reliable than comparing them? Going through PostHog.kt
, what I've understood is that, if identify()
hasn't been invoked earlier i.e. distinctId
hasn't been set, then distinctId
defaults to the anonymousId
. Once identify()
is invoked, the distinctId
is changed and set to distinctId param of identify()
. So, comparing distinctId
and anonymousId
would be in my opinion a single source of truth to verify if the user is identified or not.
@beradeep good point and I don't disagree but this is a heuristics approach, this behavior may change hence implementing directly on identify
and reset
would be the correct approach without side effects in case this changes.
Ah, I see. Also going through posthog-js
, it seems that an "identify" event is captured only when new_distinct_id !== previous_distinct_id && isKnownAnonymous
is true
, however in posthog-android
, it is captured whenever we call identify()
. Is there any specific reason to that?
Ah, I see. Also going through
posthog-js
, it seems that an "identify" event is captured only whennew_distinct_id !== previous_distinct_id && isKnownAnonymous
istrue
, however inposthog-android
, it is captured whenever we callidentify()
. Is there any specific reason to that?
Nope, something I likely missed during the Android implementation or that was added after on the JS SDK, we can either address that too or make a new issue.
Nope, something I likely missed during the Android implementation or that was added after on the JS SDK, we can either address that too or make a new issue.
I'm sorry, I just noticed that there's already an open issue #108 mentioning this. Yes, I think both these issues are related, and can be resolved together.
Description
https://github.com/PostHog/posthog/pull/22216
$is_identified
is the property to filter identified users or not (anonymous).https://github.com/PostHog/posthog-js/blob/7022ab69505959fb065d41870d2bceeb69145916/src/posthog-core.ts#L912 JS SDK uses the
$user_state
super property to track if the user has identified already or not with the valuesidentified
oranonymous
(this super property is in deny list so not set in the event)Add to: