Skip to content

Commit

Permalink
server side sdk configuration (#357)
Browse files Browse the repository at this point in the history
* add server side logging options

* add server side start tracking on initialize

* add server size track once on app open

* updates sdk config when Radar is initialized

---------

Co-authored-by: Liam Meier <[email protected]>
Co-authored-by: KennyHuRadar <[email protected]>
  • Loading branch information
3 people authored Jul 19, 2024
1 parent a1bd2af commit 90e2654
Show file tree
Hide file tree
Showing 23 changed files with 357 additions and 189 deletions.
2 changes: 2 additions & 0 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIWindowSceneDelegate, UN

// Replace with a valid test publishable key
Radar.initialize(publishableKey: "prj_test_pk_0000000000000000000000000000000000000000")
Radar.setUserId("testUserId")
Radar.setMetadata([ "foo": "bar" ])
Radar.setDelegate(self)
Radar.setVerifiedDelegate(self)

Expand Down
2 changes: 1 addition & 1 deletion RadarSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'RadarSDK'
s.version = '3.15.0'
s.version = '3.16.0'
s.summary = 'iOS SDK for Radar, the leading geofencing and location tracking platform'
s.homepage = 'https://radar.com'
s.author = { 'Radar Labs, Inc.' => '[email protected]' }
Expand Down
25 changes: 15 additions & 10 deletions RadarSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@
82D04ABC29722ED20036619F /* RadarReplayBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 82D04AB929722ED20036619F /* RadarReplayBuffer.m */; };
82D04ABD29722ED20036619F /* RadarReplayBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 82D04ABA29722ED20036619F /* RadarReplayBuffer.h */; };
82D04AC729771BF10036619F /* RadarReplay.m in Sources */ = {isa = PBXBuildFile; fileRef = 82D04AC629771BF10036619F /* RadarReplay.m */; };
82EEA92A2A9E684C0048DCEC /* RadarFeatureSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = 82EEA9292A9E684C0048DCEC /* RadarFeatureSettings.h */; };
82EEA92C2A9E685B0048DCEC /* RadarFeatureSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = 82EEA92B2A9E685B0048DCEC /* RadarFeatureSettings.m */; };
82F7FAEB2A65FDD50055AA4B /* RadarNotificationHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 01DDC7C529FC387400C0D039 /* RadarNotificationHelper.m */; };
82F7FAEE2A65FE030055AA4B /* RadarVerificationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 82F7FAEC2A65FE030055AA4B /* RadarVerificationManager.h */; };
82F7FAEF2A65FE030055AA4B /* RadarVerificationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 82F7FAED2A65FE030055AA4B /* RadarVerificationManager.m */; };
Expand Down Expand Up @@ -167,6 +165,9 @@
DE1E7644239724FD006F34A1 /* search_geofences.json in Resources */ = {isa = PBXBuildFile; fileRef = DE1E7643239724FD006F34A1 /* search_geofences.json */; };
E6EEC56E2B20F41A00DD096B /* RadarFileStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = E6EEC56D2B20F41A00DD096B /* RadarFileStorage.h */; };
E6EEC5702B20F45D00DD096B /* RadarFileStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = E6EEC56F2B20F45D00DD096B /* RadarFileStorage.m */; };
F65AF72C2C10B242002BA009 /* get_config_response.json in Resources */ = {isa = PBXBuildFile; fileRef = F65AF72B2C10B242002BA009 /* get_config_response.json */; };
F667F8272BFBF3C8001F2F67 /* RadarSdkConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = F667F8262BFBF3C8001F2F67 /* RadarSdkConfiguration.m */; };
F667F8292BFBF3D1001F2F67 /* RadarSdkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = F667F8282BFBF3D1001F2F67 /* RadarSdkConfiguration.h */; };
F6F959802C3D7D9900BC30FE /* RadarTimeZone.h in Headers */ = {isa = PBXBuildFile; fileRef = F6F9597F2C3D7D9900BC30FE /* RadarTimeZone.h */; settings = {ATTRIBUTES = (Public, ); }; };
F6F959822C3D7EA200BC30FE /* RadarTimeZone+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = F6F959812C3D7EA200BC30FE /* RadarTimeZone+Internal.h */; };
F6F959842C3D7EDE00BC30FE /* RadarTimeZone.m in Sources */ = {isa = PBXBuildFile; fileRef = F6F959832C3D7EDE00BC30FE /* RadarTimeZone.m */; };
Expand Down Expand Up @@ -198,8 +199,6 @@
82D04AB929722ED20036619F /* RadarReplayBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarReplayBuffer.m; sourceTree = "<group>"; };
82D04ABA29722ED20036619F /* RadarReplayBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RadarReplayBuffer.h; sourceTree = "<group>"; };
82D04AC629771BF10036619F /* RadarReplay.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarReplay.m; sourceTree = "<group>"; };
82EEA9292A9E684C0048DCEC /* RadarFeatureSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RadarFeatureSettings.h; sourceTree = "<group>"; };
82EEA92B2A9E685B0048DCEC /* RadarFeatureSettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarFeatureSettings.m; sourceTree = "<group>"; };
82F7FAEC2A65FE030055AA4B /* RadarVerificationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RadarVerificationManager.h; sourceTree = "<group>"; };
82F7FAED2A65FE030055AA4B /* RadarVerificationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarVerificationManager.m; sourceTree = "<group>"; };
966D885F288F7404008C0D00 /* conversion_event.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = conversion_event.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -334,6 +333,9 @@
DE1E7643239724FD006F34A1 /* search_geofences.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = search_geofences.json; sourceTree = "<group>"; };
E6EEC56D2B20F41A00DD096B /* RadarFileStorage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarFileStorage.h; sourceTree = "<group>"; };
E6EEC56F2B20F45D00DD096B /* RadarFileStorage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RadarFileStorage.m; sourceTree = "<group>"; };
F65AF72B2C10B242002BA009 /* get_config_response.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = get_config_response.json; sourceTree = "<group>"; };
F667F8262BFBF3C8001F2F67 /* RadarSdkConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarSdkConfiguration.m; sourceTree = "<group>"; };
F667F8282BFBF3D1001F2F67 /* RadarSdkConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RadarSdkConfiguration.h; sourceTree = "<group>"; };
F6F9597F2C3D7D9900BC30FE /* RadarTimeZone.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarTimeZone.h; sourceTree = "<group>"; };
F6F959812C3D7EA200BC30FE /* RadarTimeZone+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RadarTimeZone+Internal.h"; sourceTree = "<group>"; };
F6F959832C3D7EDE00BC30FE /* RadarTimeZone.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RadarTimeZone.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -409,6 +411,7 @@
isa = PBXGroup;
children = (
53B3B26A23EE41B400080818 /* context.json */,
F65AF72B2C10B242002BA009 /* get_config_response.json */,
966D885F288F7404008C0D00 /* conversion_event.json */,
968C839828A6D8350030103E /* conversion_event_nil_event.json */,
DD5E35E0238205FF002D93FF /* events_verification.json */,
Expand Down Expand Up @@ -459,6 +462,7 @@
DD236C792308797B00EB88F9 /* Info.plist */,
532FC303277A783900989279 /* Radar+Internal.h */,
DD236C9023087A3500EB88F9 /* Radar.m */,
F667F8282BFBF3D1001F2F67 /* RadarSdkConfiguration.h */,
DD236C9823087F9200EB88F9 /* RadarAPIClient.h */,
DD236C9923087F9200EB88F9 /* RadarAPIClient.m */,
DD633EC1237C5B800026C91A /* RadarAPIHelper.h */,
Expand All @@ -473,8 +477,6 @@
E6EEC56F2B20F45D00DD096B /* RadarFileStorage.m */,
96A5A11727ADA02E007B960B /* RadarDelegateHolder.h */,
DD4C104925D87E3E009C2E36 /* RadarDelegateHolder.m */,
82EEA9292A9E684C0048DCEC /* RadarFeatureSettings.h */,
82EEA92B2A9E685B0048DCEC /* RadarFeatureSettings.m */,
DD236CF723088F8400EB88F9 /* RadarLocationManager.h */,
DD236CF823088F8400EB88F9 /* RadarLocationManager.m */,
96A5A11527ADA02E007B960B /* RadarLog.h */,
Expand All @@ -493,6 +495,7 @@
82D04ABA29722ED20036619F /* RadarReplayBuffer.h */,
82D04AB929722ED20036619F /* RadarReplayBuffer.m */,
DD236C782308797B00EB88F9 /* RadarSDK.h */,
F667F8262BFBF3C8001F2F67 /* RadarSdkConfiguration.m */,
DD236CFB230895D400EB88F9 /* RadarSettings.h */,
DD236CFC230895D400EB88F9 /* RadarSettings.m */,
DD236D0E2309B3FE00EB88F9 /* RadarState.h */,
Expand Down Expand Up @@ -619,7 +622,6 @@
96A5A0C127AD9F41007B960B /* RadarRoutes+Internal.h in Headers */,
96A5A10C27AD9F7F007B960B /* RadarRoutes.h in Headers */,
82D04ABD29722ED20036619F /* RadarReplayBuffer.h in Headers */,
82EEA92A2A9E684C0048DCEC /* RadarFeatureSettings.h in Headers */,
96A5A11B27ADA02F007B960B /* RadarDelegateHolder.h in Headers */,
96A5A10F27AD9F7F007B960B /* RadarRouteDuration.h in Headers */,
96A5A10627AD9F7F007B960B /* RadarFraud.h in Headers */,
Expand Down Expand Up @@ -653,6 +655,7 @@
96A5A0C027AD9F41007B960B /* RadarRouteDistance+Internal.h in Headers */,
96A5A0D227AD9F41007B960B /* RadarContext+Internal.h in Headers */,
96A5A10E27AD9F7F007B960B /* RadarRouteDistance.h in Headers */,
F667F8292BFBF3D1001F2F67 /* RadarSdkConfiguration.h in Headers */,
82D04ABB29722ED20036619F /* RadarReplay.h in Headers */,
96A5A10727AD9F7F007B960B /* RadarCircleGeometry.h in Headers */,
96A5A0F827AD9F7F007B960B /* RadarRegion.h in Headers */,
Expand Down Expand Up @@ -773,6 +776,7 @@
buildActionMask = 2147483647;
files = (
966D8860288F7404008C0D00 /* conversion_event.json in Resources */,
F65AF72C2C10B242002BA009 /* get_config_response.json in Resources */,
DD4D4D2523E648D000D36C1D /* search_autocomplete.json in Resources */,
DD5E35E1238205FF002D93FF /* events_verification.json in Resources */,
825732512B72BE1900DF8B88 /* PrivacyInfo.xcprivacy in Resources */,
Expand Down Expand Up @@ -835,6 +839,8 @@
0107AB29262201F4008AB52F /* RadarTrackingOptions.m in Sources */,
0107AB2F262201FB008AB52F /* RadarUtils.m in Sources */,
0107AA8926220140008AB52F /* RadarChain.m in Sources */,
F667F8272BFBF3C8001F2F67 /* RadarSdkConfiguration.m in Sources */,
F667F8272BFBF3C8001F2F67 /* RadarSdkConfiguration.m in Sources */,
0107AB11262201D9008AB52F /* RadarCollectionAdditions.m in Sources */,
96FC90F7277379C1000757DF /* RadarFraud.m in Sources */,
F6F959842C3D7EDE00BC30FE /* RadarTimeZone.m in Sources */,
Expand All @@ -847,7 +853,6 @@
53CCD783275E579800F79CC8 /* RadarLogBuffer.m in Sources */,
82D04ABC29722ED20036619F /* RadarReplayBuffer.m in Sources */,
82F7FAEF2A65FE030055AA4B /* RadarVerificationManager.m in Sources */,
82EEA92C2A9E685B0048DCEC /* RadarFeatureSettings.m in Sources */,
0107AA832622013A008AB52F /* RadarBeacon.m in Sources */,
82F7FAEB2A65FDD50055AA4B /* RadarNotificationHelper.m in Sources */,
0107AAB626220172008AB52F /* RadarPolygonGeometry.m in Sources */,
Expand Down Expand Up @@ -1017,7 +1022,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.15.0;
MARKETING_VERSION = 3.16.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1075,7 +1080,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.15.0;
MARKETING_VERSION = 3.16.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
OTHER_CFLAGS = "-fembed-bitcode";
Expand Down
2 changes: 1 addition & 1 deletion RadarSDK/Include/Radar.h
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ logConversionWithNotification
#pragma mark - Logging

/**
Sets the log level for debug logs.
Sets the preferred log level for debug logs. This can be overridden by the remote SDK configuration set in the dashboard.
@param level The log level.
*/
Expand Down
47 changes: 37 additions & 10 deletions RadarSDK/Radar.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

#import "Radar.h"
#include "RadarSdkConfiguration.h"

#import "RadarAPIClient.h"
#import "RadarBeaconManager.h"
Expand All @@ -20,7 +21,6 @@
#import "RadarUtils.h"
#import "RadarVerificationManager.h"
#import "RadarReplayBuffer.h"
#import "RadarFeatureSettings.h"

@interface Radar ()

Expand Down Expand Up @@ -51,8 +51,8 @@ + (void)initializeWithPublishableKey:(NSString *)publishableKey {

[RadarSettings setPublishableKey:publishableKey];

RadarFeatureSettings *featureSettings = [RadarSettings featureSettings];
if (featureSettings.usePersistence) {
RadarSdkConfiguration *sdkConfiguration = [RadarSettings sdkConfiguration];
if (sdkConfiguration.usePersistence) {
[[RadarReplayBuffer sharedInstance] loadReplaysFromPersistentStore];
}

Expand All @@ -62,19 +62,29 @@ + (void)initializeWithPublishableKey:(NSString *)publishableKey {


[[RadarLocationManager sharedInstance] updateTrackingFromInitialize];

[[RadarAPIClient sharedInstance] getConfigForUsage:@"initialize"
verified:NO
completionHandler:^(RadarStatus status, RadarConfig *config) {
if (status != RadarStatusSuccess || !config) {
return;
if (status == RadarStatusSuccess && config) {
[[RadarLocationManager sharedInstance] updateTrackingFromMeta:config.meta];
[RadarSettings setSdkConfiguration:config.meta.sdkConfiguration];
}

RadarSdkConfiguration *sdkConfiguration = [RadarSettings sdkConfiguration];
if (sdkConfiguration.startTrackingOnInitialize && ![RadarSettings tracking]) {
[Radar startTrackingWithOptions:[RadarSettings trackingOptions]];
}
if (sdkConfiguration.trackOnceOnAppOpen) {
[Radar trackOnceWithCompletionHandler:nil];
}
[[RadarLocationManager sharedInstance] updateTrackingFromMeta:config.meta];
[RadarSettings setFeatureSettings:config.meta.featureSettings];

[self flushLogs];
}];

}



#pragma mark - Properties

+ (NSString *)sdkVersion {
Expand Down Expand Up @@ -1008,7 +1018,18 @@ + (void)getMatrixFromOrigins:(NSArray<CLLocation *> *_Nonnull)origins
#pragma mark - Logging

+ (void)setLogLevel:(RadarLogLevel)level {
[RadarSettings setLogLevel:level];
NSMutableDictionary *sdkConfiguration = [[RadarSettings clientSdkConfiguration] mutableCopy];
NSObject *logLevelObj = sdkConfiguration[@"logLevel"];
if ([logLevelObj isKindOfClass:[NSString class]] && [[RadarLog stringForLogLevel:level] isEqualToString:(NSString *)logLevelObj]) {
return;
}
[sdkConfiguration setValue:[RadarLog stringForLogLevel:level] forKey:@"logLevel"];
[RadarSettings setClientSdkConfiguration:sdkConfiguration];

if ([RadarSettings logLevel] == level) {
return;
}
[RadarSdkConfiguration updateSdkConfigurationFromServer];
}

+ (void)logTermination {
Expand Down Expand Up @@ -1220,11 +1241,17 @@ - (void)applicationWillEnterForeground {
return;
}
[[RadarLocationManager sharedInstance] updateTrackingFromMeta:config.meta];
[RadarSettings setFeatureSettings:config.meta.featureSettings];
[RadarSettings setSdkConfiguration:config.meta.sdkConfiguration];
}];
}


[Radar logOpenedAppConversion];

RadarSdkConfiguration *sdkConfiguration = [RadarSettings sdkConfiguration];
if (sdkConfiguration.trackOnceOnAppOpen) {
[Radar trackOnceWithCompletionHandler:nil];
}
}

- (void)dealloc {
Expand Down
3 changes: 2 additions & 1 deletion RadarSDK/RadarAPIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#import "RadarReplayBuffer.h"
#import "RadarRouteMatrix+Internal.h"
#import "RadarRoutes+Internal.h"
#import "RadarSdkConfiguration.h"
#import "RadarSettings.h"
#import "RadarState.h"
#import "RadarTrip+Internal.h"
Expand Down Expand Up @@ -101,6 +102,7 @@ - (void)getConfigForUsage:(NSString *_Nullable)usage verified:(BOOL)verified com
[queryString appendFormat:@"&usage=%@", usage];
}
[queryString appendFormat:@"&verified=%@", verified ? @"true" : @"false"];
[queryString appendFormat:@"&clientSdkConfiguration=%@", [RadarUtils dictionaryToJson:[RadarSettings clientSdkConfiguration]]];

NSString *host = verified ? [RadarSettings verifiedHost] : [RadarSettings host];
NSString *url = [NSString stringWithFormat:@"%@/v1/config?%@", host, queryString];
Expand Down Expand Up @@ -128,7 +130,6 @@ - (void)getConfigForUsage:(NSString *_Nullable)usage verified:(BOOL)verified com
}];
}


- (void)flushReplays:(NSArray<NSDictionary *> *_Nonnull)replays
completionHandler:(RadarFlushReplaysAPICompletionHandler _Nonnull)completionHandler {
NSString *publishableKey = [RadarSettings publishableKey];
Expand Down
51 changes: 0 additions & 51 deletions RadarSDK/RadarFeatureSettings.h

This file was deleted.

Loading

0 comments on commit 90e2654

Please sign in to comment.