Hello, Flowing source is snippet of GrowthBookSDK ...
# ask-questions
c
Hello, Flowing source is snippet of GrowthBookSDK in Android SDK (1.1.61)
Copy code
internal constructor(
    context: GBContext,
    refreshHandler: GBCacheRefreshHandler?,
    networkDispatcher: NetworkDispatcher,
    features: GBFeatures? = null,
    savedGroups: Map<String, Any>? = null
) : this() {
    gbContext = context
    this.refreshHandler = refreshHandler
    this.networkDispatcher = networkDispatcher

    /**
     * JAVA Consumers preset Features
     * SDK will not call API to fetch Features List
     */
    this.featuresViewModel =
        FeaturesViewModel(
            delegate = this,
            dataSource = FeaturesDataSource(dispatcher = networkDispatcher),
            encryptionKey = gbContext.encryptionKey,
        )
    if (features != null) {
        gbContext.features = features
    } else {
        refreshCache()
    }
    this.attributeOverrides = gbContext.attributes
    this.savedGroups = savedGroups
    refreshStickyBucketService()
}
what is purpose of the flowing code?
Copy code
this.attributeOverrides = gbContext.attributes
if calling growthBook.feature(key) then try evaluate variation of experiment by hashkey, but, evaluating a hash may depend on attributeOverrides values. in case, attributeOverrides has user_id, no matter how much i try changing user_id by setAttribute(), experiment variation is not changes.
a
Experiment variation is not changes but feature value is changing, right?
c
feature value is not changed, too
in iOS SDK, this code is not in the initializer func.
this.attributeOverrides = gbContext.attributes
following code works I expected,
Copy code
val growthBook = GBSDKBuilder().initialize()
growthBook.setAttributeOverrides(emptyMap())

// when attribute changed
growthBook.setAttribute()
a
Have you tried to pass other attributes map instead of using setAttribute()?
c
is there other way to set attributes, except GBSDKBuilder(attributes).initialized() or setAttributes(map)?
a
The documentation describes passing user attributes through constructor same as in Javascript SDK
c
for example with usecase, use experiment with featureFlag key (“featureKey”) at first, when starting the application, I called
Copy code
growthBook = GBSDKBuilder(
    apiKey = context.getString(R.string.key_growth_book),
    hostURL = "<https://cdn.growthbook.io/>",
    attributes = mapOf("userId", "lastLoginedUserId"),
).initialize()
attributes is set for last user, getFeature(featureKey) returns A then user logout, I need to change attributes. so I called
growthBook.setAttribute(mapOf("userId" to ""))
then call getFeature(featureKey) returns A again, expected value is B.
a
Have you exactly configured that if userId is empty than feature value should be B or you just point that feature value should be different?
The user id should be updated for sure but if no corresponding feature rule set, then after update the value can be the same
c
i will show my test code.
and logs
because, user_id = 0 is set in constructor and, evaluateFunc use attributeOverride values
a
I see. Maybe evaluateFeature() method don't work right but to make sure I will also need to know how feature rule configured (if configured)
c
Hi, @cuddly-zebra-96178. We will try to find solution for that issue and get back to you.
thankyou 1
c
feature rule is here
experiments rule is here
c
Hi, @cuddly-zebra-96178. We fixed that and add changes in pull request. I will write to you asap after we will merge it and release a new version.