Skip to content

Commit

Permalink
feat: add support for global customContext option (#485)
Browse files Browse the repository at this point in the history
* chore: remove lingering reference to deleted RudderConfig file

* fix: logic to merge the externalId in identify call

* chore: refactor code

* feat: add global option support for customContext

* feat: when reset is called then clear the  globalOptions customContext field

* chore: create a mutable copy of customContexts while merging

* Revert "chore: refactor code"

This reverts commit 4773a05.

* Revert "fix: logic to merge the externalId in identify call"

This reverts commit 9e22dbb.

* Revert "chore: remove lingering reference to deleted RudderConfig file"

This reverts commit fd8bf6b.
  • Loading branch information
1abhishekpandey authored Mar 19, 2024
1 parent a824d4f commit 27f21b9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Sources/Classes/RSEventRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@ - (void)applyIntegrations:(RSMessage *)message withDefaultOption:(RSOption *)def
[mutableIntegrations setObject:@YES forKey:@"All"];
message.integrations = mutableIntegrations;
}

// Merge local customContext (message.customContexts) with global customContext (defaultOption.customContexts) giving preference to local one.
if (defaultOption) {
NSMutableDictionary<NSString*, NSDictionary<NSString*, id>*>* mergedCustomContextValues = [NSMutableDictionary dictionaryWithDictionary:[message.customContexts mutableCopy]];

for (NSString* key in defaultOption.customContexts) {
if (!mergedCustomContextValues[key]) {
mergedCustomContextValues[key] = [defaultOption.customContexts[key] mutableCopy];
}
}

message.customContexts = mergedCustomContextValues;
}
}

- (RSMessage *)applyConsents:(RSMessage *)message {
Expand All @@ -287,6 +300,11 @@ - (void)applySession:(RSMessage *)message withUserSession:(RSUserSession *)_user
}

-(void) reset {
if (self->defaultOptions != nil && self->defaultOptions.customContexts != nil) {
// Since the reset operation is intended to reset user-level fields, we clear the globalOptions->customContext field.
// The globalOptions->integrations field is a workspace-level setting and should not be cleared.
[self->defaultOptions.customContexts removeAllObjects];
}
if([self->userSession getSessionId] != nil) {
[RSLogger logDebug: @"EventRepository: reset: Refreshing the session as the reset is triggered"];
[self->userSession refreshSession];
Expand Down

0 comments on commit 27f21b9

Please sign in to comment.