Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions Segment-Firebase/Classes/SEGFirebaseIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@

@implementation SEGFirebaseIntegration

#pragma mark - Helper Functions
+ (NSDictionary *)mapToStrings:(NSDictionary *)dictionary
{
NSMutableDictionary *output = [NSMutableDictionary dictionaryWithCapacity:dictionary.count];

[dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id data, BOOL *stop) {
if ([data isKindOfClass:[NSString class]]) {
[output setObject:data forKey:key];
} else {
[output setObject:[NSString stringWithFormat:@"%@", data] forKey:key];
}
}];

return [output copy];
}


#pragma mark - Initialization

- (id)initWithSettings:(NSDictionary *)settings
Expand All @@ -29,8 +46,9 @@ - (void)identify:(SEGIdentifyPayload *)payload
[FIRAnalytics setUserID:payload.userId];
SEGLog(@"[FIRAnalytics setUserId:%@]", payload.userId);
}

[payload.traits enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop){
// Firebase requires user properties to be a NSString
NSDictionary *mappedTraits = [SEGFirebaseIntegration mapToStrings:payload.traits];
[mappedTraits enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@ladanazita ladanazita Sep 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mappedTraits has run through mapToStrings, which returns a NSDictionary of key value pairs of type NSString. Also broken link?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. So using it as a NSString should be fine here then.

NSString *trait = [key stringByReplacingOccurrencesOfString:@" " withString:@"_"];
NSString *value = [obj stringByReplacingOccurrencesOfString:@" " withString:@"_"];
[FIRAnalytics setUserPropertyString:value forName:trait];
Expand Down