feat: expose device-based consent APIs in React Native bridge#351
Conversation
Bridge setDeviceConsentState, clearDeviceConsentState, and getDeviceConsentState to native device consent on iOS and Android.
PR SummaryMedium Risk Overview Introduces a Consent timestamp handling is tightened on both platforms—Android accepts number or string millis via Reviewed by Cursor Bugbot for commit ab85cc1. Bugbot is set up for automated code reviews on this repo. Configure here. |
Re-export DeviceConsentState from NativeMParticle codegen so getDeviceConsentState callback matches the TurboModule signature.
Device consent RCT_EXPORT_METHODs call MPConsentState: before the RCTConvert category is defined later in the file.
- Move old-arch RCT_EXPORT_METHODs into #else block to avoid duplicate declarations when New Architecture is enabled. - Move consentStateToDictionary onto RNMParticle (was wrongly on RCTConvert). - Use NSDictionary codegen types for new-arch setDeviceConsentState.
Use NSNull in getDeviceConsentState callback when consentStateToDictionary returns nil for an empty MPConsentState.
When gdpr is null or not a map, continue processing ccpa instead of returning null from convertToConsentState.
MPConsentState and RCT_EXPORT consent paths use MPGDPRConsent/ MPCCPAConsent converters that treated JS timestamps as seconds via RCTConvert NSDate. Divide by 1000 to match Date.now() and read path.
Assign nil/null when the converted consent state has no GDPR or CCPA entries, matching clearDeviceConsentState behavior.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a30b9e8. Configure here.
Read consent timestamps as Number or String on Android so getDeviceConsentState round-trips correctly. Guard iOS MPConsentState conversion against non-dictionary GDPR/CCPA values. Fix new arch setDeviceConsentState by converting codegen structs to NSDictionary before RCTConvert.
Codegen exposes DeviceConsentState.gdpr() as id, not std::optional, so setDeviceConsentState must not call has_value/value on it.

Add device-level consent state to React Native bridge
Summary
Exposes device-level consent APIs in the React Native wrapper so apps can set, read, and clear device-scoped consent from JavaScript. Native device consent (added in mParticle Apple SDK and android-core) supersedes per-user/MPID consent when set — consent collected before login or across identity changes at checkout is retained on the device.
Bridges to:
MParticle.sharedInstance().deviceConsentState(requires mParticle Apple SDK 9.2+ with device consent)MParticle.getInstance().setDeviceConsentState()/getDeviceConsentState()(requires android-core release with device consent APIs; resolves via[5.79.2, 6.0))What has changed
setDeviceConsentState,clearDeviceConsentState, andgetDeviceConsentStateto the JS API and default exportMParticleModule, and iOSRNMParticle(old arch + new arch)RCTConvert MPConsentState:andconsentStateToDictionary:on iOSSample code
Testing
./gradlew testand./gradlew ktlintCheckpass on the Android moduleChecklist
Related Android PR: mParticle/mparticle-android-sdk#726
Related iOS PR: mParticle/mparticle-apple-sdk#784 (merged)