-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Extend product attribute mapping/ord_id to all ecommerce; support sendProductNamesAsContents #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/FacebookEventForwarder.js
Outdated
| if (contents && contents.length > 0) { | ||
| params['contents'] = contents; | ||
| } | ||
| var contents = buildProductContents(event.ProductAction.ProductList); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
rmi22186
left a comment
There was a problem hiding this 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
There was a problem hiding this 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.
src/FacebookEventForwarder.js
Outdated
| function setProductNamesAsContentName(params, productList) { | ||
| if (productList) { | ||
| params['content_name'] = productList | ||
| .filter(function(product) { | ||
| return product && product.Name; | ||
| }) | ||
| .map(function(product) { | ||
| return product.Name; | ||
| }); | ||
| } | ||
| } |
There was a problem hiding this comment.
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);
| 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; | |
| }); | |
| } | |
| } |
There was a problem hiding this comment.
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
src/FacebookEventForwarder.js
Outdated
| 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; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/FacebookEventForwarder.js
Outdated
| // Build contents array for RemoveFromCart events | ||
| contents = buildProductContents(event.ProductAction.ProductList); | ||
| if (contents && contents.length > 0) { | ||
| params['contents'] = contents; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
ea40320 to
9cf4a60
Compare
Instructions
developmentSummary
sendProductNamesasContentsis enabled, update content name to array of product namesTesting Plan
Reference Issue (For mParticle employees only. Ignore if you are an outside contributor)