Skip to content

Commit

Permalink
feat(sdk): custom dimesion support via push API and in luanch config
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyamjain65 authored and Varun Malhotra committed Jun 9, 2021
1 parent 8da135d commit 885a5d6
Show file tree
Hide file tree
Showing 20 changed files with 267 additions and 18 deletions.
1 change: 1 addition & 0 deletions Demo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ platform :ios, '9.0'

target 'VWO Demo' do
use_frameworks!
#pod 'VWO', '~> 2.7'
pod 'VWO', :path => '../'
# pod 'FLEX', '~> 2.0', :configurations => ['Debug']
pod 'SCLAlertView'
Expand Down
10 changes: 5 additions & 5 deletions Demo/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PODS:
- MBProgressHUD (1.1.0)
- SCLAlertView (0.8)
- Socket.IO-Client-Swift (13.3.0):
- Socket.IO-Client-Swift (13.4.0):
- Starscream (~> 3.0.2)
- Starscream (3.0.5)
- Starscream (3.0.6)
- VWO (2.6.0):
- VWO/All (= 2.6.0)
- VWO/All (2.6.0):
Expand All @@ -28,10 +28,10 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
MBProgressHUD: e7baa36a220447d8aeb12769bf0585582f3866d9
SCLAlertView: 6a77bb2edfc65e04dbe57725546cb4107a506b85
Socket.IO-Client-Swift: 0afb192a562db90d50e3f7f7421c06925a3f0179
Starscream: faf918b2f2eff7d5dd21180646bf015a669673bd
Socket.IO-Client-Swift: 2b2720f14c92ff1237ced09bc2f2da2022624fee
Starscream: ef3ece99d765eeccb67de105bfa143f929026cf5
VWO: 67b825b53b72ede9fe11796a2e137c7e893c36b6

PODFILE CHECKSUM: 132ef71ef05014159c35355b317739088f66af35
PODFILE CHECKSUM: d4c98c91472994b426b3f22ad61ac4197ae00a0c

COCOAPODS: 1.8.4
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
84 changes: 84 additions & 0 deletions Demo/VWO Demo.xcodeproj/xcshareddata/xcschemes/VWO Demo.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1230"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E34D6BA91F7E4BE40094A905"
BuildableName = "VWO Demo.app"
BlueprintName = "VWO Demo"
ReferencedContainer = "container:VWO Demo.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E34D6BA91F7E4BE40094A905"
BuildableName = "VWO Demo.app"
BlueprintName = "VWO Demo"
ReferencedContainer = "container:VWO Demo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-VWOApiKey 20d11bb3c68db966715757f8cbeaf8b5-469557"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E34D6BA91F7E4BE40094A905"
BuildableName = "VWO Demo.app"
BlueprintName = "VWO Demo"
ReferencedContainer = "container:VWO Demo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
4 changes: 3 additions & 1 deletion Demo/VWO Demo/VWOManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class VWOManager {

VWO.logLevel = .debug
let config = VWOConfig()
// config.userID = "info@vow.com"
// config.setCustomDimension(customDimensionKey: "userId", customDimensionValue: "userName")
config.userID = "userId"
VWO.launch(apiKey: apiKey, config: config, completion: {
DispatchQueue.main.async {
// VWO.pushCustomDimension(customDimensionKey: "userId", customDimensionValue: "userName")
hud.hide(animated: false)
SCLAlertView().showSuccess("Success", subTitle: "VWO launched successfully \(apiKey)")
}
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.6.0"
s.version = "2.7.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
2 changes: 2 additions & 0 deletions VWO.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@
SWIFT_OBJC_BRIDGING_HEADER = "VWOTests/VWOTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
VALIDATE_WORKSPACE = YES;
};
name = Debug;
};
Expand All @@ -952,6 +953,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "VWOTests/VWOTests-Bridging-Header.h";
SWIFT_VERSION = 4.0;
VALIDATE_WORKSPACE = YES;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
11 changes: 11 additions & 0 deletions VWO/VWO.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ __deprecated_msg("Use objectForKey:defaultValue instead");
+ (void)setCustomVariable:(NSString *)key
withValue:(NSString *)value NS_SWIFT_NAME(setCustomVariable(key:value:));

/**
Push the custom dimensions to the VWO servers.
* This will help to filter out the reports on VWO web-app.
@param customDimensionKey key for the custom dimension
@param customDimensionValue value corresponding to the given customDimensionKey
*/
+ (void) pushCustomDimension:(NSString *) customDimensionKey
withCustomDimensionValue:(NSString *) customDimensionValue NS_SWIFT_NAME(pushCustomDimension(customDimensionKey:customDimensionValue:));

@end
NS_ASSUME_NONNULL_END

9 changes: 9 additions & 0 deletions VWO/VWO.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ + (void)setCustomVariable:(NSString *)key withValue:(NSString *)value {
});
}

+ (void)pushCustomDimension:(NSString *)customDimensionKey withCustomDimensionValue:(nonnull NSString *)customDimensionValue {
NSParameterAssert(customDimensionKey);
NSParameterAssert(customDimensionValue);
dispatch_barrier_async(VWOController.taskQueue, ^{
[VWOController.shared pushCustomDimension:customDimensionKey withCustomDimensionValue:customDimensionValue];
});

}

+ (NSString *)version {
return kVWOSDKversion;
}
Expand Down
5 changes: 5 additions & 0 deletions VWO/VWOConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
@property NSDictionary<NSString *, NSString*> *customVariables;

@property NSString *customDimension;

/**
Disabling preview would stop VWO from initializing the Socket connection that is done on VWO.launch
Preview is enabled by default
Expand All @@ -28,4 +30,7 @@

@property NSString *userID;

- (void)setCustomDimension:(NSString *)customDimensionKey withCustomDimensionValue:(NSString*) customDimensionValue
NS_SWIFT_NAME(setCustomDimension(customDimensionKey:customDimensionValue:));

@end
6 changes: 6 additions & 0 deletions VWO/VWOConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ - (NSString *)description {
self.userID,
self.customVariables];
}

- (void) setCustomDimension:(nonnull NSString *)customDimensionKey withCustomDimensionValue:(nonnull NSString *)customDimensionValue {
NSAssert(customDimensionKey.length != 0, @"CustomDimensionKey cannot be empty");
NSAssert(customDimensionValue.length != 0, @"customDimensionValue cannot be empty");
_customDimension = [NSString stringWithFormat:@"{\"u\":{\"%@\":\"%@\"}}", customDimensionKey, customDimensionValue];
}
@end
3 changes: 2 additions & 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.6.0";
static NSString *kVWOSDKversion = @"2.7.0";

@class VWOConfig;

Expand All @@ -38,6 +38,7 @@ static NSString *kVWOSDKversion = @"2.6.0";
- (void)trackConversion:(NSString *)goal withValue:(nullable NSNumber *)value;
- (nullable id)variationForKey:(NSString *)key;
- (nullable NSString *)variationNameForCampaignTestKey:(NSString *)campaignTestKey;
- (void)pushCustomDimension:(NSString *) customDimensionKey withCustomDimensionValue:(NSString *) customDimensionValue;

@end

Expand Down
19 changes: 18 additions & 1 deletion VWO/VWOController.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@interface VWOController() <VWOURLQueueDelegate>
@property (atomic) VWOCampaignArray *campaignList;
@property (nonatomic) VWOURL *vwoURL;
@property (atomic) VWOConfig *vwoConfig;
@end

@implementation VWOController {
Expand Down Expand Up @@ -69,6 +70,7 @@ - (void)launchWithAPIKey:(NSString *)apiKey
failure:(void(^)(NSString *error))failureBlock {

VWOConfig *config = configNullable != nil ? configNullable : [VWOConfig new];
_vwoConfig = config;
self.customVariables = [config.customVariables mutableCopy];
[self updateAPIKey:apiKey];
_vwoURL = [VWOURL urlWithAppKey:_appKey accountID:_accountID];
Expand Down Expand Up @@ -318,13 +320,28 @@ - (void)trackUserForCampaign:(VWOCampaign *)campaign {

//Send network request and notification only if the campaign is running

NSURL *url = [_vwoURL forMakingUserPartOfCampaign:campaign dateTime:NSDate.date];
NSURL *url = [_vwoURL forMakingUserPartOfCampaign:campaign dateTime:NSDate.date config: _vwoConfig];
NSString *description = [NSString stringWithFormat:@"Track user %@ %@", campaign, campaign.variation];
[pendingURLQueue enqueue:url maxRetry:10 description:description];

[self sendNotificationUserStartedTracking:campaign];
}

- (void)pushCustomDimension:(nonnull NSString *)customDimensionKey withCustomDimensionValue:(nonnull NSString *)customDimensionValue {
NSAssert(customDimensionKey.length != 0, @"customDimensionKey cannot be empty");
NSAssert(customDimensionValue.length != 0, @"customDimensionValue cannot be empty");

if (!_initialised) {
VWOLogWarning(@"pushCustomDimension called before launching VWO");
return;
}

NSURL *url = [_vwoURL forPushingCustomDimension:customDimensionKey withCustomDimensionValue:customDimensionValue dateTime:NSDate.date];
NSString *description = [NSString stringWithFormat:@"Custom Dimension %@ %@", customDimensionKey, customDimensionValue];
[pendingURLQueue enqueue:url maxRetry:10 description:description];

}

- (void)dealloc {
[NSNotificationCenter.defaultCenter removeObserver:self];
}
Expand Down
9 changes: 7 additions & 2 deletions VWO/VWOURL.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

NS_ASSUME_NONNULL_BEGIN

@class VWOCampaign, VWOGoal, VWOUserDefaults;
@class VWOCampaign, VWOGoal, VWOUserDefaults, VWOConfig;

@interface VWOURL : NSObject

Expand All @@ -19,13 +19,18 @@ NS_ASSUME_NONNULL_BEGIN
- (NSURL *)forFetchingCampaigns:(nullable NSString *)userID;

- (NSURL *)forMakingUserPartOfCampaign:(VWOCampaign *)campaign
dateTime:(NSDate *)date;
dateTime:(NSDate *)date
config:(VWOConfig *) config;

- (NSURL *)forMarkingGoal:(VWOGoal *)goal
withValue:(nullable NSNumber *)goalValue
campaign:(VWOCampaign *)campaign
dateTime:(NSDate *)date;

- (NSURL *)forPushingCustomDimension:(NSString *) customDimensionKey
withCustomDimensionValue:(NSString *) customDimensionValue
dateTime:(NSDate *)date;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 885a5d6

Please sign in to comment.