Amplitude-iOS icon indicating copy to clipboard operation
Amplitude-iOS copied to clipboard

UserID remained in the value nil

Open bently93 opened this issue 4 years ago • 14 comments

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.

bently93 avatar Mar 17 '20 08:03 bently93

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

haoliu-amp avatar Mar 17 '20 16:03 haoliu-amp

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.

bently93 avatar Mar 20 '20 09:03 bently93

@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?

haoliu-amp avatar Mar 23 '20 05:03 haoliu-amp

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

bently93 avatar Mar 23 '20 07:03 bently93

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

haoliu-amp avatar Mar 23 '20 17:03 haoliu-amp

i don't get nil but in website is empty

bently93 avatar Mar 23 '20 18:03 bently93

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

haoliu-amp avatar Mar 23 '20 18:03 haoliu-amp

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.

bchiu146 avatar Mar 23 '20 19:03 bchiu146

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.

ceocraft avatar Mar 24 '20 08:03 ceocraft

@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.

haoliu-amp avatar Mar 24 '20 17:03 haoliu-amp

@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

ceocraft avatar Mar 25 '20 07:03 ceocraft

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.

bently93 avatar Apr 10 '20 06:04 bently93

@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.

haoliu-amp avatar Apr 10 '20 17:04 haoliu-amp

@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?

vitogit avatar Mar 18 '21 14:03 vitogit