Skip to content

Commit

Permalink
fix: allow changing person properties after identify
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Nov 12, 2024
1 parent bd1ec53 commit a5e6feb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
20 changes: 16 additions & 4 deletions posthog/src/main/java/com/posthog/PostHog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit a5e6feb

Please sign in to comment.