Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

identify() doesn't update user properties. #120

Closed
choim4389 opened this issue Nov 6, 2024 · 13 comments
Closed

identify() doesn't update user properties. #120

choim4389 opened this issue Nov 6, 2024 · 13 comments
Labels
bug Something isn't working Product Analytics

Comments

@choim4389
Copy link

Version

4.6.0

Steps to Reproduce

Even though I used the same id, identify() doesn't update user properties(not once).
How to update user's properties using flutter sdk?

Expected Result

user properties must be changed if using same distinct id.

Actual Result

user properties not changed.

@choim4389 choim4389 added the bug Something isn't working label Nov 6, 2024
@marandaneto
Copy link
Member

marandaneto commented Nov 6, 2024

@choim4389 can you share the code snippet you use to update user properties and capture events?
Android or iOS do you see this issue?
Thanks

@marandaneto marandaneto added question Further information is requested Product Analytics labels Nov 6, 2024
@choim4389
Copy link
Author

choim4389 commented Nov 7, 2024

@marandaneto

Posthog().identify(userId: 'test_id', properties: {'family_id': '2', 'test': 'test'});
Posthog().screen(screenName: screenName, properties: {'queryParameters': queryParameters});

It just set user property, and track screen.
Even if you change family_id, the initially set value does not change.
I have the same issue on both android and ios.

@marandaneto
Copy link
Member

marandaneto commented Nov 7, 2024

https://posthog.com/docs/libraries/flutter
See the Identifying users section, for user props, use the following props:

await Posthog().identify(
  userId: id, 
  userProperties: {"name": "Peter Griffin", "email": "[email protected]"},
  userPropertiesSetOnce: {"date_of_first_log_in": "2024-03-01"}
);

@marandaneto marandaneto closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2024
@choim4389
Copy link
Author

@marandaneto
userProperties was a typo during writing.
await Posthog().identify(userId: 'test_id', userProperties: {'family_id': '2', 'test': 'test'}); is not working.

@choim4389
Copy link
Author

It seems that the change will only be reflected if the app is reinstalled.

@marandaneto
Copy link
Member

marandaneto commented Nov 11, 2024

Please provide a MRE since everything works as expected when I test myself, it's likely something in your setup.
I will happily reopen the issue if there's a reproducible example.

@choim4389
Copy link
Author

It's so easy to reproduce.

Posthog().identify(userId: 'test_id', userProperties: {'family_id': '2'});
Posthog().screen(screenName: screenName, properties: {'queryParameters': queryParameters});

And then

Posthog().identify(userId: 'test_id', userProperties: {'family_id': '1'});
Posthog().screen(screenName: screenName, properties: {'queryParameters': queryParameters});

family_id not changed to '1'. screen and capture are both the same.

@choim4389
Copy link
Author

I looked into the identify function in the Android SDK, and it seems that once identify is performed, it does not work after that.
Is this how it works? Then I can't change properties until the user changes (since the distinctId has to change)?

if (previousDistinctId != distinctId && !isIdentified) {
            // this has to be set before capture since this flag will be read during the event
            // capture
            synchronized(identifiedLock) {
                isIdentified = true
            }

            capture(
                "\$identify",
                distinctId = distinctId,
                properties = props,
                userProperties = userProperties,
                userPropertiesSetOnce = userPropertiesSetOnce,
            )

            // We keep the AnonymousId to be used by decide calls and identify to link the previousId
            if (previousDistinctId.isNotBlank()) {
                this.anonymousId = previousDistinctId
            } else {
                config?.logger?.log("identify called with invalid former distinctId: $previousDistinctId.")
            }
            this.distinctId = distinctId

            // only because of testing in isolation, this flag is always enabled
            if (reloadFeatureFlags) {
                reloadFeatureFlags()
            }
        } else {
            config?.logger?.log("already identified with id: $distinctId.")
        }

https://github.com/PostHog/posthog-android/blob/bd1ec53504cd174cf335a34c9bef89ccbedb9099/posthog/src/main/java/com/posthog/PostHog.kt#L559-L588

@marandaneto marandaneto reopened this Nov 12, 2024
@marandaneto marandaneto removed the question Further information is requested label Nov 12, 2024
@marandaneto
Copy link
Member

You're right, it was unclear from your first messages that you're calling identify with the same distinct id multiple times.
I think we are missing this bits here: https://github.com/PostHog/posthog-js/blob/ba4f3bde44607f99a3ff63e7985d783b2a184ee8/src/posthog-core.ts#L1384-L1385

You can as a workaround do this for now.

await Posthog().identify(userId: 'test_id', userProperties: {'family_id': '1'});
await Posthog().capture(
  eventName: '$set', 
  properties: {'$set': {'family_id': '2'}} // or $set_once for userPropertiesSetOnce
);

@marandaneto
Copy link
Member

marandaneto commented Nov 12, 2024

Fixes are WIP

@marandaneto
Copy link
Member

@choim4389 if you upgrade your cocoapods, and generate a new build, this should be fixed.

@choim4389
Copy link
Author

choim4389 commented Nov 19, 2024

Thanks! I verified that it works. Isn't it being distributed as 4.6.1?

@marandaneto
Copy link
Member

Thanks! I verified that it works. Isn't it being distributed as 4.6.1?

The changes were on the Native SDKs (android and iOS), so the Flutter SDK picks up the latest compatible version.
We only bump the flutter SDK if there are breaking changes on the native SDKs or changes on the dart code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Product Analytics
Projects
None yet
Development

No branches or pull requests

2 participants