Skip to content

feat(snapchat_conversion): add products to contents mapping - #4526

Merged
maheshkutty merged 6 commits into
developfrom
feat.snapchat_product_mapping
Aug 18, 2025
Merged

maheshkutty merged 6 commits into
developfrom
feat.snapchat_product_mapping

Conversation

@maheshkutty

@maheshkutty maheshkutty commented Jul 23, 2025 •

Copy link
Copy Markdown
Contributor

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 contents field in outgoing payloads is consistently populated based on product data, improving downstream analytics and event tracking.

Transformation logic improvements:

  • Added the productsToContentsMapping utility function to utilsV3.js, which extracts and normalizes product information from incoming messages to generate a standardized contents array for Snapchat payloads. This function handles various edge cases, such as missing or malformed product data, and ensures only valid content objects are included.
  • Updated transformV3.js to use the new productsToContentsMapping function within the payload builder, ensuring the contents field is added to outgoing payloads when applicable. [1] [2]

Testing and validation:

  • Added comprehensive unit tests for the productsToContentsMapping function in utilsV3.test.js, covering a wide range of input scenarios and edge cases to guarantee correct behavior.
  • Updated processor test data in dataV3.ts to include the new contents field 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:

  • Extended imports from the shared util module in utilsV3.js to 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.

@maheshkutty
maheshkutty requested review from a team and sivashanmukh as code owners July 23, 2025 15:36
@maheshkutty
maheshkutty requested review from a team, chandumlg and utsabc July 23, 2025 15:36
@coderabbitai

coderabbitai Bot commented Jul 23, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Enriched Snapchat Conversion events with a contents field in custom data, automatically built from product information.
    • Supports multiple products and sensible fallbacks when a products list is missing, using top-level properties.
    • Skips empty or invalid fields for cleaner payloads and improved compatibility with Snapchat.
    • No breaking changes.
  • Tests

    • Added comprehensive test coverage for various product structures, precedence rules, and fallback scenarios to ensure accurate contents generation.

Walkthrough

Adds 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

Cohort / File(s) Change Summary
Transform integration
src/v0/destinations/snapchat_conversion/transformV3.js
Imports productsToContentsMapping and in buildBasePayload computes contents = productsToContentsMapping(message); if non-empty, assigns payload.data[0].custom_data.contents = contents. No signature changes.
Utility
src/v0/destinations/snapchat_conversion/utilsV3.js
Adds and exports productsToContentsMapping(message) which maps message.properties.products (array) or top-level product fields to sanitized content objects with id (priority: product_id → sku → id), item_price (from price), quantity, and delivery_category; returns [] for missing/invalid products. Expanded imports from ../../util to include isAppleFamily, isObject, removeUndefinedAndNullValues, and isEmptyObject.
Tests
src/v0/destinations/snapchat_conversion/utilsV3.test.js
New Jest tests covering null/invalid inputs, empty arrays, identifier precedence, field mapping/renaming, removal of null/undefined fields, filtering of invalid product entries, and fallback to top-level properties.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • feat: snapchat v3 #4052 — Adds or modifies Snapchat v3 transform and utilities; directly related to the introduction and wiring of productsToContentsMapping.

Suggested reviewers

  • sivashanmukh
  • manish339k
  • koladilip
  • utsabc

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 details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f13f0de and 55d0063.

⛔ Files ignored due to path filters (1)
  • test/integrations/destinations/snapchat_conversion/processor/dataV3.ts is excluded by !**/test/**
📒 Files selected for processing (2)
  • src/v0/destinations/snapchat_conversion/utilsV3.js (2 hunks)
  • src/v0/destinations/snapchat_conversion/utilsV3.test.js (1 hunks)
🧰 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
  • src/v0/destinations/snapchat_conversion/utilsV3.test.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 (2)
src/v0/destinations/snapchat_conversion/utilsV3.js (1)
src/v0/util/index.js (1)
  • removeUndefinedAndNullValues (55-55)
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-10)
  • productsToContentsMapping (139-169)
⏰ 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)
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • 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: UT Tests
  • GitHub Check: test_and_publish
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
src/v0/destinations/snapchat_conversion/utilsV3.js (3)

5-10: Imports are scoped and used correctly.

The broadened util imports are appropriate and each symbol is used in this module. No ESLint issues here.


139-169: Sanitization approach is solid and preserves zeroes.

Using removeUndefinedAndNullValues + isEmptyObject yields clean contents while preserving falsy-but-valid values like 0 (quantity/price). The tests cover these cases. LGTM.


171-175: Export wiring looks correct.

productsToContentsMapping is exported and consumed in transformV3/tests as expected.

src/v0/destinations/snapchat_conversion/utilsV3.test.js (1)

1-188: Comprehensive coverage of edge cases and happy paths.

The table-driven tests cover null/undefined inputs, empty/non-array products, identifier precedence, sanitization behavior (keeping zeros), delivery_category, ordering, and fallback to root properties. This should prevent regressions. LGTM.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat.snapchat_product_mapping

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Jul 23, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.81%. Comparing base (a0d4325) to head (55d0063).
⚠️ Report is 38 commits behind head on develop.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

ItsSudip
ItsSudip previously approved these changes Jul 24, 2025
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@maheshkutty
maheshkutty requested a review from ItsSudip August 12, 2025 09:39

@coderabbitai coderabbitai Bot left a comment

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.

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, and expect will 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.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

2 similar comments
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@coderabbitai coderabbitai Bot left a comment

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.

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 covered

This 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 good

The 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.js properly destructures and calls productsToContentsMapping
– utilsV3.test.js already covers the function via its test suite

All downstream references are in place; no further action required.

@maheshkutty
maheshkutty force-pushed the feat.snapchat_product_mapping branch from 4f0d8c2 to f13f0de Compare August 18, 2025 04:13
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

Copy link
Copy Markdown

@maheshkutty
maheshkutty merged commit 26c3dd7 into develop Aug 18, 2025
@maheshkutty
maheshkutty deleted the feat.snapchat_product_mapping branch August 18, 2025 10:10
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