Skip to content

ExperimentUserBuilder doesn't seem to parse user properties correctly #75

@glenngijsberts

Description

@glenngijsberts

When fetching the feature flags/experiments in our Swift app we use the ExperimentUserBuilder function from the SDK to build up the experiment user, passing user properties like so:

func createUserContext(_ userInfo: AnalyticsUserProfile) async -> ExperimentUser? {

  ...
  
  return ExperimentUserBuilder()
      .userId(userInfo?.id)
      .deviceId(analytics.anonymousId)
      .userProperties([
          "userId": userInfo?.id as Any,
          "isEmployee": userInfo?.isEmployee ?? false,
          "platform": deviceContext.os,
          "mobileAppOsVersion": deviceContext.osVersion,
          "mobileAppVersion": deviceContext.appVersion,
          "mobileAppBuildNumber": deviceContext.buildNumber,
          "countryCode": Locale.current.language.languageCode?.identifier as Any,
      ])
      .build()

...

and then pass this experiment user to the SDK to start Amplitude like so:

    public func start(_ user: AnalyticsUserProfile?) async throws {
        let experimentUser = await createUserContext(user)

        try await withCheckedThrowingContinuation { continuation in
            amplitude.start(experimentUser) { error in
                continuation.resume(with: .init {
                    if let error { throw error }
                })
            }
        }
    }

Pretty straight forward I would say so far, but I was running into issues where my feature flags didn't work based on for example the isEmployee property, which is a simple true/false value.

Looking into what I pass, and then looking into the ExperimentUser I get I found some issues with the userProperties on this user and the ones that are probably used to determine which flags are enabled?

For example, values that I pass from the analytics user:

...
    - isNewProfile : false
    - isEmployee : true
    ▿ city : Optional<String>
      - some : ""
    ▿ countryCode : Optional<String>
      - some : "NL"
    ▿ isPhoneVerified : Optional<Bool>
      - some : true
...

Values I get from the experiment user' user properties:

([String : String]?) 7 key/value pairs {
  [0] = (key = "countryCode", value = <uninitialized>)
  [1] = (key = "isEmployee", value = <uninitialized>)
  [2] = (key = "mobileAppVersion", value = unable to read data)
  [3] = (key = "mobileAppBuildNumber", value = <uninitialized>)
  [4] = (key = "mobileAppOsVersion", value = Swift.String @ 0x00006000435a6850)
  [5] = (key = "platform", value = <uninitialized>)
  [6] = (key = "userId", value = <uninitialized>)
}

This doesn't seems correct to me. FWIW, it does work when I use local evaluation for my feature flags, but that doesn't seem right to me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions