amplitude / Amplitude-iOS

Native iOS/tvOS/macOS SDK
MIT License
305 stars 194 forks source link

UserID remained in the value nil #236

Open bently93 opened 4 years ago

bently93 commented 4 years ago

Hello! We had a issue with setting UserID in the iOS SDK. As UserID we use DeviceToken. For 90% of our users, UserID remained in the value "(none)", while for 10% it was successfully setted. On our test devices, UserID is also successfully setted. SDK amplitude/ 5.1.0

code example: Amplitude.instance(withName: "first").initializeApiKey(amplitudeApiKey, userId: UIDevice.current.identifierForVendor?.uuidString ?? "")

UIDevice.current.identifierForVendor?.uuidString always don't nil. It's checked through debugPrint.

haoliu-amp commented 4 years ago

Hey @bently93 ,

I saw you're using idfv as userId in your code. Problem is that identifierForVendor might return nil the fist time you call it. Please refer to https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor.

Screen Shot 2020-03-17 at 9 52 41 AM

That's also why we tried ourselves in our code while fetching idfv. https://github.com/amplitude/Amplitude-iOS/blob/master/Sources/Amplitude/AMPDeviceInfo.m#L222

bently93 commented 4 years ago

The idfv is always not nil value, I have checked in colsole. The trouble is, we passed correct idfv value to Amplitude Identify, but UserID is still empty in a user profile and his event stream. Note: after passing value, we also rechecked current UserID value in Amplitude instance, and we see what passed value = current UserID in instance.

haoliu-amp commented 4 years ago

@bently93 That's in your dev environment, right? On other users' devices, this might be nil. It's not guaranteed non-nil when fetching it for the 1st time.

My question is, while you're testing it on your dev environment, are you able to see userId, assuming idfv is not nil?

bently93 commented 4 years ago

yes, I see the correct UserID in console when idfv not nil

haoliu-amp commented 4 years ago

Yep, that's the problem. One the phones of some of your users, they could get idfv nil, which leads to this problem.

bently93 commented 4 years ago

i don't get nil but in website is empty

haoliu-amp commented 4 years ago

Could you share which company are you coming from? I might need look into your data.

bchiu146 commented 4 years ago

Hi @bently93 - to further assist you on your inquiry, please submit a ticket to our Support team at support.amplitude.com and link this Github issue to the form. If you could also provide your org ID when filling out the form, that would be helpful as well.

ceocraft commented 4 years ago

Could you share which company are you coming from? I might need look into your data. @haoliu-amp, I need your email for share the chart.

haoliu-amp commented 4 years ago

@ceocraft Could you create a ticket in our help center instead and share the information with our platform team? Thanks. @bchiu146 can help you out on this.

ceocraft commented 4 years ago

@ceocraft Could you create a ticket in our help center instead and share the information with our platform team? Thanks. @bchiu146 can help you out on this.

Ticket ID #39026

bently93 commented 4 years ago

We performed several tests and found out that if we set the deviceToken as the User ID and it matches the Device ID in Amplitude , the User ID in "User look-up" report becomes "(none)", but if we append the any character to the deviceToken, for example dataCacheRepo.deviceToken + "A", then UserID is successfully mounted.

haoliu-amp commented 4 years ago

@bently93 I see! Look like we have some logic in our backend system might lead this to be nil. We will discuss internally about what to do for this case.

vitogit commented 3 years ago

@haoliu-amp Any updates on this? I think I'm having the same issue, should I try the hacky way of adding an extra character? or is something solved now in newer versions?