Skip to content

fix(android): log commerce events without transaction attributes - #367

Open
thomson-t wants to merge 1 commit into
mainfrom
fix/android-commerce-events-without-transaction-attributes
Open

fix(android): log commerce events without transaction attributes#367
thomson-t wants to merge 1 commit into
mainfrom
fix/android-commerce-events-without-transaction-attributes

Conversation

@thomson-t

Copy link
Copy Markdown
Contributor

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.

  • Always create Android product-action events and conditionally attach transaction attributes.
  • Stop adding a synthetic empty transaction ID from the JavaScript factory.
  • Preserve explicitly supplied transaction attributes.
  • Add regression coverage for AddToCart, Purchase, empty attributes, empty IDs, and multiple products.
  • Update the commerce example to omit transaction attributes for AddToCart.

Testing Plan

  • yarn install --frozen-lockfile
  • yarn test
  • yarn build
  • cd android && ./gradlew test lint ktlintCheck assembleDebug
  • trunk check --ci

Master Issue

Closes #278

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
@thomson-t
thomson-t requested a review from a team as a code owner July 28, 2026 15:48
Copilot AI review requested due to automatic review settings July 28, 2026 15:48
@cursor

cursor Bot commented Jul 28, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Targeted ecommerce bridge and factory behavior with broad regression tests; no auth or data-model changes beyond fixing missing event logging.

Overview
Fixes Android silently dropping product-action commerce events (e.g. AddToCart) when transactionAttributes were omitted. The native bridge now always builds a CommerceEvent and only attaches transaction attributes when conversion succeeds, instead of requiring them to create the builder.

On the JavaScript side, CommerceEvent.createProductActionEvent no longer defaults to an empty TransactionAttributes(''); transaction attributes are optional and are omitted from the payload sent to native when not provided. Explicit attributes (including purchase IDs) are unchanged.

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.

Copilot AI left a comment

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.

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.createProductActionEvent accept optional transactionAttributes and only set them when provided (no synthetic empty transaction ID).
  • Android: always create the product-action CommerceEvent.Builder and conditionally attach converted transaction attributes.
  • Tests/docs: add regression coverage (JS + Android) and update README to show transactionAttributes as 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.

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.

New release may have broken AddToCart commerce events on Android?

2 participants