Repository navigation
feat: add new identify flow and subscription event in track call for attentive tag - #4468
Conversation
Summary by CodeRabbit
Summary by CodeRabbit
WalkthroughA new configuration category Changes
Sequence Diagram(s)sequenceDiagram
participant Source as Event Source
participant Transform as transform.js
participant API as Attentive API
Source->>Transform: Send identify event
alt enableNewIdentifyFlow = true
Transform->>Transform: responseBuilderForIdentityResolution
Transform->>API: Identity resolution API call
Transform->>Transform: responseBuilderForUserAttributes
Transform->>API: User attributes API call
Transform->>Source: Aggregate responses
else
Transform->>Transform: identifyResponseBuilder (legacy)
Transform->>API: Single API call
Transform->>Source: Response
end
sequenceDiagram
participant Source as Event Source
participant Transform as transform.js
participant API as Attentive API
Source->>Transform: Send track event ("subscription_event")
Transform->>Transform: subscriptionResponseBuilder
Transform->>Transform: getConsentedUserContacts
alt Subscribe consents present
Transform->>API: Subscribe API call(s)
end
alt Unsubscribe consents present
Transform->>API: Unsubscribe API call(s)
end
Transform->>Source: Aggregate responses
Suggested reviewers
Suggestions for improvement:
📜 Recent review detailsConfiguration used: .coderabbit.yaml ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used📓 Path-based instructions (1)**/*.jsInstructions used from: Sources: 🧠 Learnings (2)src/v0/destinations/attentive_tag/config.js (2)src/v0/destinations/attentive_tag/transform.js (7)⏰ 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 (9)
✨ Finishing Touches
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
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #4468 +/- ##
===========================================
+ Coverage 91.24% 91.27% +0.02%
===========================================
Files 641 640 -1
Lines 33727 33805 +78
Branches 7954 7986 +32
===========================================
+ Hits 30775 30854 +79
- Misses 2687 2717 +30
+ Partials 265 234 -31 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
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: 2
🧹 Nitpick comments (2)
src/v0/destinations/attentive_tag/transform.js (2)
311-313: Consider extracting the subscription event name as a constant.The hardcoded event name comparison could be more maintainable.
Extract the event name constant at the top of the file:
+const SUBSCRIPTION_EVENT_NAME = 'subscription_event'; + const trackResponseBuilder = (message, { Config }) => { const { apiKey } = Config; let endpoint; let payload; const event = get(message, 'event'); if (!event) { throw new InstrumentationError('[Attentive Tag] :: Event name is not present'); } - if (event.toLowerCase().trim().replace(/\s+/g, '_') === 'subscription_event') { + if (event.toLowerCase().trim().replace(/\s+/g, '_') === SUBSCRIPTION_EVENT_NAME) { return subscriptionResponseBuilder(message, { Config }); }
39-301: Add comprehensive test coverage for the new functionality.The PR introduces significant new functionality (identity flow and subscription events) but doesn't include test files. Please ensure adequate test coverage for all new functions.
Would you like me to help generate unit tests for the new identify flow and subscription event handling?
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (4)
src/v0/destinations/attentive_tag/data/identityConfig.jsonis excluded by!**/*.jsontest/integrations/destinations/attentive_tag/processor/identifyTestData.tsis excluded by!**/test/**test/integrations/destinations/attentive_tag/processor/trackTestData.tsis excluded by!**/test/**test/integrations/destinations/attentive_tag/processor/validationTestData.tsis excluded by!**/test/**
📒 Files selected for processing (2)
src/v0/destinations/attentive_tag/config.js(1 hunks)src/v0/destinations/attentive_tag/transform.js(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.js`: Focus on ESLint errors (max 3) and warnings (max 5).
**/*.js: Focus on ESLint errors (max 3) and warnings (max 5).
⚙️ Source: CodeRabbit Configuration File
List of files the instruction was applied to:
src/v0/destinations/attentive_tag/config.jssrc/v0/destinations/attentive_tag/transform.js
🧠 Learnings (1)
src/v0/destinations/attentive_tag/transform.js (1)
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.
🔇 Additional comments (7)
src/v0/destinations/attentive_tag/config.js (1)
8-8: Configuration addition looks good.The new
IDENTITYconfiguration category follows the established pattern and naming convention.src/v0/destinations/attentive_tag/transform.js (6)
39-60: Identity resolution logic is well-structured.The function properly validates required fields and handles the payload construction cleanly.
62-95: User attributes processing is robust.Good validation to prevent empty payloads and clean separation of standard vs custom properties.
97-121: New identify flow orchestration is well-designed.Proper error handling when no valid responses are generated, with a clear error message.
123-128: Feature flag implementation ensures backward compatibility.Good use of default value and clean delegation to the new identify flow.
204-218: Subscribe consent processing is implemented correctly.Proper validation of required fields with clear error messaging.
220-250: Unsubscribe logic handles channel transformation correctly.Good implementation with proper handling of optional fields and channel name mapping.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/v0/destinations/attentive_tag/transform.js (4)
62-95: Consider edge case handling for empty traits object.The function handles most scenarios well, but there's a potential issue when traits is an empty object or null.
const processUserAttributes = (message, apiKey) => { - const traits = getFieldValueFromMessage(message, 'traits') || {}; + const traits = getFieldValueFromMessage(message, 'traits'); + if (!traits || typeof traits !== 'object') { + return null; + }
97-121: Enhance error message with more specific details.The error message could be more helpful by indicating which specific validations failed.
if (responses.length === 0) { throw new InstrumentationError( - '[Attentive Tag]: Identify payload is not valid, either user or properties is empty', + '[Attentive Tag]: No valid API calls generated - check that user identifiers and custom properties are provided', ); }
204-218: Validate signUpSourceId earlier to prevent processing overhead.Move the signUpSourceId validation before processing the filtered user to avoid unnecessary work.
const processSubscribeConsents = (filteredUser, signUpSourceId, apiKey) => { + if (!signUpSourceId) { + throw new ConfigurationError( + '[Attentive Tag]: SignUp Source Id is required for subscribe event', + ); + } + if (Object.keys(filteredUser).length === 0) return []; - if (!signUpSourceId) { - throw new ConfigurationError( - '[Attentive Tag]: SignUp Source Id is required for subscribe event', - ); - }
220-250: Channel mapping logic could be more maintainable.The hardcoded channel mapping ('sms' → 'TEXT', others → 'EMAIL') should be extracted to a constant or helper function for better maintainability.
+const CHANNEL_MAPPING = { + sms: 'TEXT', + email: 'EMAIL' +}; + +const mapChannelToSubscriptionType = (channel) => { + return CHANNEL_MAPPING[channel?.toLowerCase()] || 'EMAIL'; +}; // In the processUnsubscribeConsents function: const subscriptions = unsubscribeConsents .filter((consent) => consent.type) .map((consent) => ({ type: consent.type, - channel: consent.channel === 'sms' ? 'TEXT' : 'EMAIL', + channel: mapChannelToSubscriptionType(consent.channel), }));
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
test/integrations/destinations/attentive_tag/processor/validationTestData.tsis excluded by!**/test/**
📒 Files selected for processing (1)
src/v0/destinations/attentive_tag/transform.js(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.js`: Focus on ESLint errors (max 3) and warnings (max 5).
**/*.js: Focus on ESLint errors (max 3) and warnings (max 5).
⚙️ Source: CodeRabbit Configuration File
List of files the instruction was applied to:
src/v0/destinations/attentive_tag/transform.js
🧠 Learnings (1)
src/v0/destinations/attentive_tag/transform.js (7)
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.
Learnt from: krishna2020
PR: rudderlabs/rudder-transformer#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: anantjain45823
PR: rudderlabs/rudder-transformer#2842
File: src/v1/sources/shopify/enrichmentLayer.js:36-42
Timestamp: 2024-07-27T07:02:57.329Z
Learning: The user clarified that errors in the `setExtraNonEcomProperties` function should not cause the event to fail, indicating a preference for resilience over strict error propagation.
Learnt from: anantjain45823
PR: rudderlabs/rudder-transformer#2842
File: src/v1/sources/shopify/enrichmentLayer.js:36-42
Timestamp: 2024-10-08T15:52:59.819Z
Learning: The user clarified that errors in the `setExtraNonEcomProperties` function should not cause the event to fail, indicating a preference for resilience over strict error propagation.
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` 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: krishna2020
PR: rudderlabs/rudder-transformer#4178
File: src/sources/shopify/transform.js:37-45
Timestamp: 2025-03-21T12:32:28.443Z
Learning: The getBodyFromV2SpecPayload function throws an error if request is not defined, making additional null checks in the getEventFromV2Request function unnecessary.
Learnt from: krishna2020
PR: rudderlabs/rudder-transformer#4178
File: src/sources/shopify/transform.js:37-45
Timestamp: 2025-03-21T12:32:28.443Z
Learning: The getBodyFromV2SpecPayload function in the Shopify source throws an error if request is not defined, making additional null checks in getEventFromV2Request function unnecessary.
⏰ 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 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 ARM64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Code Coverage
- GitHub Check: UT Tests
- GitHub Check: test_and_publish
- GitHub Check: Analyze (go)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (5)
src/v0/destinations/attentive_tag/transform.js (5)
39-60: The identity resolution logic looks solid.The function correctly validates required fields and constructs the payload appropriately. The conditional logic ensures API calls are only made when necessary data is present.
123-128: LGTM - Clean feature flag implementation.The conditional logic properly maintains backward compatibility while enabling the new identify flow when the feature flag is enabled.
188-202: Good implementation addressing previous feedback.The case-insensitive channel comparison and optional chaining properly handle edge cases as suggested in previous reviews.
252-305: Robust subscription event handling with proper validation.The function properly validates user data as suggested in previous reviews and handles both subscribe and unsubscribe scenarios effectively. The error handling is comprehensive.
315-317: Event name normalization is consistent.The event name processing using
toLowerCase().trim().replace(/\s+/g, '_')is consistent with the existing switch statement logic below.
|
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.
Pull Request Overview
This PR introduces a feature-flagged identify flow leveraging Identity Resolution and User Attributes APIs, and adds support for a new subscription_event in the track call for subscription management.
- Implements
identifyResponseBuilderNewwithprocessIdentityResolutionandprocessUserAttributesunder theenableNewIdentifyFlowflag - Adds subscription-event handling in
trackResponseBuilderviasubscriptionResponseBuilder, with helpers for filtering and processing consents - Expands test coverage: new validation tests for identify and subscription errors and un-skips existing integration tests
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/v0/destinations/attentive_tag/config.js | Added IDENTITY config category and mapChannelToSubscriptionType |
| src/v0/destinations/attentive_tag/data/identityConfig.json | New mapping for identity resolution (phone, email) |
| src/v0/destinations/attentive_tag/transform.js | New helper functions for identify and subscription flows; updated builders |
| test/integrations/.../validationTestData.ts | Added validation tests for new identify flow and subscription error cases |
| test/integrations/.../trackTestData.ts & identifyTestData.ts | Removed skip flags to activate previously-skipped tests |
Comments suppressed due to low confidence (2)
src/v0/destinations/attentive_tag/transform.js:320
- Add positive test cases for successful
subscription_eventhandling (e.g., valid subscribe and unsubscribe flows) to ensure the new code path is fully exercised.
if (event.toLowerCase().trim().replace(/\s+/g, '_') === 'subscription_event') {
src/v0/destinations/attentive_tag/transform.js:194
- [nitpick] Consider adding JSDoc comments for the new helper functions (
filterUserByConsents,processSubscribeConsents, etc.) to clarify their purpose, parameters, and return values.
const filterUserByConsents = (user, consents) => {
|
I will raise doc PR after we merge this PR. |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/v0/destinations/attentive_tag/transform.js (1)
68-101: Consider relaxing the validation logic for user attributes.The current validation on lines 96-97 returns null if either user or properties is empty. This might be too restrictive - consider allowing updates when a user has valid contact info even without custom properties.
- // If user or properties is empty, return null as we don't want to send empty user or properties - if (Object.keys(user).length === 0 || Object.keys(properties).length === 0) { - return null; - } + // If user is empty, return null. Allow empty properties for users with valid contact info + if (Object.keys(user).length === 0) { + return null; + }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
src/v0/destinations/attentive_tag/data/identityResolutionConfig.jsonis excluded by!**/*.json
📒 Files selected for processing (3)
src/v0/destinations/attentive_tag/config.js(2 hunks)src/v0/destinations/attentive_tag/transform.js(5 hunks)src/v0/destinations/attentive_tag/util.js(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/v0/destinations/attentive_tag/config.js
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.js`: Focus on ESLint errors (max 3) and warnings (max 5).
**/*.js: Focus on ESLint errors (max 3) and warnings (max 5).
⚙️ Source: CodeRabbit Configuration File
List of files the instruction was applied to:
src/v0/destinations/attentive_tag/transform.jssrc/v0/destinations/attentive_tag/util.js
🧠 Learnings (2)
src/v0/destinations/attentive_tag/transform.js (6)
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.
Learnt from: krishna2020
PR: rudderlabs/rudder-transformer#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: anantjain45823
PR: rudderlabs/rudder-transformer#2842
File: src/v1/sources/shopify/enrichmentLayer.js:36-42
Timestamp: 2024-07-27T07:02:57.329Z
Learning: The user clarified that errors in the `setExtraNonEcomProperties` function should not cause the event to fail, indicating a preference for resilience over strict error propagation.
Learnt from: anantjain45823
PR: rudderlabs/rudder-transformer#2842
File: src/v1/sources/shopify/enrichmentLayer.js:36-42
Timestamp: 2024-10-08T15:52:59.819Z
Learning: The user clarified that errors in the `setExtraNonEcomProperties` function should not cause the event to fail, indicating a preference for resilience over strict error propagation.
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` 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: krishna2020
PR: rudderlabs/rudder-transformer#4178
File: src/sources/shopify/transform.js:37-45
Timestamp: 2025-03-21T12:32:28.443Z
Learning: The getBodyFromV2SpecPayload function throws an error if request is not defined, making additional null checks in the getEventFromV2Request function unnecessary.
src/v0/destinations/attentive_tag/util.js (1)
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.
⏰ 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 ARM64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Code Coverage
- GitHub Check: UT Tests
- GitHub Check: test_and_publish
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (9)
src/v0/destinations/attentive_tag/util.js (1)
141-155: Function implementation looks solid with proper defensive programming.The
filterUserByConsentsfunction is well-structured with appropriate null safety and case-insensitive channel comparison. The logic correctly filters user contact information based on consent channels.src/v0/destinations/attentive_tag/transform.js (8)
4-9: Import statements properly updated for new functionality.The additional imports for
mapChannelToSubscriptionTypeand configuration categories are correctly added to support the new subscription event handling.
45-66: Identity resolution logic is well-implemented with proper validation.The function correctly constructs the payload and validates required fields before returning a response. The conditional logic ensures API calls are only made when necessary data is available.
104-127: New identify flow implementation is well-structured.The modular approach with separate identity resolution and user attributes processing provides clear separation of concerns. The error handling appropriately catches cases where no valid responses are generated.
129-134: Feature flag implementation maintains backward compatibility effectively.The conditional logic based on
enableNewIdentifyFlowensures existing functionality remains unchanged while allowing new features to be enabled when ready.
194-208: Subscribe response builder handles validation appropriately.The function correctly validates required fields and returns empty arrays when conditions aren't met, which integrates well with the response aggregation logic.
210-240: Unsubscribe logic properly handles consent mapping and validation.The implementation correctly filters consents, maps channels to subscription types, and includes optional notification data. The validation ensures only valid unsubscribe requests are processed.
242-295: Subscription event handling is comprehensive and well-structured.The implementation properly separates subscribe and unsubscribe consents, validates user data, and aggregates responses. The error handling covers edge cases appropriately.
305-307: Track event routing for subscription events is implemented correctly.The conditional logic properly detects subscription events and routes them to the appropriate handler before falling through to existing event processing.
|
Allure Test reports for this run are available at:
|
|
Allure Test reports for this run are available at:
|
|
ItsSudip
left a comment
There was a problem hiding this comment.
Can we add some positive scenarios for both the identify and track events?
I have added most of the positive tests here #4457 |



What are the changes introduced in this PR?
Key Changes:
✅ Enhanced identify flow using Identity Resolution + User Attributes APIs when enableNewIdentifyFlow enabled
✅ New subscription_event track call for subscription management
What is the related Linear task?
Resolves INT-3829
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.