Skip to content

Commit

Permalink
Update non-transaction custom flags and fix NSNumber conversion (#10)
Browse files Browse the repository at this point in the history
* Fix incorrect NSNumber conversion

* Apply custom flags to non-transaction events

* Ensure revenue is not sent as string
  • Loading branch information
peterjenkins authored Mar 23, 2021
1 parent 2974241 commit 7c52491
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions mParticle_Optimizely/MPKitOptimizely.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,39 +126,39 @@ - (MPKitExecStatus *)routeCommerceEvent:(MPCommerceEvent *)commerceEvent {

for (MPCommerceEventInstruction *commerceEventInstruction in expandedInstructions) {
NSMutableDictionary *baseProductAttributes = [[NSMutableDictionary alloc] init];

NSString *customCommerceEventName;
if (customFlags) {
if (customFlags[MPKitOptimizelyEventName].count != 0) {
customCommerceEventName = customFlags[MPKitOptimizelyEventName][0];
}
if (customFlags[MPKitOptimizelyCustomUserId].count != 0 & customFlags[MPKitOptimizelyCustomUserId][0] != nil) {
userId = customFlags[MPKitOptimizelyCustomUserId][0];
}
}

if (customCommerceEventName) {
commerceEventInstruction.event.name = customCommerceEventName;
}

NSNumber *revenueInCents = nil;
if (commerceEventInstruction.event.type == MPEventTypeTransaction && [commerceEventInstruction.event.name isEqualToString:@"eCommerce - purchase - Total"]) {

NSString *customCommerceEventName;
if (customFlags) {
if (customFlags[MPKitOptimizelyEventName].count != 0) {
customCommerceEventName = customFlags[MPKitOptimizelyEventName][0];
}
}

NSDictionary *transactionAttributes = commerceEventInstruction.event.customAttributes;

if (commerceEvent.transactionAttributes.revenue != nil) {
NSNumber *revenueInCents = [NSNumber numberWithLong:[commerceEvent.transactionAttributes.revenue integerValue]*100];
revenueInCents = [NSNumber numberWithDouble:[commerceEvent.transactionAttributes.revenue doubleValue]*100];
[baseProductAttributes setObject:revenueInCents forKey: @"revenue"];
}

if (transactionAttributes) {
[baseProductAttributes addEntriesFromDictionary:transactionAttributes];
}

if (customCommerceEventName) {
commerceEventInstruction.event.name = customCommerceEventName;
}
}

if (customFlags) {
if (customFlags[MPKitOptimizelyCustomUserId].count != 0 & customFlags[MPKitOptimizelyCustomUserId][0] != nil) {
userId = customFlags[MPKitOptimizelyCustomUserId][0];
}
}

NSDictionary *transformedEventInfo = [baseProductAttributes transformValuesToString];
NSMutableDictionary *transformedEventInfo = [baseProductAttributes transformValuesToString].mutableCopy;
[transformedEventInfo setObject:revenueInCents forKey: @"revenue"]; // Re-set so revenue is not sent as string


[optimizelyClient trackWithEventKey:commerceEventInstruction.event.name userId:userId attributes:currentUser.userAttributes eventTags:transformedEventInfo error:nil];
[execStatus incrementForwardCount];
Expand Down

0 comments on commit 7c52491

Please sign in to comment.