Skip to content

Commit

Permalink
LIBMOBILE-109: Updated an issue with new traits not overriding old tr…
Browse files Browse the repository at this point in the history
…aits (#917)
  • Loading branch information
migs647 authored Jul 6, 2020
1 parent 5158e55 commit b82f0ed
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Analytics/Classes/SEGAnalytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,25 +223,28 @@ - (void)identify:(NSString *)userId traits:(NSDictionary *)traits options:(NSDic
anonId = [self getAnonymousId];
}
// configure traits to match what is seen on android.
NSMutableDictionary *newTraits = [traits mutableCopy];
NSMutableDictionary *existingTraitsCopy = [[SEGState sharedInstance].userInfo.traits mutableCopy];
NSMutableDictionary *traitsCopy = [traits mutableCopy];
// if no traits were passed in, need to create.
if (newTraits == nil) {
newTraits = [[NSMutableDictionary alloc] init];
if (existingTraitsCopy == nil) {
existingTraitsCopy = [[NSMutableDictionary alloc] init];
}
newTraits[@"anonymousId"] = anonId;
if (traitsCopy == nil) {
traitsCopy = [[NSMutableDictionary alloc] init];
}
traitsCopy[@"anonymousId"] = anonId;
if (userId != nil) {
newTraits[@"userId"] = userId;
traitsCopy[@"userId"] = userId;
[SEGState sharedInstance].userInfo.userId = userId;
}
// merge w/ existing traits and set them.
NSDictionary *existingTraits = [SEGState sharedInstance].userInfo.traits;
[newTraits addEntriesFromDictionary:existingTraits];
[SEGState sharedInstance].userInfo.traits = newTraits;
[existingTraitsCopy addEntriesFromDictionary:traits];
[SEGState sharedInstance].userInfo.traits = existingTraitsCopy;

[self run:SEGEventTypeIdentify payload:
[[SEGIdentifyPayload alloc] initWithUserId:userId
anonymousId:anonId
traits:SEGCoerceDictionary(newTraits)
traits:SEGCoerceDictionary(existingTraitsCopy)
context:SEGCoerceDictionary([options objectForKey:@"context"])
integrations:[options objectForKey:@"integrations"]]];
}
Expand Down

0 comments on commit b82f0ed

Please sign in to comment.