amplitude / experiment-ios-client

MIT License
2 stars 9 forks source link

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

Open areejSad opened 7 months ago

areejSad commented 7 months ago

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 commented 6 months ago

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 commented 6 months ago

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

bgiori commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

it says in the documentation:

Screenshot 2024-02-22 at 2 00 49 PM
bgiori commented 5 months ago

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