fix(android): log commerce events without transaction attributes - #367
fix(android): log commerce events without transaction attributes#367thomson-t wants to merge 1 commit into
Conversation
Always build Android product-action events before optionally attaching transaction attributes, so AddToCart and similar events are not silently dropped. Omit the JavaScript factory synthetic empty transaction ID and add cross-layer regression coverage for omitted and explicit attributes. #agentic
PR SummaryLow Risk Overview On the JavaScript side, README commerce examples and notes were updated to match. Regression tests cover Android conversion and JS normalization for missing, empty, and valid transaction attributes. Reviewed by Cursor Bugbot for commit a38ed8b. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Pull request overview
This PR fixes an Android-specific regression where product-action commerce events (e.g., AddToCart) could be silently dropped when transactionAttributes were omitted, by ensuring the native Android CommerceEvent.Builder is always created and transaction attributes are only attached when present. It also updates the JS factory to stop synthesizing an empty transaction ID, adds regression tests across JS and Android, and updates the README example accordingly.
Changes:
- JavaScript: make
CommerceEvent.createProductActionEventaccept optionaltransactionAttributesand only set them when provided (no synthetic empty transaction ID). - Android: always create the product-action
CommerceEvent.Builderand conditionally attach converted transaction attributes. - Tests/docs: add regression coverage (JS + Android) and update README to show
transactionAttributesas optional for AddToCart.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Updates commerce event example and clarifies when transaction attributes are required vs optional. |
| js/index.tsx | Makes product-action event factory not inject default TransactionAttributes(''); attaches only when supplied. |
| js/tests/attribute-normalization.test.ts | Adds JS regression tests ensuring omitted vs explicitly supplied transaction attributes are preserved correctly. |
| android/src/test/java/com/mparticle/react/MParticleModuleTest.java | Adds Android-side regression tests for product actions with/without transaction attributes and multiple products. |
| android/src/main/java/com/mparticle/react/MParticleModule.kt | Fixes Android commerce event conversion to always build product-action events and conditionally apply transaction attributes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Android silently dropped product-action commerce events when transaction attributes were omitted because the native builder was only created after successful transaction-attribute conversion.
Testing Plan
yarn install --frozen-lockfileyarn testyarn buildcd android && ./gradlew test lint ktlintCheck assembleDebugtrunk check --ciMaster Issue
Closes #278