Skip to content
Open
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
33 changes: 29 additions & 4 deletions ios/RNMParticle/RNMParticle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ @interface MParticleUser ()
- (void)setUserId:(NSNumber *)userId;
@end

// Forward declare so New Arch `logCommerceEvent` can use the same JS→native
// mappings as `RCTConvert (MPCommerceEvent)` (defined later in this file).
@interface RCTConvert (MPCommerceEvent)
+ (MPCommerceEventAction)MPCommerceEventAction:(id)json;
+ (MPPromotionAction)MPPromotionAction:(id)json;
@end

@implementation RNMParticle

RCT_EXTERN void RCTRegisterModule(Class);
Expand Down Expand Up @@ -447,11 +454,14 @@ - (void)logCommerceEvent:(JS::NativeMParticle::CommerceEvent &)commerceEvent {
MPCommerceEvent *mpCommerceEvent = [[MPCommerceEvent alloc] init];

if (commerceEvent.productActionType().has_value()) {
mpCommerceEvent.action = (MPCommerceEventAction)commerceEvent.productActionType().value();
mpCommerceEvent.action = [RCTConvert MPCommerceEventAction:@(commerceEvent.productActionType().value())];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves for the product action but looks like we'll have the same issue with the promotion actions? Looks like view and click would get the wrong index too?

Could you cast a wider net to see if there's anything more widespread here please?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to fix the PromotionActionType as well. On JS side 0 means View. But on the Objective-C side it is Click

}

if (commerceEvent.promotionActionType().has_value()) {
mpCommerceEvent.promotionContainer = [[MPPromotionContainer alloc] initWithAction:(MPPromotionAction)commerceEvent.promotionActionType().value() promotion:nil];
MPPromotionAction promotionAction =
[RCTConvert MPPromotionAction:@(commerceEvent.promotionActionType().value())];
mpCommerceEvent.promotionContainer =
[[MPPromotionContainer alloc] initWithAction:promotionAction promotion:nil];
}

if (commerceEvent.products().has_value()) {
Expand Down Expand Up @@ -778,7 +788,7 @@ + (MPCommerceEvent *)MPCommerceEvent:(NSDictionary *)dict {
MPCommerceEvent *commerceEvent = [[MPCommerceEvent alloc] init];

if (dict[@"productActionType"] && dict[@"productActionType"] != [NSNull null]) {
commerceEvent.action = (MPCommerceEventAction)[dict[@"productActionType"] integerValue];
commerceEvent.action = [RCTConvert MPCommerceEventAction:dict[@"productActionType"]];
}

if (dict[@"products"] && dict[@"products"] != [NSNull null]) {
Expand Down Expand Up @@ -920,6 +930,7 @@ + (MPPromotion *)MPPromotion:(id)json;
+ (MPTransactionAttributes *)MPTransactionAttributes:(id)json;
+ (MPProduct *)MPProduct:(id)json;
+ (MPCommerceEventAction)MPCommerceEventAction:(id)json;
+ (MPPromotionAction)MPPromotionAction:(id)json;
+ (MPIdentityApiRequest *)MPIdentityApiRequest:(id)json;
+ (MPIdentityApiResult *)MPIdentityApiResult:(id)json;
+ (MPAliasRequest *)MPAliasRequest:(id)json;
Expand Down Expand Up @@ -989,7 +1000,7 @@ + (MPCommerceEvent *)MPCommerceEvent:(id)json {
}

+ (MPPromotionContainer *)MPPromotionContainer:(id)json {
MPPromotionAction promotionAction = (MPPromotionAction)[json[@"promotionActionType"] intValue];
MPPromotionAction promotionAction = [RCTConvert MPPromotionAction:json[@"promotionActionType"]];
MPPromotionContainer *promotionContainer = [[MPPromotionContainer alloc] initWithAction:promotionAction promotion:nil];
NSArray *jsonPromotions = json[@"promotions"];
[jsonPromotions enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
Expand Down Expand Up @@ -1039,6 +1050,20 @@ + (MPProduct *)MPProduct:(id)json {
return product;
}

+ (MPPromotionAction)MPPromotionAction:(NSNumber *)json {
// JS `PromotionActionType`: View = 0, Click = 1 (js/index.tsx).
// Apple `MPPromotionAction`: Click = 0, View = 1 (MPPromotion.h).
switch ([json intValue]) {
case 0:
return MPPromotionActionView;
case 1:
return MPPromotionActionClick;
default:
// Match Android `convertPromotionActionType`: non-zero → Click
return MPPromotionActionClick;
}
}

+ (MPCommerceEventAction)MPCommerceEventAction:(NSNumber *)json {
int actionInt = [json intValue];
MPCommerceEventAction action;
Expand Down
Loading