From a5e6feb7e0a376f36c6b55986dea941188a8b5e1 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Tue, 12 Nov 2024 08:36:52 +0100 Subject: [PATCH] fix: allow changing person properties after identify --- CHANGELOG.md | 2 ++ posthog/src/main/java/com/posthog/PostHog.kt | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 608067cf..c5af48d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Next +- fix: allow changing person properties after identify ([#204](https://github.com/PostHog/posthog-android/pull/204)) + ## 3.9.1 - 2024-11-11 - recording: fix observation on multiple threads in layout/draw is not supported for compose ([#204](https://github.com/PostHog/posthog-android/pull/204)) diff --git a/posthog/src/main/java/com/posthog/PostHog.kt b/posthog/src/main/java/com/posthog/PostHog.kt index 1ecc29ee..e2404aef 100644 --- a/posthog/src/main/java/com/posthog/PostHog.kt +++ b/posthog/src/main/java/com/posthog/PostHog.kt @@ -556,6 +556,8 @@ public class PostHog private constructor( config?.logger?.log("identify called with invalid anonymousId: $anonymousId.") } + var shouldReloadFlags = false + if (previousDistinctId != distinctId && !isIdentified) { // this has to be set before capture since this flag will be read during the event // capture @@ -578,14 +580,24 @@ public class PostHog private constructor( config?.logger?.log("identify called with invalid former distinctId: $previousDistinctId.") } this.distinctId = distinctId + shouldReloadFlags = true + } else if (userProperties?.isNotEmpty() == true || userPropertiesSetOnce?.isNotEmpty() == true) { + capture( + "\$set", + distinctId = distinctId, + userProperties = userProperties, + userPropertiesSetOnce = userPropertiesSetOnce, + ) - // only because of testing in isolation, this flag is always enabled - if (reloadFeatureFlags) { - reloadFeatureFlags() - } + shouldReloadFlags = true } else { config?.logger?.log("already identified with id: $distinctId.") } + + // only because of testing in isolation, this flag(reloadFeatureFlags) is always enabled + if (shouldReloadFlags && reloadFeatureFlags) { + reloadFeatureFlags() + } } private fun hasPersonProcessing(): Boolean {