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

fix: flutter web identify getAnonymousId error. #16

Merged

Conversation

keepwa1king
Copy link

@keepwa1king keepwa1king commented Jun 29, 2021

  1. I found that Posthog().identify not works in Flutter web. The reason is calling distinctId. So I changed distinctId to userId.
  2. I found that Posthog().getAnonymousId not works in Flutter web. It makes error like this.
Error: PlatformException(error, NoSuchMethodError: 'user'
method not found
Receiver: Instance of 'NativeJavaScriptObject'
Arguments: [], null, null)

In posthog-js, getting the anonymous Id is able to call the method "get_distinct_id". So, I changed the code to call method "get_distinct_id".

https://posthogusers.slack.com/archives/CT7HXDEG3/p1624946446377900

I sended at Slack about the error.

Copy link
Member

@fuziontech fuziontech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for the PR! Nice catch on the get_distinct_id call.

Can you try passing your userId as distinctId parameter in identify to see if that works?

@@ -20,7 +19,7 @@ class PosthogWeb {
switch (call.method) {
case 'identify':
analytics.callMethod('identify', [
call.arguments['distinctId'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think keeping it as distinctId keeps it aligned with our JS library
https://github.com/PostHog/posthog-js/blob/master/src/posthog-core.js#L810

Have you tried passing your userId as the distinctId parameter?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fuziontech
Thank you for giving me a feedback!
I changed distinctId to userId because of the default setting of Posthog().identify.
To use Posthog().identify, there is a required parameter "userId".
So I have to use like this.

Posthog().identify(userId: "Shinyoung Tyga Lee");

I think that using distinctId should make change about default setting of required parameter "userId" name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are totally right!

required userId,

Your changes look great and make this more consistent.

Comment on lines -45 to -46
final user = analytics.callMethod('user');
final anonymousId = user.callMethod('anonymousId');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Great catch here :)

Copy link
Member

@fuziontech fuziontech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good!

@fuziontech fuziontech merged commit 0933ac9 into PostHog:master Jun 29, 2021
@keepwa1king
Copy link
Author

Thank you!

@fuziontech
Copy link
Member

No prob! give 2.0.3 a try to make sure everything is working 👍

@PostHog PostHog locked and limited conversation to collaborators Jun 29, 2021
@PostHog PostHog unlocked this conversation Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants