From 97af01301800db3adaa859849d5a51544094eea1 Mon Sep 17 00:00:00 2001 From: sanyamjain65 Date: Wed, 22 Dec 2021 15:40:27 +0530 Subject: [PATCH] feat(sdk): support for configuring and using VWO chinese cdn --- Demo/Podfile.lock | 12 ++++++------ Demo/VWO Demo/VWOManager.swift | 1 + VWO.podspec | 2 +- VWO/VWOConfig.h | 5 +++++ VWO/VWOConfig.m | 1 + VWO/VWOController.h | 2 +- VWO/VWOController.m | 2 +- VWO/VWOURL.h | 2 +- VWO/VWOURL.m | 26 ++++++++++++++++---------- 9 files changed, 33 insertions(+), 20 deletions(-) diff --git a/Demo/Podfile.lock b/Demo/Podfile.lock index e1c0b86d..38ee6210 100644 --- a/Demo/Podfile.lock +++ b/Demo/Podfile.lock @@ -4,9 +4,9 @@ PODS: - Socket.IO-Client-Swift (13.4.0): - Starscream (~> 3.0.2) - Starscream (3.0.6) - - VWO (2.7.0): - - VWO/All (= 2.7.0) - - VWO/All (2.7.0): + - VWO (2.7.1): + - VWO/All (= 2.7.1) + - VWO/All (2.7.1): - Socket.IO-Client-Swift (~> 13.1) DEPENDENCIES: @@ -30,8 +30,8 @@ SPEC CHECKSUMS: SCLAlertView: 6a77bb2edfc65e04dbe57725546cb4107a506b85 Socket.IO-Client-Swift: 2b2720f14c92ff1237ced09bc2f2da2022624fee Starscream: ef3ece99d765eeccb67de105bfa143f929026cf5 - VWO: f86cb4e2df45c2c04188800ebcede0da0ae10e4c + VWO: f7cfcc0df231c378eed8d8088d30babf456ccc9c -PODFILE CHECKSUM: d09e5733ca3cd69659f82c8ebab0ed0ff0b9e3a7 +PODFILE CHECKSUM: 2b2638e9e63d49ba40c6ab42dfe34e64a8745537 -COCOAPODS: 1.10.1 +COCOAPODS: 1.10.2 diff --git a/Demo/VWO Demo/VWOManager.swift b/Demo/VWO Demo/VWOManager.swift index 01583bdd..928fb3f0 100644 --- a/Demo/VWO Demo/VWOManager.swift +++ b/Demo/VWO Demo/VWOManager.swift @@ -23,6 +23,7 @@ class VWOManager { let config = VWOConfig() // config.setCustomDimension(customDimensionKey: "userId", customDimensionValue: "userName") config.userID = "userId" + config.isChinaCDN = false VWO.launch(apiKey: apiKey, config: config, completion: { DispatchQueue.main.async { // VWO.pushCustomDimension(customDimensionKey: "userId", customDimensionValue: "userName") diff --git a/VWO.podspec b/VWO.podspec index d0a1fc31..34d9e2b0 100644 --- a/VWO.podspec +++ b/VWO.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "VWO" - s.version = "2.7.1" + s.version = "2.8.0" s.summary = "VWO SDK for A/B Testing iOS apps." s.description = "VWO iOS SDK enables you to A/B test mobile apps." s.documentation_url = "http://developers.vwo.com/reference#ios-sdk-reference" diff --git a/VWO/VWOConfig.h b/VWO/VWOConfig.h index c304fce1..e2f04c16 100644 --- a/VWO/VWOConfig.h +++ b/VWO/VWOConfig.h @@ -15,6 +15,11 @@ */ @property BOOL optOut; +/** + isChinaCDN can be used to bypass China's firewall which blocks VWO tracking + */ +@property BOOL isChinaCDN; + /** Custom Variable is used in the cases where developer intends to programatically create segmentation. */ diff --git a/VWO/VWOConfig.m b/VWO/VWOConfig.m index 3c59ceba..92c1b395 100644 --- a/VWO/VWOConfig.m +++ b/VWO/VWOConfig.m @@ -13,6 +13,7 @@ @implementation VWOConfig - (NSString *)description { return [NSString stringWithFormat:@"Optout: %@\nPreviewDisabled: %@\nUserID: %@\n%@", self.optOut ? @"YES" : @"NO", + self.isChinaCDN ? @"YES" : @"NO", self.disablePreview ? @"YES" : @"NO", self.userID, self.customVariables]; diff --git a/VWO/VWOController.h b/VWO/VWOController.h index f8fb2873..43063ee5 100644 --- a/VWO/VWOController.h +++ b/VWO/VWOController.h @@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN -static NSString *kVWOSDKversion = @"2.7.1"; +static NSString *kVWOSDKversion = @"2.8.0"; @class VWOConfig; diff --git a/VWO/VWOController.m b/VWO/VWOController.m index e771dd75..ad83a370 100644 --- a/VWO/VWOController.m +++ b/VWO/VWOController.m @@ -73,7 +73,7 @@ - (void)launchWithAPIKey:(NSString *)apiKey _vwoConfig = config; self.customVariables = [config.customVariables mutableCopy]; [self updateAPIKey:apiKey]; - _vwoURL = [VWOURL urlWithAppKey:_appKey accountID:_accountID]; + _vwoURL = [VWOURL urlWithAppKey:_appKey accountID:_accountID isChinaCDN:config.isChinaCDN]; if (config.optOut) { [self handleOptOutwithCompletion:completionBlock]; return; diff --git a/VWO/VWOURL.h b/VWO/VWOURL.h index ec21f0a1..f6d2e523 100644 --- a/VWO/VWOURL.h +++ b/VWO/VWOURL.h @@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN @interface VWOURL : NSObject -+ (instancetype)urlWithAppKey:(NSString *)appKey accountID:(NSString *)accountID; ++ (instancetype)urlWithAppKey:(NSString *)appKey accountID:(NSString *)accountID isChinaCDN:(BOOL)isChinaCDN; - (NSURL *)forFetchingCampaigns:(nullable NSString *)userID; diff --git a/VWO/VWOURL.m b/VWO/VWOURL.m index add5a3f0..8a8a1105 100644 --- a/VWO/VWOURL.m +++ b/VWO/VWOURL.m @@ -17,37 +17,43 @@ @implementation NSURLComponents (VWO) /// Creates URL component with scheme host and path. Eg: https://dacdn.visual.com/path -+ (instancetype)vwoComponentForPath:(NSString *)path { ++ (instancetype)vwoComponentForPath:(NSString *)path isChinaCDN:(BOOL)isChinaCDN { NSURLComponents *components = [NSURLComponents new]; [components setScheme:@"https"]; - [components setHost:@"dacdn.visualwebsiteoptimizer.com"]; + if (isChinaCDN) { + [components setHost:@"cdn-cn.vwo-analytics.com"]; + } else { + [components setHost:@"dacdn.visualwebsiteoptimizer.com"]; + } [components setPath:path]; return components; } @end -static NSString *kSDKversionNumber = @"17"; +static NSString *kSDKversionNumber = @"18"; @interface VWOURL() @property NSString *appKey; @property NSString *accountID; +@property BOOL isChinaCDN; @end @implementation VWOURL -+ (instancetype)urlWithAppKey:(NSString *)appKey accountID:(NSString *)accountID { - return [[self alloc] initWithAppKey:appKey accountID:accountID]; ++ (instancetype)urlWithAppKey:(NSString *)appKey accountID:(NSString *)accountID isChinaCDN:(BOOL)isChinaCDN { + return [[self alloc] initWithAppKey:appKey accountID:accountID isChinaCDN:isChinaCDN]; } -- (instancetype)initWithAppKey:(NSString *)appKey accountID:(NSString *)accountID { +- (instancetype)initWithAppKey:(NSString *)appKey accountID:(NSString *)accountID isChinaCDN:(BOOL)isChinaCDN { NSParameterAssert(appKey != nil); NSParameterAssert(accountID != nil); self = [self init]; if (self) { _appKey = appKey; _accountID = accountID; + _isChinaCDN = isChinaCDN; } return self; } @@ -71,7 +77,7 @@ - (NSDictionary *)extraParametersWithDate:(NSDate *)date { #pragma mark - Public Methods - (NSURL *)forFetchingCampaigns:(nullable NSString *)userID { - NSURLComponents *components = [NSURLComponents vwoComponentForPath:@"/mobile"]; + NSURLComponents *components = [NSURLComponents vwoComponentForPath:@"/mobile" isChinaCDN:_isChinaCDN]; NSMutableDictionary *paramDict = [@{@"api-version": @"2", @"a" : _accountID, @@ -95,7 +101,7 @@ - (NSURL *)forFetchingCampaigns:(nullable NSString *)userID { - (NSURL *)forMakingUserPartOfCampaign:(VWOCampaign *)campaign dateTime:(NSDate *)date config:(VWOConfig *) config { - NSURLComponents *components = [NSURLComponents vwoComponentForPath:@"/track-user"]; + NSURLComponents *components = [NSURLComponents vwoComponentForPath:@"/track-user" isChinaCDN:_isChinaCDN]; NSMutableDictionary *paramDict = [@{@"experiment_id": [NSString stringWithFormat:@"%d", campaign.iD], @"account_id" : _accountID, @@ -117,7 +123,7 @@ - (NSURL *)forMarkingGoal:(VWOGoal *)goal withValue:(NSNumber *)goalValue campaign:(VWOCampaign *)campaign dateTime:(NSDate *)date { - NSURLComponents *components = [NSURLComponents vwoComponentForPath:@"/track-goal"]; + NSURLComponents *components = [NSURLComponents vwoComponentForPath:@"/track-goal" isChinaCDN:_isChinaCDN]; NSMutableDictionary *paramDict = [NSMutableDictionary new]; paramDict[@"experiment_id"] = [NSString stringWithFormat:@"%d", campaign.iD]; paramDict[@"account_id"] = _accountID; @@ -137,7 +143,7 @@ - (NSURL *)forMarkingGoal:(VWOGoal *)goal } - (NSURL *)forPushingCustomDimension:(NSString *)customDimensionKey withCustomDimensionValue:(nonnull NSString *)customDimensionValue dateTime:(nonnull NSDate *)date { - NSURLComponents *components = [NSURLComponents vwoComponentForPath:@"/mobile-app/push"]; + NSURLComponents *components = [NSURLComponents vwoComponentForPath:@"/mobile-app/push" isChinaCDN:_isChinaCDN]; NSMutableDictionary *paramDict = [NSMutableDictionary new]; paramDict[@"account_id"] = _accountID; paramDict[@"u"] = VWOUserDefaults.UUID;