Repository navigation
feat(snapchat_conversion): add products to contents mapping - #4526
Conversation
Summary by CodeRabbit
WalkthroughAdds a productsToContentsMapping utility, exports it, and integrates it into Snapchat v3 transform to populate payload.data[0].custom_data.contents from message.properties.products when present; also adds unit tests covering mapping behavior and edge cases. Changes
Sequence Diagram(s)sequenceDiagram
participant Msg as Message
participant Transformer as buildBasePayload
participant Utils as productsToContentsMapping
participant Payload as payload.data[0].custom_data
Msg->>Transformer: event with products
Transformer->>Utils: productsToContentsMapping(message)
Utils-->>Transformer: contents array (may be [])
alt contents non-empty
Transformer->>Payload: set contents = contents
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: .coderabbit.yaml 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (1)**/*.js⚙️ CodeRabbit Configuration File
Files:
🧠 Learnings (1)📚 Learning: 2025-05-29T13:29:39.436ZApplied to files:
🧬 Code Graph Analysis (2)src/v0/destinations/snapchat_conversion/utilsV3.js (1)
src/v0/destinations/snapchat_conversion/utilsV3.test.js (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
🔇 Additional comments (4)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
|
Allure Test reports for this run are available at:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4526 +/- ##
===========================================
+ Coverage 91.79% 91.81% +0.01%
===========================================
Files 642 642
Lines 33889 33939 +50
Branches 8028 8044 +16
===========================================
+ Hits 31110 31160 +50
Misses 2527 2527
Partials 252 252 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
e7e2355 to
ec64d03
Compare
|
Allure Test reports for this run are available at:
|
There was a problem hiding this comment.
Actionable comments posted: 4
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between ec64d03518775c3881d70a1e8646f2928df8a0eb and 1a50593f1c8a33cf33d1bb1874e1633e0f65204c.
📒 Files selected for processing (3)
src/v0/destinations/snapchat_conversion/transformV3.js(2 hunks)src/v0/destinations/snapchat_conversion/utilsV3.js(2 hunks)src/v0/destinations/snapchat_conversion/utilsV3.test.js(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- src/v0/destinations/snapchat_conversion/utilsV3.js
- src/v0/destinations/snapchat_conversion/transformV3.js
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js
⚙️ CodeRabbit Configuration File
Focus on ESLint errors (max 3) and warnings (max 5).
Files:
src/v0/destinations/snapchat_conversion/utilsV3.test.js
🧬 Code Graph Analysis (1)
src/v0/destinations/snapchat_conversion/utilsV3.test.js (1)
src/v0/destinations/snapchat_conversion/utilsV3.js (5)
require(1-1)require(2-2)require(4-4)require(5-5)productsToContentsMapping(134-158)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Code Coverage
- GitHub Check: test_and_publish
- GitHub Check: UT Tests
- GitHub Check: Analyze (go)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
src/v0/destinations/snapchat_conversion/utilsV3.test.js (2)
1-1: Add Jest env hint to avoid ESLint no-undef on globals.If your ESLint configuration doesn't already set the Jest environment for test files,
describe,it, andexpectwill be flagged as undefined. Add the env directive at the top.+/* eslint-env jest */ const { productsToContentsMapping } = require('./utilsV3');
16-30: Good coverage for happy-path mapping (product_id + delivery_category).This case correctly asserts field names, value mapping, and sanitization expectations. Nice.
|
Allure Test reports for this run are available at:
|
2 similar comments
|
Allure Test reports for this run are available at:
|
|
Allure Test reports for this run are available at:
|
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/v0/destinations/snapchat_conversion/utilsV3.js (1)
142-144: Consider fallback mapping when products array is absent (pre-discussed); keeps VIEW_CONTENT and similar events coveredThis mirrors an earlier review discussion about using root-level properties when properties.products is missing. If acceptable for scope, here’s a minimal, consistent fallback that still sanitizes and validates id.
- if (!Array.isArray(products) || products.length === 0) { - return []; - } + if (!Array.isArray(products) || products.length === 0) { + // Fallback to root-level properties when `products` is absent (e.g., Product Viewed) + const idCandidate = [get(message, 'properties.product_id'), get(message, 'properties.sku'), get(message, 'properties.id')].find( + (v) => v !== undefined && v !== null && String(v).trim() !== '', + ); + const rootContent = removeUndefinedAndNullValues({ + id: idCandidate, + item_price: get(message, 'properties.price'), + quantity: get(message, 'properties.quantity'), + delivery_category: get(message, 'properties.delivery_category'), + }); + if ( + isEmptyObject(rootContent) || + rootContent.id === undefined || + rootContent.id === null || + String(rootContent.id).trim() === '' + ) { + return []; + } + return [rootContent]; + }If this is intentionally out of scope for this PR, feel free to defer; otherwise, it improves coverage for events like VIEW_CONTENT.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 76c20b0a7f47352a13bb6a360e4fd7997a48c7c9 and 4f0d8c24052b97aa8b8131efe0909ce86040283a.
📒 Files selected for processing (2)
src/v0/destinations/snapchat_conversion/utilsV3.js(2 hunks)src/v0/destinations/snapchat_conversion/utilsV3.test.js(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/v0/destinations/snapchat_conversion/utilsV3.test.js
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js
⚙️ CodeRabbit Configuration File
Focus on ESLint errors (max 3) and warnings (max 5).
Files:
src/v0/destinations/snapchat_conversion/utilsV3.js
🧠 Learnings (1)
📚 Learning: 2025-05-29T13:29:39.436Z
Learnt from: maheshkutty
PR: rudderlabs/rudder-transformer#4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The `combineBatchRequestsWithSameJobIds` function in `src/v0/util/index.js` is used by both Mixpanel and Google AdWords Offline Conversions destinations in production. The function assumes metadata is always an array in multiple operations (forEach, filter, sort, map) and needs defensive programming to handle non-array metadata cases to prevent runtime errors.
Applied to files:
src/v0/destinations/snapchat_conversion/utilsV3.js
🧬 Code Graph Analysis (1)
src/v0/destinations/snapchat_conversion/utilsV3.js (3)
src/v0/destinations/snapchat_conversion/utilsV3.test.js (1)
require(1-1)src/v0/destinations/snapchat_conversion/transform.js (4)
require(2-2)require(3-3)require(5-15)get(1-1)src/v0/util/index.js (1)
removeUndefinedAndNullValues(55-55)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Code Coverage
- GitHub Check: test_and_publish
- GitHub Check: UT Tests
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (2)
src/v0/destinations/snapchat_conversion/utilsV3.js (2)
5-10: Imports expansion looks goodThe additional util imports are all used within this module (getExtInfo and productsToContentsMapping) and keep concerns local. No unused-import linting concerns.
169-170: No issues with the new export—imports and usage are correct–
transformV3.jsproperly destructures and callsproductsToContentsMapping
–utilsV3.test.jsalready covers the function via its test suiteAll downstream references are in place; no further action required.
4f0d8c2 to
f13f0de
Compare
|
Allure Test reports for this run are available at:
|
|
Allure Test reports for this run are available at:
|
|



What are the changes introduced in this PR?
This pull request enhances the Snapchat Conversion destination integration by introducing a new utility function to standardize product-to-contents mapping and updating the transformation logic and tests to support this feature. The main goal is to ensure the
contentsfield in outgoing payloads is consistently populated based on product data, improving downstream analytics and event tracking.Transformation logic improvements:
productsToContentsMappingutility function toutilsV3.js, which extracts and normalizes product information from incoming messages to generate a standardizedcontentsarray for Snapchat payloads. This function handles various edge cases, such as missing or malformed product data, and ensures only valid content objects are included.transformV3.jsto use the newproductsToContentsMappingfunction within the payload builder, ensuring thecontentsfield is added to outgoing payloads when applicable. [1] [2]Testing and validation:
productsToContentsMappingfunction inutilsV3.test.js, covering a wide range of input scenarios and edge cases to guarantee correct behavior.dataV3.tsto include the newcontentsfield in expected outputs, ensuring integration tests validate the correct population of product details for all relevant event types. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17]Utility enhancements:
utilmodule inutilsV3.jsto leverage helper functions for object validation and cleanup, supporting the new mapping logic.These changes collectively improve the reliability and consistency of product data handling for Snapchat Conversion events.
What is the related Linear task?
Resolves INT-3958
Please explain the objectives of your changes below
Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here
Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?
N/A
Any new dependencies introduced with this change?
N/A
Any new generic utility introduced or modified. Please explain the changes.
N/A
Any technical or performance related pointers to consider with the change?
N/A
@coderabbitai review
Developer checklist
My code follows the style guidelines of this project
No breaking changes are being introduced.
All related docs linked with the PR?
All changes manually tested?
Any documentation changes needed with this change?
Is the PR limited to 10 file changes?
Is the PR limited to one linear task?
Are relevant unit and component test-cases added in new readability format?
Reviewer checklist
Is the type of change in the PR title appropriate as per the changes?
Verified that there are no credentials or confidential data exposed with the changes.