Skip to content

Conversation

@jaissica12
Copy link
Contributor

@jaissica12 jaissica12 commented Nov 25, 2025

Instructions

  1. PR target branch should be against development
  2. PR title name should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-title-check.yml
  3. PR branch prefix should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-branch-check-name.yml

Summary

  • Extended existing product attribute mapping functionality to AddToCart, RemoveFromCart, Checkout and Purchase event.
  • If sendProductNamesasContents is enabled, update content name to array of product names
  • Add related tests

Testing Plan

  • Was this tested locally? If not, explain why.
  • {explain how this has been tested, and what, if any, additional testing should be done}
Screenshot 2025-11-25 at 2 36 16 PM Screenshot 2025-11-25 at 2 36 42 PM Screenshot 2025-11-25 at 2 37 20 PM

Reference Issue (For mParticle employees only. Ignore if you are an outside contributor)

@jaissica12 jaissica12 requested a review from rmi22186 November 25, 2025 21:25
if (contents && contents.length > 0) {
params['contents'] = contents;
}
var contents = buildProductContents(event.ProductAction.ProductList);
Copy link
Collaborator

Choose a reason for hiding this comment

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

var contents is being redeclared here. best to declar it at the top of the file rather than twice at 234/257

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved contents declaration to the top of the logCommerceEvent function (line 171)

Copy link
Collaborator

@rmi22186 rmi22186 left a comment

Choose a reason for hiding this comment

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

just 1 minor comment

@jaissica12 jaissica12 requested a review from rmi22186 November 26, 2025 14:56
Copy link
Collaborator

@rmi22186 rmi22186 left a comment

Choose a reason for hiding this comment

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

There's probably a fair amount of refactoring that can be done to this file given all the if/else. But this is in line with the necessary change that the customer needs and we can do a broader refactor after blackout I'd say. Adding @samdozor for final approval.

@jaissica12 jaissica12 requested a review from rmi22186 December 9, 2025 22:58
Comment on lines 444 to 454
function setProductNamesAsContentName(params, productList) {
if (productList) {
params['content_name'] = productList
.filter(function(product) {
return product && product.Name;
})
.map(function(product) {
return product.Name;
});
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a cleaner approach would be to have the function just return the content_name value, and you can just assign it to the params. This way it's not mutating one of the arguments.

For example, the invocation becomes:

params['content_name'] = setProductNamesAsContentName(event.ProductAction.ProductList);

Suggested change
function setProductNamesAsContentName(params, productList) {
if (productList) {
params['content_name'] = productList
.filter(function(product) {
return product && product.Name;
})
.map(function(product) {
return product.Name;
});
}
}
function setProductNamesAsContentName(productList) {
if (productList) {
return productList
.filter(function(product) {
return product && product.Name;
})
.map(function(product) {
return product.Name;
});
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexs-mparticle Thanks for the feedback! I’ve updated the return type as suggested. Refactored the logic for setting content_name: instead of assigning the result directly, we now call buildProductNames(event.ProductAction.ProductList) and only set params['content_name'] if the returned array is non-empty, similar to how params['contents'] is handled.

For consistency, I removed the helper function setOrderId and moved the order_id assignment inline next to the other parameter assignments

Comment on lines 224 to 239
if (sendProductNamesAsContents) {
productNames = buildProductNames(event.ProductAction.ProductList);
if (productNames && productNames.length > 0) {
params['content_name'] = productNames;
}
}

if (event.ProductAction.TransactionId) {
params['order_id'] = event.ProductAction.TransactionId;
}

// Build contents array for AddToCart events
contents = buildProductContents(event.ProductAction.ProductList);
if (contents && contents.length > 0) {
params['contents'] = contents;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

From a product (and code simplification/maintainability) perspective, I think that these new settings should support all of the commerce events types.

The reason being - we have one customer who wants this to be in a few commerce types because those are the only ones they currently use. But if another customer does use a separate commerce event type, they would expect the settings selected in the UI to apply to all commerce event types, not just a few.

So let's move logic related to sendProductNamesAsContents and order_id to above and outside of when we do specific commerce event typ elogic. (I'd say line 192.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, that makes sense. I’ve moved the logic for sendProductNamesAsContents and order_id so that it runs before any event-type-specific commerce logic.

@jaissica12 jaissica12 requested a review from rmi22186 December 11, 2025 15:20
Comment on lines 289 to 292
// Build contents array for RemoveFromCart events
contents = buildProductContents(event.ProductAction.ProductList);
if (contents && contents.length > 0) {
params['contents'] = contents;
Copy link
Collaborator

Choose a reason for hiding this comment

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

similar to the feedback I gave before, I think we should simplify this further and have the buildProductContents be top level so it applies to every commerce event type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

@jaissica12 jaissica12 requested a review from rmi22186 December 11, 2025 20:49
@rmi22186 rmi22186 changed the title feat: extend Product Attribute Mapping functionality to AddToCart and Checkout feat: Extend product attribute mapping, sendProductNamesAsContents, and order_id to all ecommerce events Dec 11, 2025
@rmi22186 rmi22186 changed the title feat: Extend product attribute mapping, sendProductNamesAsContents, and order_id to all ecommerce events feat: Extend product attribute mapping/ord_id to all ecommerce; support sendProductNamesAsContents Dec 11, 2025
@jaissica12 jaissica12 closed this Dec 12, 2025
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.

4 participants