Skip to content

feat: Java enum for MPCommerceEventActionType was base 1#336

Open
BrandonStalnaker wants to merge 1 commit into
mainfrom
fix/TRIAGE-719-Java-Enum-is-Base-1-unlike-iOS
Open

feat: Java enum for MPCommerceEventActionType was base 1#336
BrandonStalnaker wants to merge 1 commit into
mainfrom
fix/TRIAGE-719-Java-Enum-is-Base-1-unlike-iOS

Conversation

@BrandonStalnaker
Copy link
Copy Markdown
Contributor

Summary

On iOS with the New Architecture (RCT_NEW_ARCH_ENABLED), logCommerceEvent set MPCommerceEvent.action by casting the TurboModule / codegen number straight to MPCommerceEventAction. That number is the JavaScript ProductActionType (1-based MPReactCommerceEventAction: AddToCart = 1, …), which does not match the Apple SDK’s native enum raw values or ordering. The result was wrong commerce actions (e.g. AddToCart → remove_from_cart, and generally scrambled types including wishlist vs checkout).

The legacy bridge path already fixed this by routing productActionType through [RCTConvert MPCommerceEventAction:], which maps each JS constant to the correct MPCommerceEventAction.

This PR aligns the New Architecture path with that behavior by:

  • Using [RCTConvert MPCommerceEventAction:@(productActionType)] in the New Arch logCommerceEvent implementation instead of a direct cast.
  • Adding a forward declaration for + [RCTConvert MPCommerceEventAction:] near the top of RNMParticle.mm so the call is valid before the RCTConvert (MPCommerceEvent) category implementation later in the file.
  • Updating RCTConvert (MParticle) + MPCommerceEvent: (dictionary-based helper) to set commerceEvent.action via MPCommerceEventAction: as well, instead of casting the integer directly—same bug class if that code path is used.
    Android is unchanged (already maps JS ints explicitly in Kotlin). Promotion action types were not part of this issue (JS 0/1 matches existing native usage).

Master Issue

Closes https://go.mparticle.com/work/TRIAGE-719

@BrandonStalnaker BrandonStalnaker self-assigned this Jun 4, 2026
@BrandonStalnaker BrandonStalnaker requested a review from a team as a code owner June 4, 2026 20:32
@cursor
Copy link
Copy Markdown

cursor Bot commented Jun 4, 2026

PR Summary

Medium Risk
Changes how commerce events are encoded before upload; incorrect mapping previously sent wrong actions (e.g. add-to-cart as remove), so this fix affects analytics accuracy for iOS New Arch users.

Overview
Fixes incorrect commerce product actions on iOS when React Native’s New Architecture is enabled. logCommerceEvent no longer casts the JS productActionType integer straight to MPCommerceEventAction; it now uses [RCTConvert MPCommerceEventAction:], matching the legacy bridge and mapping 1-based JS constants to the Apple SDK enum.

The dictionary-based RCTConvert (MParticle) +MPCommerceEvent: path is updated the same way. A forward declaration for MPCommerceEventAction: was added near the top of RNMParticle.mm so the New Arch method can call the converter defined later in the file.

Reviewed by Cursor Bugbot for commit 2a8ebda. Bugbot is set up for automated code reviews on this repo. Configure here.


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

@jamesnrokt
Copy link
Copy Markdown
Contributor

Also wondering if there's any tests we can be adding here as a regression on this type of error can easily occur

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants