Skip to content
Closed
Show file tree
Hide file tree
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: 32 additions & 1 deletion ios/RNMParticle/RNMParticle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ - (void)logCommerceEvent:(JS::NativeMParticle::CommerceEvent &)commerceEvent {
NSMutableDictionary *productDict = [[NSMutableDictionary alloc] init];
if (productStruct.name()) productDict[@"name"] = productStruct.name();
if (productStruct.sku()) productDict[@"sku"] = productStruct.sku();
productDict[@"price"] = @(productStruct.price());
if (productStruct.price()) productDict[@"price"] = @(productStruct.price());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Zero price silently drops products

Medium Severity

price is a required non-optional number on Product, unlike optional fields that use .has_value(). Guarding with if (productStruct.price()) treats 0 as absent, so the key is omitted and createMPProductFromDict returns nil. Free products are then dropped from commerce events and impressions.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e264e8d. Configure here.

if (productStruct.quantity().has_value()) productDict[@"quantity"] = @(productStruct.quantity().value());
if (productStruct.brand()) productDict[@"brand"] = productStruct.brand();
if (productStruct.couponCode()) productDict[@"couponCode"] = productStruct.couponCode();
Expand All @@ -526,6 +526,37 @@ - (void)logCommerceEvent:(JS::NativeMParticle::CommerceEvent &)commerceEvent {
}
[mpCommerceEvent addProducts:productsArray];
}

if (commerceEvent.impressions().has_value()) {
auto impressionsVector = commerceEvent.impressions().value();
for (size_t j = 0; j < impressionsVector.size(); j++) {
auto impressionStruct = impressionsVector[j];
NSString *listName = impressionStruct.impressionListName();
if (!listName) {
continue;
}
auto productsInImpression = impressionStruct.products();
for (size_t k = 0; k < productsInImpression.size(); k++) {
auto productStruct = productsInImpression[k];
NSMutableDictionary *productDict = [[NSMutableDictionary alloc] init];
if (productStruct.name()) productDict[@"name"] = productStruct.name();
if (productStruct.sku()) productDict[@"sku"] = productStruct.sku();
if (productStruct.price()) productDict[@"price"] = @(productStruct.price());
if (productStruct.quantity().has_value()) productDict[@"quantity"] = @(productStruct.quantity().value());
if (productStruct.brand()) productDict[@"brand"] = productStruct.brand();
if (productStruct.couponCode()) productDict[@"couponCode"] = productStruct.couponCode();
if (productStruct.position().has_value()) productDict[@"position"] = @(productStruct.position().value());
if (productStruct.category()) productDict[@"category"] = productStruct.category();
if (productStruct.variant()) productDict[@"variant"] = productStruct.variant();
if (productStruct.customAttributes()) productDict[@"customAttributes"] = productStruct.customAttributes();

MPProduct *product = [self createMPProductFromDict:productDict];
if (product) {
[mpCommerceEvent addImpression:product listName:listName];
}
}
}
}

if (commerceEvent.transactionAttributes().has_value()) {
// Create transaction attributes from the struct
Expand Down
3 changes: 2 additions & 1 deletion react-native-mparticle.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Pod::Spec.new do |s|
s.dependency "React-Core"
end

s.dependency 'mParticle-Apple-SDK-ObjC', '~> 9.2'
# deviceConsentState exists on Apple SDK 9.2.2+ (not 9.2.0/9.2.1).
s.dependency 'mParticle-Apple-SDK-ObjC', '>= 9.2.2', '< 10.0'
s.dependency 'RoktContracts', '~> 2.0'
end
4 changes: 2 additions & 2 deletions sample/ios/MParticleSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

/* Begin PBXBuildFile section */
00E356F31AD99517003FC87E /* MParticleSampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* MParticleSampleTests.m */; };
B7C10E912E50AA1100000002 /* RCTConvertCommerceMappingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B7C10E902E50AA1100000001 /* RCTConvertCommerceMappingTests.m */; };
0C80B921A6F3F58F76C31292 /* libPods-MParticleSample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DCACB8F33CDC322A6C60F78 /* libPods-MParticleSample.a */; };
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
4B55574964776A1532DBA98C /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */; };
7699B88040F8A987B510C191 /* libPods-MParticleSample-MParticleSampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 19F6CBCC0A4E27FBF8BF4A61 /* libPods-MParticleSample-MParticleSampleTests.a */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
B7C10E912E50AA1100000002 /* RCTConvertCommerceMappingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B7C10E902E50AA1100000001 /* RCTConvertCommerceMappingTests.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -32,7 +32,6 @@
00E356EE1AD99517003FC87E /* MParticleSampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MParticleSampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
00E356F21AD99517003FC87E /* MParticleSampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MParticleSampleTests.m; sourceTree = "<group>"; };
B7C10E902E50AA1100000001 /* RCTConvertCommerceMappingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTConvertCommerceMappingTests.m; sourceTree = "<group>"; };
13B07F961A680F5B00A75B9A /* MParticleSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MParticleSample.app; sourceTree = BUILT_PRODUCTS_DIR; };
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = MParticleSample/AppDelegate.h; sourceTree = "<group>"; };
13B07FB01A68108700A75B9A /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = MParticleSample/AppDelegate.mm; sourceTree = "<group>"; };
Expand All @@ -47,6 +46,7 @@
5DCACB8F33CDC322A6C60F78 /* libPods-MParticleSample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MParticleSample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = MParticleSample/LaunchScreen.storyboard; sourceTree = "<group>"; };
89C6BE57DB24E9ADA2F236DE /* Pods-MParticleSample-MParticleSampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MParticleSample-MParticleSampleTests.release.xcconfig"; path = "Target Support Files/Pods-MParticleSample-MParticleSampleTests/Pods-MParticleSample-MParticleSampleTests.release.xcconfig"; sourceTree = "<group>"; };
B7C10E902E50AA1100000001 /* RCTConvertCommerceMappingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTConvertCommerceMappingTests.m; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

Expand Down
3 changes: 3 additions & 0 deletions sample/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ target 'MParticleSample' do
:app_path => "#{Pod::Config.instance.installation_root}/.."
)
pod 'mParticle-Rokt', '~> 9.2'
# deviceConsentState is on Apple SDK 9.2.2+; without this floor, CocoaPods can
# resolve 9.2.1 and the RN bridge fails to compile.
pod 'mParticle-Apple-SDK-ObjC', '>= 9.2.2', '< 10.0'
# Exact Rokt-Widget keeps RoktUXHelper on the same version (Rokt pins them together).
pod 'Rokt-Widget', '5.2.0'
# RoktUXHelper declares `DcuiSchema` `~> 2.6`, which otherwise floats to 2.8.x; that
Expand Down
Loading