Repository navigation
feat: add missing params and refactor - #4527
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Summary by CodeRabbit
WalkthroughThis update enhances the TikTok Ads destination transformation logic by enriching event payloads, introducing platform-specific user identifier filtering, and implementing dynamic event source handling. The batching logic is refactored to separate test events and group events by their source. Utility functions are extended, and comprehensive tests are added for the new behaviors. Changes
Sequence Diagram(s)sequenceDiagram
participant SourceEvent
participant transformV2
participant util
participant BatchBuilder
participant TikTokAPI
SourceEvent->>transformV2: Incoming event(s)
transformV2->>util: getContents, hashUserField, getEventSource
util-->>transformV2: Enriched payload, filtered user IDs, event source
transformV2->>transformV2: Separate test events, group by event source
transformV2->>BatchBuilder: Batch normal events per source
BatchBuilder->>TikTokAPI: Send batched events
transformV2->>TikTokAPI: Send test events separately
TikTokAPI-->>transformV2: Responses
transformV2-->>SourceEvent: Aggregated and sorted responses
Estimated code review effort🎯 4 (Complex) | ⏱️ ~35 minutes The changes involve significant refactoring, new utility logic, and comprehensive test additions. Reviewers should pay close attention to the batching logic, platform-specific user filtering, and event source handling to ensure correctness and backward compatibility. Possibly related PRs
Suggested reviewers
Suggestions for improvement:
✨ 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. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
src/v0/destinations/tiktok_ads/transformV2.js (1)
715-756: Potential issue with eventSource variable scopeThe
eventSourcevariable is declared outside the loop but reassigned inside it (line 724). Since this is used later when creating the batch event, consider declaring it inside the appropriate scope or extracting it differently:const batchEvents = (processedEvents) => { const events = []; let data = []; let metadata = []; - let eventSource = 'web'; const { destination } = processedEvents[0]; const { pixelCode } = destination.Config; + // Extract event source from first event as all events in this batch should have the same source + const eventSource = processedEvents[0]?.message[0]?.body.JSON.event_source || 'web'; processedEvents.forEach((event) => { const eventData = event.message[0]?.body.JSON.data; - eventSource = event.message[0]?.body.JSON.event_source;This ensures consistency since all events in a batch should have the same event source after grouping.
🧹 Nitpick comments (4)
src/v0/destinations/tiktok_ads/util.test.js (1)
175-185: Consider adding test for idfa lowercase behaviorThe test verifies that
idfaandgaidare hashed, but doesn't validate thatidfais lowercased after hashing (as mentioned in the implementation). Consider adding an assertion to verify this specific behavior:it('should hash idfa and gaid fields if present', () => { const user = { idfa: 'AEBE52E7-03EE-455A-B3C4-E57283966239', gaid: '38400000-8cf0-11bd-b23e-10b96e40000d', }; const hashedUser = hashUserField(user); expect(hashedUser.idfa).toBeDefined(); expect(hashedUser.idfa).not.toBe(user.idfa); + expect(hashedUser.idfa).toBe(hashedUser.idfa.toLowerCase()); expect(hashedUser.gaid).toBeDefined(); expect(hashedUser.gaid).not.toBe(user.gaid); });src/v0/destinations/tiktok_ads/transformV2.test.js (2)
168-188: Consider adding initial gaid value to strengthen the testWhile the test correctly verifies that
gaidis undefined for Apple OS, it would be more robust to initially set agaidvalue in the message to ensure it's actively removed:it('should remove gaid for Apple family OS', async () => { const message = { event: 'purchase', properties: { products: [{ product_id: '123', name: 'Product1', price: 10, quantity: 2 }], }, + user: { + gaid: 'test-gaid-value', + idfa: 'test-idfa-value' + }, context: { os: { name: 'ios' }, device: { advertisingId: 'some-idfa' } }, timestamp: '2023-10-01T00:00:00Z', };
190-211: Consider adding initial device ID valuesSimilar to the Apple OS test, consider adding initial
idfaandidfvvalues to verify they are actively removed:it('should remove idfa and idfv for Android OS', async () => { const message = { event: 'purchase', properties: { products: [{ product_id: '123', name: 'Product1', price: 10, quantity: 2 }], }, + user: { + idfa: 'test-idfa-value', + idfv: 'test-idfv-value', + gaid: 'test-gaid-value' + }, context: { os: { name: 'android' }, device: { advertisingId: 'some-gaid' } }, timestamp: '2023-10-01T00:00:00Z', };src/v0/destinations/tiktok_ads/transformV2.js (1)
86-97: Platform-specific ID filtering implemented correctlyThe logic appropriately removes device IDs based on the operating system. Consider extracting the OS name to a variable to avoid multiple lookups:
- const os = get(message, 'context.os.name'); - - if (isDefinedAndNotNull(os) && payload.user) { - if (isAppleFamily(os)) { + const osName = get(message, 'context.os.name'); + + if (isDefinedAndNotNull(osName) && payload.user) { + if (isAppleFamily(osName)) { delete payload.user.gaid; - } else if (os.toLowerCase() === 'android') { + } else if (osName?.toLowerCase() === 'android') { delete payload.user.idfa; delete payload.user.idfv; } }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
src/v0/destinations/tiktok_ads/data/TikTokTrackV2.jsonis excluded by!**/*.jsontest/integrations/destinations/tiktok_ads/processor/data.tsis excluded by!**/test/**test/integrations/destinations/tiktok_ads/router/data.tsis excluded by!**/test/**
📒 Files selected for processing (4)
src/v0/destinations/tiktok_ads/transformV2.js(13 hunks)src/v0/destinations/tiktok_ads/transformV2.test.js(1 hunks)src/v0/destinations/tiktok_ads/util.js(2 hunks)src/v0/destinations/tiktok_ads/util.test.js(2 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/tiktok_ads/util.test.jssrc/v0/destinations/tiktok_ads/transformV2.test.jssrc/v0/destinations/tiktok_ads/util.jssrc/v0/destinations/tiktok_ads/transformV2.js
🧠 Learnings (5)
📓 Common learnings
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
Learnt from: maheshkutty
PR: rudderlabs/rudder-transformer#4380
File: src/v0/destinations/google_adwords_remarketing_lists/config.js:3-5
Timestamp: 2025-06-04T07:24:58.591Z
Learning: User maheshkutty prefers to handle Google Ads API version upgrades for different destinations in separate pull requests rather than bundling multiple destinations together in a single PR.
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.
src/v0/destinations/tiktok_ads/util.test.js (3)
Learnt from: ItsSudip
PR: #4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
Learnt from: maheshkutty
PR: #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.
Learnt from: anantjain45823
PR: #2842
File: src/v1/sources/shopify/identifierEventsLayer.test.js:5-40
Timestamp: 2024-07-27T07:02:57.329Z
Learning: The processIdentifierEvent function in identifierEventsLayer.test.js is designed to succeed for any input, hence no negative test cases are required.
src/v0/destinations/tiktok_ads/transformV2.test.js (4)
Learnt from: ItsSudip
PR: #4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
Learnt from: maheshkutty
PR: #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.
Learnt from: anantjain45823
PR: #2842
File: src/v1/sources/shopify/identifierEventsLayer.test.js:5-40
Timestamp: 2024-07-27T07:02:57.329Z
Learning: The processIdentifierEvent function in identifierEventsLayer.test.js is designed to succeed for any input, hence no negative test cases are required.
Learnt from: krishna2020
PR: #4178
File: src/sources/shopify/transform.js:37-45
Timestamp: 2025-03-21T12:32:28.443Z
Learning: The getBodyFromV2SpecPayload function in Shopify source transformation throws an error if request is not defined, making additional null checks in getEventFromV2Request function unnecessary.
src/v0/destinations/tiktok_ads/util.js (2)
Learnt from: ItsSudip
PR: #4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
Learnt from: maheshkutty
PR: #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.
src/v0/destinations/tiktok_ads/transformV2.js (6)
Learnt from: ItsSudip
PR: #4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
Learnt from: maheshkutty
PR: #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.
Learnt from: maheshkutty
PR: #4380
File: src/v0/destinations/google_adwords_remarketing_lists/config.js:3-5
Timestamp: 2025-06-04T07:24:58.591Z
Learning: User maheshkutty prefers to handle Google Ads API version upgrades for different destinations in separate pull requests rather than bundling multiple destinations together in a single PR.
Learnt from: krishna2020
PR: #4178
File: src/sources/shopify/transform.js:37-45
Timestamp: 2025-03-21T12:32:28.443Z
Learning: The getBodyFromV2SpecPayload function in Shopify source transformation throws an error if request is not defined, making additional null checks in getEventFromV2Request function unnecessary.
Learnt from: maheshkutty
PR: #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 assumes metadata is always an array throughout its implementation, but defensive programming should be added to handle cases where metadata might not be an array type to prevent runtime errors.
Learnt from: anantjain45823
PR: #2842
File: src/v1/sources/shopify/identifierEventsLayer.test.js:5-40
Timestamp: 2024-07-27T07:02:57.329Z
Learning: The processIdentifierEvent function in identifierEventsLayer.test.js is designed to succeed for any input, hence no negative test cases are required.
⏰ 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 ARM64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Code Coverage
- GitHub Check: test_and_publish
- GitHub Check: UT Tests
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (13)
src/v0/destinations/tiktok_ads/util.test.js (2)
1-1: Import statement correctly updatedThe addition of
getEventSourceto the imports is necessary for the new test suite.
199-240: Comprehensive test coverage for getEventSourceThe test suite thoroughly covers all scenarios including fallback logic, default values, and support for both camelCase and snake_case properties. Well done!
src/v0/destinations/tiktok_ads/util.js (4)
40-40: Destructuring correctly extendedThe addition of
idfaandgaidto the destructured variables is appropriate for the subsequent hashing logic.
61-68: Hashing implementation for device IDs looks goodThe implementation correctly hashes
idfawith lowercase conversion andgaidwithout modification, which aligns with platform-specific requirements.
72-98: Well-implemented event source resolutionThe
getEventSourcefunction correctly implements the fallback logic with proper validation against supported sources. The precedence (camelCase > snake_case > channel > default) is appropriate, and the function handles edge cases safely.
99-99: Module exports correctly updatedThe addition of
getEventSourceto exports is necessary for its usage in the transformation logic.src/v0/destinations/tiktok_ads/transformV2.test.js (2)
144-166: Good test coverage for content aggregationThe test correctly verifies that
contents_idsandnum_itemsare properly extracted from the products array.
213-231: Good test for snake_case event source supportThe test correctly verifies that
event_sourcein snake_case format is properly recognized and used in the response.src/v0/destinations/tiktok_ads/transformV2.js (5)
4-28: Import statements properly extendedThe additional imports correctly support the new functionality for batching, OS detection, and event source handling.
65-76: Well-implemented content aggregation logicThe code correctly extracts
content_idvalues, filters out falsy values, and only addscontents_idswhen valid IDs exist. Thenum_itemscount is appropriately added.
167-167: Dynamic event source correctly implementedThe replacement of the hardcoded
'web'value withgetEventSource(message)enables proper event source resolution from message properties.
423-435: Function rename improves clarityThe rename from
getEventChunkstoseparateTestEventsbetter describes the function's purpose, and the updated parameter names are more descriptive.
788-803: Event source grouping well implementedThe implementation correctly groups events by
event_sourcebefore batching, ensuring all events in a batch have the same source. This aligns with the planned enhancement mentioned in the previous PR feedback.
|
Allure Test reports for this run are available at:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## fix/tiktok_ads_v2 #4527 +/- ##
==================================================
Coverage 91.44% 91.45%
==================================================
Files 639 639
Lines 33788 33809 +21
Branches 7988 7995 +7
==================================================
+ Hits 30899 30920 +21
Misses 2627 2627
Partials 262 262 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Allure Test reports for this run are available at:
|
|
* feat: add missing parameters and refactor code * chore: fix as per cursor review * chore: add test cases to increase coverage * feat: add support of mapping to consider default eventSource --------- Co-authored-by: Sudip Paul <[email protected]>
* fix: add mapping of event_source instead of static * feat: enhance mapping with missing fields of app event_source and the batching logic with grouping (#4501) * feat: enable group by event_source before batching * feat: add missing parameter for app event_source * chore: refactor test cases * chore: revert unwanted changes to test cases --------- Co-authored-by: Sudip Paul <[email protected]> * feat: add missing params and refactor (#4527) * feat: add missing parameters and refactor code * chore: fix as per cursor review * chore: add test cases to increase coverage * feat: add support of mapping to consider default eventSource --------- Co-authored-by: Sudip Paul <[email protected]> * chore: refactor code * chore: address comments * chore: address coderabbit comments --------- Co-authored-by: Sudip Paul <[email protected]>



TikTok Ads Destination Enhancement PR Description
What are the changes introduced in this PR?
This PR enhances the TikTok Ads destination transformer with missing parameters, improved content processing, and comprehensive code refactoring. The changes include:
Added Missing Parameters: Enhanced mapping configuration with device IDs (
idfa,idfv,gaid), search functionality (search_string), attribution tracking (att_status), and lead management fields (lead_id,lead_event_source)Improved Content Processing: Added automatic generation of
contents_idsandnum_itemsfrom content arrays with proper filtering to prevent empty arraysPlatform-Specific Device ID Handling: Implemented OS-based logic to remove inappropriate device IDs (removes
gaidfor Apple devices,idfa/idfvfor Android devices)Enhanced Event Source Detection: Added support for both
eventSourceandevent_source(V2) properties. Also added mapping for the rudderstack-defined channel to eventSource.Code Refactoring: Improved function naming (
getEventChunks→separateTestEvents) and variable naming for better readability and maintainabilityEnhanced User Field Hashing: Extended hashing functionality to include device advertising IDs (
idfa,gaid)What is the related Linear task?
https://linear.app/rudderstack/issue/INT-3933/investigate-hardcoded-event-source-in-tiktok-ads-v2-integration
Please explain the objectives of your changes below
Any changes to existing capabilities/behaviour, mention the reason & what are the changes?
No breaking changes introduced. The enhancements maintain backward compatibility while adding new capabilities:
Content Processing Enhancement: Previously, content arrays were processed without generating
contents_idsandnum_items. Now these fields are automatically generated from content arrays, improving data completeness for TikTok's tracking requirements.Device ID Compliance: Added platform-specific device ID filtering to ensure only appropriate device identifiers are sent to TikTok (Apple devices don't send
gaid, Android devices don't sendidfa/idfv).Enhanced Event Source Support: Extended support for both legacy and new event source properties to accommodate different client implementations. Also considered a mapping to convert rudderstack supported channel to a specific eventSources.
Any new dependencies introduced with this change?
No new dependencies were introduced. All changes utilize existing utility functions and libraries.
Any new generic utility introduced or modified. Please explain the changes.
No new utilities were introduced. The changes leverage existing utilities:
isAppleFamily()for OS detectionget()for safe property accesshashToSha256()for device ID hashingremoveUndefinedAndNullValues()for payload cleanupAny technical or performance related pointers to consider with this change?
Developer checklist
Reviewer checklist
@coderabbitai review