Skip to content

Commit f308d68

Browse files
refactor(EventBuilder): Moved decision service and bucketing from EventBuilder to Optimizely (#306)
* Send decisions for all experiments using an event * nits * accept tags as event tags even if not convertible to revenue or value tag * Optimizely refactored * make projectConfig a private property of EventBuilder instead passing it to every method * impression event refactored * track and conversion refactored * test cases * fixed test cases * Optimizely coverage increased * EventBuilder coverage increased * LoggerMessages refactored * removed params validation from eventBuilder methods, 
updated license headers, 
removed unused loggerMessages * removed 'ticket' from eventBuilder methods and separated event tags work from EventBuilder class by making it a Util
1 parent e5af712 commit f308d68

File tree

14 files changed

+887
-784
lines changed

14 files changed

+887
-784
lines changed

OptimizelySDKCore/OptimizelySDKCore.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@
217217
5E4C07FC1DFF66B00042B1F8 /* OPTLYNetworkServiceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E4C07FA1DFF66B00042B1F8 /* OPTLYNetworkServiceTest.m */; };
218218
5ECBBE681DDE6A800028FF6B /* OPTLYVariable.h in Headers */ = {isa = PBXBuildFile; fileRef = 5ECBBE661DDE6A800028FF6B /* OPTLYVariable.h */; settings = {ATTRIBUTES = (Public, ); }; };
219219
5ECBBE691DDE6A800028FF6B /* OPTLYVariable.m in Sources */ = {isa = PBXBuildFile; fileRef = 5ECBBE671DDE6A800028FF6B /* OPTLYVariable.m */; };
220+
9084F7812150D4F700ACBA99 /* OPTLYEventTagUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 9084F77F2150D4F700ACBA99 /* OPTLYEventTagUtil.h */; settings = {ATTRIBUTES = (Public, ); }; };
221+
9084F7822150D4F800ACBA99 /* OPTLYEventTagUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 9084F77F2150D4F700ACBA99 /* OPTLYEventTagUtil.h */; settings = {ATTRIBUTES = (Public, ); }; };
222+
9084F7832150D4F800ACBA99 /* OPTLYEventTagUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 9084F7802150D4F700ACBA99 /* OPTLYEventTagUtil.m */; };
223+
9084F7842150D4F800ACBA99 /* OPTLYEventTagUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 9084F7802150D4F700ACBA99 /* OPTLYEventTagUtil.m */; };
220224
90855D0020ED254500A97BEC /* OPTLYControlAttributes.h in Headers */ = {isa = PBXBuildFile; fileRef = 90855CFC20ED237F00A97BEC /* OPTLYControlAttributes.h */; settings = {ATTRIBUTES = (Public, ); }; };
221225
90855D0120ED254600A97BEC /* OPTLYControlAttributes.h in Headers */ = {isa = PBXBuildFile; fileRef = 90855CFC20ED237F00A97BEC /* OPTLYControlAttributes.h */; settings = {ATTRIBUTES = (Public, ); }; };
222226
90855D0D20ED2E0100A97BEC /* OPTLYControlAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = 90855D0420ED2B0200A97BEC /* OPTLYControlAttributes.m */; };
@@ -614,6 +618,8 @@
614618
5ECBBE671DDE6A800028FF6B /* OPTLYVariable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYVariable.m; sourceTree = "<group>"; };
615619
8766E217ECD3BEA353B080F5 /* Pods_OptimizelySDKCoreiOSTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_OptimizelySDKCoreiOSTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
616620
8B04E0101E180FAD8C9CA7A6 /* Pods_OptimizelySDKCoreiOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_OptimizelySDKCoreiOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
621+
9084F77F2150D4F700ACBA99 /* OPTLYEventTagUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OPTLYEventTagUtil.h; sourceTree = "<group>"; };
622+
9084F7802150D4F700ACBA99 /* OPTLYEventTagUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OPTLYEventTagUtil.m; sourceTree = "<group>"; };
617623
90855CFC20ED237F00A97BEC /* OPTLYControlAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OPTLYControlAttributes.h; path = OptimizelySDKCore/OPTLYControlAttributes.h; sourceTree = "<group>"; };
618624
90855D0420ED2B0200A97BEC /* OPTLYControlAttributes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OPTLYControlAttributes.m; path = OptimizelySDKCore/OPTLYControlAttributes.m; sourceTree = "<group>"; };
619625
924C83E5511EF3E43FC015AF /* Pods-OptimizelySDKCoreTVOSTests.rc.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OptimizelySDKCoreTVOSTests.rc.xcconfig"; path = "../Pods/Target Support Files/Pods-OptimizelySDKCoreTVOSTests/Pods-OptimizelySDKCoreTVOSTests.rc.xcconfig"; sourceTree = "<group>"; };
@@ -1004,6 +1010,8 @@
10041010
EA2FAB6E1DC6F5F400B1D81B /* OPTLYLog.m */,
10051011
EA064BC51DD3FC8800DF7537 /* OPTLYQueue.h */,
10061012
EA064BC61DD3FC8800DF7537 /* OPTLYQueue.m */,
1013+
9084F77F2150D4F700ACBA99 /* OPTLYEventTagUtil.h */,
1014+
9084F7802150D4F700ACBA99 /* OPTLYEventTagUtil.m */,
10071015
);
10081016
name = Utilities;
10091017
sourceTree = "<group>";
@@ -1350,6 +1358,7 @@
13501358
EA2FAAE21DC6F57200B1D81B /* OPTLYEventMetric.h in Headers */,
13511359
EA2FAA8E1DC6F57100B1D81B /* OPTLYAudience.h in Headers */,
13521360
EA2FAA9A1DC6F57100B1D81B /* OPTLYCondition.h in Headers */,
1361+
9084F7812150D4F700ACBA99 /* OPTLYEventTagUtil.h in Headers */,
13531362
EA16D9361ECBA9B200C4C998 /* OPTLYUserProfile.h in Headers */,
13541363
EA16D93C1ECBD90E00C4C998 /* OPTLYExperimentBucketMapEntity.h in Headers */,
13551364
EA8FD0DF1DE9798E00D950AD /* OPTLYNetworkService.h in Headers */,
@@ -1414,6 +1423,7 @@
14141423
EA2FAAEF1DC6F57200B1D81B /* OPTLYEventRelatedEvent.h in Headers */,
14151424
EAC5F3441E7B7DDF00C087B8 /* OPTLYEventDispatcherBasic.h in Headers */,
14161425
EA16D9371ECBA9B200C4C998 /* OPTLYUserProfile.h in Headers */,
1426+
9084F7822150D4F800ACBA99 /* OPTLYEventTagUtil.h in Headers */,
14171427
EA16D93D1ECBD90E00C4C998 /* OPTLYExperimentBucketMapEntity.h in Headers */,
14181428
EAC5F3541E7B7EEF00C087B8 /* OPTLYUserProfileServiceBasic.h in Headers */,
14191429
EA2FAAA71DC6F57200B1D81B /* OPTLYDecisionEventTicket.h in Headers */,
@@ -1910,6 +1920,7 @@
19101920
EA2FAC101DC6FFC600B1D81B /* OPTLYEvent.m in Sources */,
19111921
3EA563A11FFD23FF00D0E311 /* OPTLYNotificationCenter.m in Sources */,
19121922
EA16D9441ECCC5C600C4C998 /* OPTLYDecisionService.m in Sources */,
1923+
9084F7832150D4F800ACBA99 /* OPTLYEventTagUtil.m in Sources */,
19131924
EAC5F3551E7B7EEF00C087B8 /* OPTLYUserProfileServiceBasic.m in Sources */,
19141925
EA2FAC111DC6FFC600B1D81B /* OPTLYEventAudience.m in Sources */,
19151926
EA2FAC121DC6FFC600B1D81B /* OPTLYEventDecision.m in Sources */,
@@ -2000,6 +2011,7 @@
20002011
EA16D9451ECCC5C600C4C998 /* OPTLYDecisionService.m in Sources */,
20012012
3EA563A21FFD23FF00D0E311 /* OPTLYNotificationCenter.m in Sources */,
20022013
EA2FABEC1DC6FFA100B1D81B /* OPTLYEventAudience.m in Sources */,
2014+
9084F7842150D4F800ACBA99 /* OPTLYEventTagUtil.m in Sources */,
20032015
EA2FABED1DC6FFA100B1D81B /* OPTLYEventDecision.m in Sources */,
20042016
EA2FABEE1DC6FFA100B1D81B /* OPTLYEventDecisionTicket.m in Sources */,
20052017
EA2FABEF1DC6FFA100B1D81B /* OPTLYEventFeature.m in Sources */,

OptimizelySDKCore/OptimizelySDKCore/OPTLYBuilder.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ - (id)initWithBlock:(OPTLYBuilderBlock)block {
7474

7575
_bucketer = [[OPTLYBucketer alloc] initWithConfig:_config];
7676
_decisionService = [[OPTLYDecisionService alloc] initWithProjectConfig:_config bucketer:_bucketer];
77-
_eventBuilder = [[OPTLYEventBuilderDefault alloc] init];
77+
_eventBuilder = [[OPTLYEventBuilderDefault alloc] initWithConfig:_config];
7878
_notificationCenter = [[OPTLYNotificationCenter alloc] initWithProjectConfig:_config];
7979

8080
return self;

OptimizelySDKCore/OptimizelySDKCore/OPTLYEventBuilder.h

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#import <Foundation/Foundation.h>
2222

23-
@class OPTLYProjectConfig, OPTLYDecisionEventTicket;
23+
@class OPTLYProjectConfig, OPTLYExperiment, OPTLYVariation, OPTLYEvent;
2424
@protocol OPTLYBucketer;
2525

2626
// --- Event URLs ----
@@ -34,39 +34,45 @@ NS_ASSUME_NONNULL_END
3434
/**
3535
* Create the parameters for an impression event.
3636
*
37-
* @param config The project config object.
3837
* @param userId The ID of the user.
39-
* @param experimentKey The experiment name.
40-
* @param variationId The variation ID.
38+
* @param experiment The experiment.
39+
* @param variation The variation.
4140
* @param attributes A map of attribute names to current user attribute values.
4241
* @return A map of parameters for an impression event. This value can be nil.
4342
*
4443
*/
45-
- (nullable NSDictionary *)buildImpressionEventTicket:(nonnull OPTLYProjectConfig *)config
46-
userId:(nonnull NSString *)userId
47-
experimentKey:(nonnull NSString *)experimentKey
48-
variationId:(nonnull NSString *)variationId
49-
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
44+
- (nullable NSDictionary *)buildImpressionEventForUser:(nonnull NSString *)userId
45+
experiment:(nonnull OPTLYExperiment *)experiment
46+
variation:(nonnull OPTLYVariation *)variation
47+
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
5048

5149
/**
5250
* Create the parameters for a conversion event.
5351
*
54-
* @param config The project config object.
5552
* @param userId The ID of the user.
56-
* @param eventName The event name.
53+
* @param event The event name.
5754
* @param eventTags A map of event tag names to event tag values (NSString or NSNumber containing float, double, integer, or boolean).
5855
* @param attributes A map of attribute names to current user attribute values.
5956
* @return A map of parameters for a conversion event. This value can be nil.
6057
*
6158
*/
62-
- (nullable NSDictionary *)buildConversionTicket:(nonnull OPTLYProjectConfig *)config
63-
bucketer:(nonnull id<OPTLYBucketer>)bucketer
64-
userId:(nonnull NSString *)userId
65-
eventName:(nonnull NSString *)eventName
66-
eventTags:(nullable NSDictionary *)eventTags
67-
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
59+
- (nullable NSDictionary *)buildConversionEventForUser:(nonnull NSString *)userId
60+
event:(nonnull OPTLYEvent *)event
61+
decisions:(nonnull NSArray<NSDictionary *> *)decisions
62+
eventTags:(nullable NSDictionary *)eventTags
63+
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
6864
@end
6965

7066
@interface OPTLYEventBuilderDefault : NSObject<OPTLYEventBuilder>
7167

68+
/// init is disabled. Please use initWithConfig to create an Event Builder
69+
- (instancetype)init NS_UNAVAILABLE;
70+
71+
/**
72+
* Initialize the default event build with the project config.
73+
* @param config The project config that the event builder will use for event building.
74+
* @return The event builder that has been created.
75+
*/
76+
- (nullable instancetype)initWithConfig:(nonnull OPTLYProjectConfig *)config;
77+
7278
@end

0 commit comments

Comments
 (0)