Skip to content

Commit

Permalink
feat(sdk): support for configuring and using VWO chinese cdn
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyamjain65 authored and Varun Malhotra committed Dec 22, 2021
1 parent 4f03719 commit 97af013
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 20 deletions.
12 changes: 6 additions & 6 deletions Demo/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
1 change: 1 addition & 0 deletions Demo/VWO Demo/VWOManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion VWO.podspec
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 5 additions & 0 deletions VWO/VWOConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
1 change: 1 addition & 0 deletions VWO/VWOConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion VWO/VWOController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

NS_ASSUME_NONNULL_BEGIN

static NSString *kVWOSDKversion = @"2.7.1";
static NSString *kVWOSDKversion = @"2.8.0";

@class VWOConfig;

Expand Down
2 changes: 1 addition & 1 deletion VWO/VWOController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion VWO/VWOURL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
26 changes: 16 additions & 10 deletions VWO/VWOURL.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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 <NSString *, NSString *> *paramDict = [NSMutableDictionary new];
paramDict[@"experiment_id"] = [NSString stringWithFormat:@"%d", campaign.iD];
paramDict[@"account_id"] = _accountID;
Expand All @@ -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 <NSString *, NSString *> *paramDict = [NSMutableDictionary new];
paramDict[@"account_id"] = _accountID;
paramDict[@"u"] = VWOUserDefaults.UUID;
Expand Down

0 comments on commit 97af013

Please sign in to comment.