Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Sources/mParticle-Appboy/MPKitAppboy.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
static NSString *const emailIdTypeKey = @"emailIdentificationType";
static NSString *const enableTypeDetectionKey = @"enableTypeDetection";
static NSString *const bundleCommerceEventData = @"bundleCommerceEventData";
static NSString *const replaceSkuAsProductName = @"forwardSkuAsProductName";

// The possible values for userIdentificationType
static NSString *const userIdValueOther = @"Other";
Expand Down Expand Up @@ -550,11 +551,16 @@ - (MPKitExecStatus *)routeCommerceEvent:(MPCommerceEvent *)commerceEvent {
[properties addEntriesFromDictionary:productDictionary];
}

NSString *sanitizedProductName = product.sku;
if ([@"True" isEqualToString:_configuration[replaceSkuAsProductName]]) {
sanitizedProductName = product.name;
}

// Strips key/values already being passed to Appboy, plus key/values initialized to default values
keys = @[kMPExpProductSKU, kMPProductCurrency, kMPExpProductUnitPrice, kMPExpProductQuantity];
[properties removeObjectsForKeys:keys];

[appboyInstance logPurchase:product.sku
[appboyInstance logPurchase:sanitizedProductName
currency:currency
price:[product.price doubleValue]
quantity:[product.quantity integerValue]
Expand Down
48 changes: 48 additions & 0 deletions mParticle_AppboyTests/mParticle_AppboyTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,54 @@ - (void)testlogPurchaseCommerceEvent {
[mockClient stopMocking];
}

- (void)testlogPurchaseCommerceEventSendingProductName {
MPKitAppboy *kit = [[MPKitAppboy alloc] init];
kit.configuration = @{@"bundleCommerceEventData" : @0,
@"forwardSkuAsProductName": @"True"};

BRZConfiguration *configuration = [[BRZConfiguration alloc] init];
Braze *testClient = [[Braze alloc] initWithConfiguration:configuration];
id mockClient = OCMPartialMock(testClient);
[kit setAppboyInstance:mockClient];

XCTAssertEqualObjects(mockClient, [kit appboyInstance]);

MPProduct *product = [[MPProduct alloc] initWithName:@"product1" sku:@"1131331343" quantity:@1 price:@13];
product.category = @"category1";

MPCommerceEvent *event = [[MPCommerceEvent alloc] initWithAction:MPCommerceEventActionPurchase product:product];
event.customAttributes = @{@"testKey" : @"testCustomAttValue"};

MPTransactionAttributes *attributes = [[MPTransactionAttributes alloc] init];
attributes.transactionId = @"foo-transaction-id";
attributes.revenue = @13.00;
attributes.tax = @3;
attributes.shipping = @3;

event.transactionAttributes = attributes;

[[mockClient expect] logPurchase:@"product1"
currency:@"USD"
price:[@"13" doubleValue]
quantity:1
properties:@{@"Shipping Amount" : @3,
@"Total Amount" : @13.00,
@"Total Product Amount" : @"13",
@"Tax Amount" : @3,
@"Transaction Id" : @"foo-transaction-id",
@"Name" : @"product1",
@"Category" : @"category1"
}];

MPKitExecStatus *execStatus = [kit logBaseEvent:event];

XCTAssertEqual(execStatus.returnCode, MPKitReturnCodeSuccess);

[mockClient verify];

[mockClient stopMocking];
}

- (void)testlogPurchaseCommerceEventWithBundledProducts {
MPKitAppboy *kit = [[MPKitAppboy alloc] init];
kit.configuration = @{@"bundleCommerceEventData" : @1};
Expand Down