Skip to content

Commit

Permalink
feat: added support for sending custom context from the flutter sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Desu Sai Venkat committed Aug 4, 2023
1 parent 2a661c0 commit 21f7238
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ public RudderOption getRudderOptionsObject(Map<String, Object> optionsMap) {
option.putIntegration(entry.getKey(), (boolean) entry.getValue());
}
}

if (optionsMap.containsKey("customContexts")) {
Map<String, Object> customContextsMap = (Map<String, Object>) optionsMap.get("customContexts");
for (Map.Entry<String, Object> customContext : customContextsMap.entrySet()) {
option.putCustomContext(customContext.getKey(), (Map<String, Object>) customContext.getValue());
}
}
return option;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import 'rudder_integration.dart';

// we left fetching the external ids from the scratch here
class RudderOption {
List<Map<String, dynamic>>? externalIds;
Map<String, Object>? integrations;
List<Map<String, String>>? externalIds;
Map<String, bool>? integrations;
Map<String, Map<String, Object>>? customContexts;

RudderOption putExternalId(String type, String id) {
externalIds ??= [];

Map<String, Object>? externalIdMap;
Map<String, String>? externalIdMap;
int mapIndex = -1;
for (int index = 0; index < externalIds!.length; index++) {
Map<String, Object> map =
externalIds!.elementAt(index) as Map<String, Object>;
Map<String, String> map = externalIds!.elementAt(index);
String mapType = map["type"].toString();
if (Utils.equalsIgnoreCase(mapType, type)) {
externalIdMap = map;
Expand Down Expand Up @@ -56,12 +56,17 @@ class RudderOption {
return this;
}

RudderOption putCustomContext(String key, Map<String, Object> value) {
customContexts ??= {};
customContexts?[key] = value;
return this;
}

Map<String, Object> toMap() {
Map<String, Object> optionsMap = {};
if (externalIds != null) {
optionsMap["externalIds"] = externalIds!;
}
optionsMap["externalIds"] = externalIds ?? [];
optionsMap["integrations"] = integrations ?? {};
optionsMap["customContexts"] = customContexts ?? {};
return optionsMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
selector:@selector(listenAppLaunchNotification:)
name:UIApplicationDidFinishLaunchingNotification
object:UIApplication.sharedApplication];
[RSLogger initiate:RSLogLevelWarning];
[RSLogger initiate:RSLogLevelWarning];
isRegistrarDetached = NO;
}

Expand Down Expand Up @@ -251,6 +251,12 @@ - (RSOption*)getRudderOptionsObject:(NSDictionary*)optionsDict {
isEnabled:[[integrationsDict objectForKey:key] isEqual:@1] ? YES : NO];
}
}
if ([optionsDict objectForKey:@"customContexts"]) {
NSDictionary* customContextsDict = [optionsDict objectForKey:@"customContexts"];
for (NSString* key in customContextsDict) {
[options putCustomContext:[customContextsDict objectForKey:key] withKey:key];
}
}
return options;
}

Expand Down

0 comments on commit 21f7238

Please sign in to comment.