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

Variant Return nil If user is nil when Flag has more than one variant #45

Open
areejSad opened this issue Feb 9, 2024 · 8 comments
Open

Comments

@areejSad
Copy link

areejSad commented Feb 9, 2024

I faced an issue, that the whole variant from experiment.variant(key.rawValue) return nil.
This happens when I don't want to give a User since it's optional.

Screenshot 2024-02-09 at 4 12 36 PM

This is the flag with multiple variants:
Screenshot 2024-02-09 at 4 14 44 PM

@bgiori
Copy link
Collaborator

bgiori commented Feb 13, 2024

Hi @areejSad Thanks for reporting this issue.

What version of the SDK are you using? And can you link the flag/experiment in amplitude?

Thanks!

@areejSad
Copy link
Author

the version '1.13.0', sorry what do you exactly need? if you mean the space it's a private account for company

@bgiori
Copy link
Collaborator

bgiori commented Feb 13, 2024

Is the deployment used to initialize the SDK added to the flag, and is the flag activated?

A link to the flag/experiment in Amplitude would be sufficient for me to check.

@areejSad
Copy link
Author

I can show you a photo, and yes it's added to the deployment environment, I also checked amplitudeExperimentAPIKey
amplitudeAnalyticsAPIKey
and it's the same added in the project.
This issue only happened if I have multiple variant, but If I just changed it to one variant it will work fine in the same code. So I'm confused why.

this is a photo to check the flag and it's active
Screenshot 2024-02-14 at 12 29 48 AM

@bgiori
Copy link
Collaborator

bgiori commented Feb 17, 2024

Thanks, and sorry for the delay.

This issue only happened if I have multiple variant, but If I just changed it to one variant it will work fine in the same code. So I'm confused why.

This most likely means that the user information (user_id and device_id) are not being sent in the fetch request.

Can you turn on the debug config option and look for the logs with [Experiment] in them? Specifically the on that has Fetch variants for user

Also, could you share how the Experiment SDK is initialized? Thanks!

@areejSad
Copy link
Author

yes exactly I'm intentionally making (user_id and device_id) as nil but it suppose to be ok right? because it's optional to have a user? and if there's no user it suppose to return a random variant right?

and this is how I initialize

Screenshot 2024-02-22 at 1 56 15 PM

===========

and this is how I fetch:

Screenshot 2024-02-22 at 1 58 00 PM

@areejSad
Copy link
Author

it says in the documentation:

Screenshot 2024-02-22 at 2 00 49 PM

@bgiori
Copy link
Collaborator

bgiori commented Mar 13, 2024

yes exactly I'm intentionally making (user_id and device_id) as nil but it suppose to be ok right? because it's optional to have a user? and if there's no user it suppose to return a random variant right?

Not quite. When there is some form of randomization (e.g. 3 variants evenly distributed) then we need some input value to get a consistent output. Without a user ID or device ID we dont have an input for the hash function used to determine which variant the user should be assigned, so the result is empty.

Passing a nil user is generally if you are using the initializeWithAmplitudeAnalytics initialization function or you have intialized the SDK with a custom UserProvider

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

No branches or pull requests

2 participants