Skip to content

Commit 8bba459

Browse files
feat: Add sendProductName Option to Braze
1 parent 23f703d commit 8bba459

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

Sources/mParticle-Appboy/MPKitAppboy.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
static NSString *const emailIdTypeKey = @"emailIdentificationType";
1717
static NSString *const enableTypeDetectionKey = @"enableTypeDetection";
1818
static NSString *const bundleCommerceEventData = @"bundleCommerceEventData";
19+
static NSString *const replaceSkuAsProductName = @"forwardSkuAsProductName";
1920

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

554+
NSString *sanitizedProductName = product.sku;
555+
if ([@"True" isEqualToString:_configuration[replaceSkuAsProductName]]) {
556+
sanitizedProductName = product.name;
557+
}
558+
553559
// Strips key/values already being passed to Appboy, plus key/values initialized to default values
554560
keys = @[kMPExpProductSKU, kMPProductCurrency, kMPExpProductUnitPrice, kMPExpProductQuantity];
555561
[properties removeObjectsForKeys:keys];
556562

557-
[appboyInstance logPurchase:product.sku
563+
[appboyInstance logPurchase:sanitizedProductName
558564
currency:currency
559565
price:[product.price doubleValue]
560566
quantity:[product.quantity integerValue]

mParticle_AppboyTests/mParticle_AppboyTests.m

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,54 @@ - (void)testlogPurchaseCommerceEvent {
579579
[mockClient stopMocking];
580580
}
581581

582+
- (void)testlogPurchaseCommerceEventSendingProductName {
583+
MPKitAppboy *kit = [[MPKitAppboy alloc] init];
584+
kit.configuration = @{@"bundleCommerceEventData" : @0,
585+
@"forwardSkuAsProductName": @"True"};
586+
587+
BRZConfiguration *configuration = [[BRZConfiguration alloc] init];
588+
Braze *testClient = [[Braze alloc] initWithConfiguration:configuration];
589+
id mockClient = OCMPartialMock(testClient);
590+
[kit setAppboyInstance:mockClient];
591+
592+
XCTAssertEqualObjects(mockClient, [kit appboyInstance]);
593+
594+
MPProduct *product = [[MPProduct alloc] initWithName:@"product1" sku:@"1131331343" quantity:@1 price:@13];
595+
product.category = @"category1";
596+
597+
MPCommerceEvent *event = [[MPCommerceEvent alloc] initWithAction:MPCommerceEventActionPurchase product:product];
598+
event.customAttributes = @{@"testKey" : @"testCustomAttValue"};
599+
600+
MPTransactionAttributes *attributes = [[MPTransactionAttributes alloc] init];
601+
attributes.transactionId = @"foo-transaction-id";
602+
attributes.revenue = @13.00;
603+
attributes.tax = @3;
604+
attributes.shipping = @3;
605+
606+
event.transactionAttributes = attributes;
607+
608+
[[mockClient expect] logPurchase:@"product1"
609+
currency:@"USD"
610+
price:[@"13" doubleValue]
611+
quantity:1
612+
properties:@{@"Shipping Amount" : @3,
613+
@"Total Amount" : @13.00,
614+
@"Total Product Amount" : @"13",
615+
@"Tax Amount" : @3,
616+
@"Transaction Id" : @"foo-transaction-id",
617+
@"Name" : @"product1",
618+
@"Category" : @"category1"
619+
}];
620+
621+
MPKitExecStatus *execStatus = [kit logBaseEvent:event];
622+
623+
XCTAssertEqual(execStatus.returnCode, MPKitReturnCodeSuccess);
624+
625+
[mockClient verify];
626+
627+
[mockClient stopMocking];
628+
}
629+
582630
- (void)testlogPurchaseCommerceEventWithBundledProducts {
583631
MPKitAppboy *kit = [[MPKitAppboy alloc] init];
584632
kit.configuration = @{@"bundleCommerceEventData" : @1};

0 commit comments

Comments
 (0)