Skip to content
Open
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
31 changes: 31 additions & 0 deletions ios/RNMParticle/RNMParticle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,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();
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];

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.

If mpCommerceEvent never gets an addImpression this could leave an odd state but it seems unlikely

}
}
}
}

if (commerceEvent.transactionAttributes().has_value()) {
// Create transaction attributes from the struct
auto transactionAttrs = commerceEvent.transactionAttributes().value();
Expand Down
Loading