Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: merging of externalId in identify event #478

Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
ED761A062727E28800B086F4 /* CustomFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = ED7619FC2727E28800B086F4 /* CustomFactory.m */; };
ED761A072727E28800B086F4 /* _AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = ED7619FD2727E28800B086F4 /* _AppDelegate.m */; };
ED8738CE2AB363A80076D24A /* EncryptedDatabaseProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = ED8738CC2AB363A80076D24A /* EncryptedDatabaseProvider.m */; };
F6149CC52B32FBC2006995B7 /* RudderConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = F6149CC42B32FBC2006995B7 /* RudderConfig.plist */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -57,7 +56,6 @@
ED7619FD2727E28800B086F4 /* _AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _AppDelegate.m; sourceTree = "<group>"; };
ED8738CA2AB363A80076D24A /* EncryptedDatabaseProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EncryptedDatabaseProvider.h; sourceTree = "<group>"; };
ED8738CC2AB363A80076D24A /* EncryptedDatabaseProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EncryptedDatabaseProvider.m; sourceTree = "<group>"; };
F6149CC42B32FBC2006995B7 /* RudderConfig.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = RudderConfig.plist; sourceTree = "<group>"; };
F928F8A942558010CC7088BF /* Pods-RudderSampleAppObjC.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RudderSampleAppObjC.debug.xcconfig"; path = "Target Support Files/Pods-RudderSampleAppObjC/Pods-RudderSampleAppObjC.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -137,7 +135,6 @@
ED7619FD2727E28800B086F4 /* _AppDelegate.m */,
ED7619F02727E28700B086F4 /* _ViewController.h */,
ED7619F92727E28800B086F4 /* _ViewController.m */,
F6149CC42B32FBC2006995B7 /* RudderConfig.plist */,
ED7619F22727E28700B086F4 /* CustomFactory.h */,
ED7619FC2727E28800B086F4 /* CustomFactory.m */,
ED7619FB2727E28800B086F4 /* CustomIntegration.h */,
Expand Down Expand Up @@ -219,7 +216,6 @@
files = (
ED761A012727E28800B086F4 /* LaunchScreen.storyboard in Resources */,
ED0CA6DE2A7D049E00899C1C /* SampleRudderConfig.plist in Resources */,
F6149CC52B32FBC2006995B7 /* RudderConfig.plist in Resources */,
ED761A052727E28800B086F4 /* Images.xcassets in Resources */,
ED7619FF2727E28800B086F4 /* InfoPlist.strings in Resources */,
ED761A022727E28800B086F4 /* Main.storyboard in Resources */,
Expand Down
39 changes: 21 additions & 18 deletions Sources/Classes/RSContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -184,31 +184,34 @@ - (void)putAdvertisementId:(NSString *_Nonnull)idfa {
});
}

- (void)updateExternalIds:(NSMutableArray *)externalIds {
- (void)updateExternalIds:(NSMutableArray *)newExternalIds {
dispatch_sync(queue, ^{
if(self->_externalIds == nil)
{
if(self->_externalIds == nil){
self->_externalIds = [[NSMutableArray alloc] init];
}

NSMutableArray *newExternalIds = [externalIds mutableCopy];
if (self->_externalIds.count > 0) {
NSMutableArray *repeatingExternalIds = [[NSMutableArray alloc] init];
for (NSMutableDictionary *newExternalId in newExternalIds) {
for (NSMutableDictionary *externalId in self->_externalIds) {
if ([externalId[@"type"] isEqualToString:newExternalId[@"type"]]){
externalId[@"id"] = newExternalId[@"id"];
[repeatingExternalIds addObject:newExternalId];
break;
}
}
}
[newExternalIds removeObjectsInArray:repeatingExternalIds];
NSMutableDictionary<NSString *, NSMutableDictionary<NSString *, NSObject *> *> *mergedValues = [NSMutableDictionary dictionary];

for (NSMutableDictionary<NSString *, NSObject *> *externalId in self->_externalIds) {
NSString *type = [NSString stringWithFormat:@"%@", externalId[@"type"]];
mergedValues[type] = [externalId mutableCopy];
}

if ([newExternalIds count]) {
[self->_externalIds addObjectsFromArray: newExternalIds];
// Merge new externalIds into the existing merged values
for (NSMutableDictionary<NSString *, NSObject *> *newExternalId in newExternalIds) {
NSString *type = [NSString stringWithFormat:@"%@", newExternalId[@"type"]];
NSMutableDictionary<NSString *, NSObject *> *existingMergedValue = mergedValues[type];

if (existingMergedValue) {
// Merge values for the same "type"
[existingMergedValue addEntriesFromDictionary:newExternalId];
} else {
// No existing merged value for this "type," add a copy of the newExternalId
mergedValues[type] = [newExternalId mutableCopy];
}
}

self->_externalIds = [[mergedValues allValues] mutableCopy];
});
}

Expand Down
Loading