Skip to content

Commit 779929a

Browse files
arafay-folio3wangjoshuah
authored andcommitted
removed track APIs with revenue as a parameter (#226)
Use event tags to pass in revenue information instead.
1 parent 99ccb38 commit 779929a

File tree

4 files changed

+41
-113
lines changed

4 files changed

+41
-113
lines changed

OptimizelySDKCore/OptimizelySDKCore/Optimizely.h

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ extern NSString * _Nonnull const OptimizelyNotificationsUserDictionaryVariationK
2222
extern NSString * _Nonnull const OptimizelyNotificationsUserDictionaryUserIdKey;
2323
extern NSString * _Nonnull const OptimizelyNotificationsUserDictionaryAttributesKey;
2424
extern NSString * _Nonnull const OptimizelyNotificationsUserDictionaryEventNameKey;
25-
extern NSString * _Nonnull const OptimizelyNotificationsUserDictionaryEventValueKey;
2625
extern NSString * _Nonnull const OptimizelyNotificationsUserDictionaryExperimentVariationMappingKey;
2726

2827
@class OPTLYProjectConfig, OPTLYVariation, OPTLYDecisionService, OPTLYNotificationCenter;
@@ -201,26 +200,6 @@ extern NSString * _Nonnull const OptimizelyNotificationsUserDictionaryExperiment
201200
- (void)track:(nonnull NSString *)eventKey
202201
userId:(nonnull NSString *)userId;
203202

204-
/** @deprecated. Use `track:userId:eventValue`.
205-
* Track an event
206-
* @param eventKey The event name
207-
* @param userId The user ID associated with the event to track
208-
* @param eventValue The event value (e.g., revenue amount)
209-
*/
210-
- (void)track:(nonnull NSString *)eventKey
211-
userId:(nonnull NSString *)userId
212-
eventValue:(nonnull NSNumber *)eventValue __attribute((deprecated("eventValue is deprecated in track call. Use eventTags to pass in revenue value instead.")));
213-
214-
/**
215-
* Track an event
216-
* @param eventKey The event name
217-
* @param userId The user ID associated with the event to track
218-
* @param eventTags A map of event tag names to event tag values (NSString or NSNumber containing float, double, integer, or boolean)
219-
*/
220-
- (void)track:(nonnull NSString *)eventKey
221-
userId:(nonnull NSString *)userId
222-
eventTags:(nonnull NSDictionary<NSString *, id> *)eventTags;
223-
224203
/**
225204
* Track an event
226205
* @param eventKey The event name
@@ -231,17 +210,15 @@ extern NSString * _Nonnull const OptimizelyNotificationsUserDictionaryExperiment
231210
userId:(nonnull NSString *)userId
232211
attributes:(nonnull NSDictionary<NSString *, NSString *> *)attributes;
233212

234-
/** @deprecated. Use `track:userId:attributes:eventValue`.
213+
/**
235214
* Track an event
236215
* @param eventKey The event name
237216
* @param userId The user ID associated with the event to track
238-
* @param attributes A map of attribute names to current user attribute values
239-
* @param eventValue The event value (e.g., revenue amount)
217+
* @param eventTags A map of event tag names to event tag values (NSString or NSNumber containing float, double, integer, or boolean)
240218
*/
241219
- (void)track:(nonnull NSString *)eventKey
242220
userId:(nonnull NSString *)userId
243-
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes
244-
eventValue:(nullable NSNumber *)eventValue __attribute((deprecated("eventValue is deprecated in track call. Use eventTags to pass in revenue value instead.")));
221+
eventTags:(nonnull NSDictionary<NSString *, id> *)eventTags;
245222

246223
/**
247224
* Track an event
@@ -280,19 +257,16 @@ extern NSString * _Nonnull const OptimizelyNotificationsUserDictionaryExperiment
280257
*/
281258
+ (nullable instancetype)init:(nonnull OPTLYBuilderBlock)builderBlock;
282259

283-
// TODO: remove when eventValue is deprecated
284260
/**
285261
* Track an event
286262
* @param eventKey The event name
287263
* @param userId The user ID associated with the event to track
288264
* @param attributes A map of attribute names to current user attribute values.
289265
* @param eventTags A map of event tag names to event tag values (string, number, or boolean)
290-
* @param eventValue The event value (e.g., revenue amount)
291266
*/
292267
- (void)track:(nonnull NSString *)eventKey
293268
userId:(nonnull NSString *)userId
294269
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes
295-
eventTags:(nullable NSDictionary<NSString *, id> *)eventTags
296-
eventValue:(nullable NSNumber *)eventValue;
270+
eventTags:(nullable NSDictionary<NSString *, id> *)eventTags;
297271

298272
@end

OptimizelySDKCore/OptimizelySDKCore/Optimizely.m

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
NSString *const OptimizelyNotificationsUserDictionaryUserIdKey = @"userId";
4444
NSString *const OptimizelyNotificationsUserDictionaryAttributesKey = @"attributes";
4545
NSString *const OptimizelyNotificationsUserDictionaryEventNameKey = @"eventKey";
46-
NSString *const OptimizelyNotificationsUserDictionaryEventValueKey = @"eventValue";
4746
NSString *const OptimizelyNotificationsUserDictionaryExperimentVariationMappingKey = @"ExperimentVariationMapping";
4847

4948
@implementation Optimizely
@@ -369,66 +368,35 @@ - (NSString *)getFeatureVariableString:(nullable NSString *)featureKey
369368
}
370369

371370
#pragma mark trackEvent methods
372-
- (void)track:(NSString *)eventKey userId:(NSString *)userId
373-
{
374-
[self track:eventKey userId:userId attributes:nil eventTags:nil eventValue:nil];
375-
}
376-
377-
- (void)track:(NSString *)eventKey
378-
userId:(NSString *)userId
379-
attributes:(NSDictionary<NSString *, NSString *> * )attributes
380-
{
381-
[self track:eventKey userId:userId attributes:attributes eventTags:nil eventValue:nil];
382-
}
383-
384-
- (void)track:(NSString *)eventKey
385-
userId:(NSString *)userId
386-
eventValue:(NSNumber *)eventValue
387-
{
388-
[self track:eventKey userId:userId attributes:nil eventTags:nil eventValue:eventValue];
389-
}
390371

391-
- (void)track:(NSString *)eventKey
392-
userId:(NSString *)userId
393-
eventTags:(NSDictionary *)eventTags
394-
{
395-
[self track:eventKey userId:userId attributes:nil eventTags:eventTags eventValue:nil];
372+
- (void)track:(NSString *)eventKey userId:(NSString *)userId {
373+
[self track:eventKey userId:userId attributes:nil eventTags:nil];
396374
}
397375

398376
- (void)track:(NSString *)eventKey
399377
userId:(NSString *)userId
400-
attributes:(NSDictionary *)attributes
401-
eventValue:(NSNumber *)eventValue
402-
{
403-
[self track:eventKey userId:userId attributes:attributes eventTags:nil eventValue:eventValue];
378+
attributes:(NSDictionary<NSString *, NSString *> * )attributes {
379+
[self track:eventKey userId:userId attributes:attributes eventTags:nil];
404380
}
405381

406382
- (void)track:(NSString *)eventKey
407383
userId:(NSString *)userId
408-
attributes:(NSDictionary *)attributes
409-
eventTags:(NSDictionary *)eventTags
410-
{
411-
[self track:eventKey userId:userId attributes:attributes eventTags:eventTags eventValue:nil];
384+
eventTags:(NSDictionary<NSString *,id> *)eventTags {
385+
[self track:eventKey userId:userId attributes:nil eventTags:eventTags];
412386
}
413387

414388
- (void)track:(NSString *)eventKey
415389
userId:(NSString *)userId
416-
attributes:(NSDictionary *)attributes
417-
eventTags:(NSDictionary *)eventTags
418-
eventValue:(NSNumber *)eventValue
419-
{
390+
attributes:(NSDictionary<NSString *,NSString *> *)attributes
391+
eventTags:(NSDictionary<NSString *,id> *)eventTags {
392+
420393
OPTLYEvent *event = [self.config getEventForKey:eventKey];
421394

422395
if (!event) {
423396
[self handleErrorLogsForTrackEvent:eventKey userId:userId];
424397
return;
425398
}
426399

427-
// eventValue and eventTags are mutually exclusive
428-
if (eventValue) {
429-
eventTags = @{ OPTLYEventMetricNameRevenue: eventValue };
430-
}
431-
432400
NSDictionary *conversionEventParams = [self.eventBuilder buildConversionTicket:self.config
433401
bucketer:self.bucketer
434402
userId:userId
@@ -463,9 +431,6 @@ - (void)track:(NSString *)eventKey
463431
if (attributes != nil) {
464432
userInfo[OptimizelyNotificationsUserDictionaryAttributesKey] = attributes;
465433
}
466-
if (eventValue != nil) {
467-
userInfo[OptimizelyNotificationsUserDictionaryEventValueKey] = eventValue;
468-
}
469434
NSMutableDictionary *experimentVariationMapping = [NSMutableDictionary new];
470435

471436
NSArray *visitors = conversionEventParams[OPTLYEventParameterKeysVisitors];

OptimizelySDKCore/OptimizelySDKCoreTests/OptimizelyTest.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#import "OPTLYFeatureDecision.h"
3131
#import "OPTLYFeatureVariable.h"
3232
#import "OPTLYNotificationCenter.h"
33+
#import "OPTLYEventMetric.h"
3334

3435
static NSString *const kUserId = @"userId";
3536
static NSString *const kExperimentKey = @"testExperimentWithFirefoxAudience";
@@ -275,6 +276,22 @@ - (void)testOptimizelyPostEventTrackNotification {
275276
XCTAssertEqual(eventKey, notificationEventKey);
276277
}
277278

279+
- (void)testOptimizelyPostEventTrackNotificationWithEventTags {
280+
281+
NSString *eventKey = @"testEvent";
282+
NSDictionary *eventTags = @{ OPTLYEventMetricNameRevenue: @(2.5)};
283+
__block NSString *notificationEventKey = nil;
284+
__block NSDictionary *notificationEventTags = nil;
285+
286+
[self.optimizely.notificationCenter addTrackNotificationListener:^(NSString * _Nonnull eventKey, NSString * _Nonnull userId, NSDictionary<NSString *,NSString *> * _Nonnull attributes, NSDictionary * _Nonnull eventTags, NSDictionary<NSString *,NSObject *> * _Nonnull event) {
287+
notificationEventKey = eventKey;
288+
notificationEventTags = eventTags;
289+
}];
290+
[self.optimizely track:eventKey userId:kUserId eventTags:eventTags];
291+
XCTAssertEqual(eventKey, notificationEventKey);
292+
XCTAssertEqual(eventTags, notificationEventTags);
293+
}
294+
278295
# pragma mark - IsFeatureEnabled Tests
279296

280297
// Should return false when arguments are nil or empty.

OptimizelySDKShared/OptimizelySDKShared/OPTLYClient.m

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -230,53 +230,26 @@ - (NSString * _Nullable)getFeatureVariableString:(nullable NSString *)featureKey
230230
}
231231

232232
#pragma mark trackEvent methods
233-
- (void)track:(NSString *)eventKey userId:(NSString *)userId
234-
{
235-
[self track:eventKey userId:userId attributes:nil eventTags:nil eventValue:nil];
233+
- (void)track:(NSString *)eventKey userId:(NSString *)userId {
234+
[self track:eventKey userId:userId attributes:nil eventTags:nil];
236235
}
237236

238237
- (void)track:(NSString *)eventKey
239238
userId:(NSString *)userId
240-
attributes:(NSDictionary<NSString *, NSString *> * )attributes
241-
{
242-
[self track:eventKey userId:userId attributes:attributes eventTags:nil eventValue:nil];
239+
attributes:(NSDictionary<NSString *, NSString *> * )attributes {
240+
[self track:eventKey userId:userId attributes:attributes eventTags:nil];
243241
}
244242

245243
- (void)track:(NSString *)eventKey
246-
userId:(NSString *)userId
247-
eventValue:(NSNumber *)eventValue
248-
{
249-
[self track:eventKey userId:userId attributes:nil eventTags:nil eventValue:eventValue];
250-
}
251-
252-
- (void)track:(NSString *)eventKey
253-
userId:(NSString *)userId
254-
eventTags:(NSDictionary *)eventTags
255-
{
256-
[self track:eventKey userId:userId attributes:nil eventTags:eventTags eventValue:nil];
257-
}
258-
259-
- (void)track:(NSString *)eventKey
260-
userId:(NSString *)userId
261-
attributes:(NSDictionary *)attributes
262-
eventValue:(NSNumber *)eventValue
263-
{
264-
[self track:eventKey userId:userId attributes:attributes eventTags:nil eventValue:eventValue];
244+
userId:(NSString *)userId
245+
eventTags:(NSDictionary<NSString *,id> *)eventTags {
246+
[self track:eventKey userId:userId attributes:nil eventTags:eventTags];
265247
}
266248

267249
- (void)track:(NSString *)eventKey
268-
userId:(NSString *)userId
269-
attributes:(NSDictionary *)attributes
270-
eventTags:(NSDictionary *)eventTags
271-
{
272-
[self track:eventKey userId:userId attributes:attributes eventTags:eventTags eventValue:nil];
273-
}
274-
275-
- (void)track:(NSString *)eventKey
276-
userId:(NSString *)userId
277-
attributes:(NSDictionary *)attributes
278-
eventTags:(NSDictionary *)eventTags
279-
eventValue:(NSNumber *)eventValue {
250+
userId:(NSString *)userId
251+
attributes:(NSDictionary<NSString *,NSString *> *)attributes
252+
eventTags:(NSDictionary<NSString *,id> *)eventTags {
280253
if (self.optimizely == nil) {
281254
[self.logger logMessage:OPTLYLoggerMessagesClientDummyOptimizelyError
282255
withLevel:OptimizelyLogLevelError];
@@ -285,8 +258,7 @@ - (void)track:(NSString *)eventKey
285258
[self.optimizely track:eventKey
286259
userId:userId
287260
attributes:attributes
288-
eventTags:eventTags
289-
eventValue:eventValue];
261+
eventTags:eventTags];
290262
}
291263

292264
- (NSString *)description {

0 commit comments

Comments
 (0)