segment-integrations / analytics-ios-integration-firebase

Segment's bundled integration for Firebase on iOS
MIT License
13 stars 92 forks source link

Coerce traits to String to fix issue #4 #9

Closed ladanazita closed 6 years ago

ladanazita commented 6 years ago

Can confirm a crash will occur when passing in a non NSString value, due to stringByReplacingOccurrencesOfString assuming that all user traits passed on identify will be an NSString.

For ex:

 [[SEGAnalytics sharedAnalytics] identify:@"432940" traits:@{
                                                                @"name":@"ladan",
                                                                @"gender":@"female",
                                                                @"age": @"28",
                                                                @"profession":@"software engineer",
                                                                @"favorite_food": @"hotdogs",
                                                                @"Height": @5,
                                                                @"favoriteFood": @"pizza"}];

Throws

Segment-Firebase_Example[2735:2136898] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0xb000000000000052'

In addition to this, Firebase does not allow non NSStrings passed in. When enabling Firebase logging, Firebase logs

Firebase_Example[12774] [Firebase/Analytics][I-ACS025003] User property must be NSString. Value: 45

Can confirm things populate as expected. After triggering the following identify:

    [[SEGAnalytics sharedAnalytics] identify:@"2993" traits:@{
                                                                @"name":@"Homer",
                                                                @"gender":@"male",
                                                                @"age": @45,
                                                                @"height": @6}];

I can see this populate in Firebase's Streamview:

Note that height is a custom trait which must be configured in Firebase's UI. name, gender, and age are reserved traits and do not need to be configured.

CC @tonyxiao for review JIRA

ladanazita commented 6 years ago

Tested e2e with call:

    [[SEGAnalytics sharedAnalytics] identify:@"43902351" traits:@{
                                                                  @"name":@"Chris Pratt",
                                                                  @"gender":@"male",
                                                                  @"age": @35,
                                                                  @"height": @6.1}];