-
Notifications
You must be signed in to change notification settings - Fork 11
[CDX-280] Allow updating sendTrackingEvents in setClientOptions #407
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
[CDX-280] Allow updating sendTrackingEvents in setClientOptions #407
Conversation
This may be necessary in case a cookie consent changes and no tracking event should be dispatched anymore. This would allow it to keep the logic therefore in the client and not having to do this check before each call.
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.
Pull Request Overview
This PR adds the ability to dynamically update the sendTrackingEvents option in the ConstructorIO client library, allowing developers to enable or disable tracking events after initialization.
- Added
sendTrackingEventsparameter to thesetClientOptionsmethod - Implemented strict boolean type checking to ensure only valid boolean values update the setting
- Added propagation of the setting to the internal tracker module
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/constructorio.js | Added support for updating sendTrackingEvents option with boolean type validation and tracker propagation |
| spec/src/constructorio.js | Added comprehensive test coverage for the new functionality including type validation and behavior verification |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Code Review: PR #407 - Allow updating sendTrackingEventsSummaryThis PR adds the ability to dynamically update the ✅ StrengthsCode Quality
Test Coverage
🔍 Issues & Recommendations1. Inconsistent Option Update PatternSeverity: Medium The implementation deviates from the existing pattern in Current code (line 179-182 in if (typeof sendTrackingEvents === 'boolean') {
this.options.sendTrackingEvents = sendTrackingEvents;
this.tracker.requests.sendTrackingEvents = sendTrackingEvents;
}Comparison with other options (lines 171-176): if (segments) {
this.options.segments = segments;
}
if (testCells) {
this.options.testCells = testCells;
}Why this matters: The strict type check is actually better for a boolean flag (prevents truthy/falsy confusion), but it creates inconsistency in the codebase. Consider whether other boolean options should follow this pattern. Recommendation: This approach is correct for booleans. Consider documenting this pattern or refactoring other boolean options to use similar strict type checking in a future PR. 2. Missing Options Object UpdateSeverity: Medium The code updates Potential issue: If any code checks Recommendation: Add this line after line 181 in this.tracker.options.sendTrackingEvents = sendTrackingEvents;3. Test Import Not UsedSeverity: Low The test file adds Recommendation: Consider moving the import closer to where it's used for better clarity, or leave it if this is the project's convention. 4. Async Test TimingSeverity: Low The tests use fixed timeouts (10ms, 50ms, 100ms) which could be flaky in slow CI environments. Lines: Tests at lines 395-426 and 448-513 use Recommendation: While these timeouts seem reasonable, consider using a test helper or increasing timeouts slightly if flakiness occurs in CI. The current implementation is acceptable for now. 🚀 Performance Considerations
🔒 Security Concerns
📊 Test Coverage AssessmentExcellent coverage with tests for:
📝 Action ItemsBefore merging:
Future considerations:
VerdictApprove with minor changes. The implementation is solid and well-tested. The main issue is ensuring consistency with the tracker's options object. Once addressed, this is ready to merge. Generated by Claude Code Review |
jjl014
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.
Looks good to me! 🚀
jensmeichler
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.
Thank you very much :D
That saves us a lot of extra logic we'd have to wrap around all calls 👍
Code Review - PR #407: Allow updating sendTrackingEvents in setClientOptionsSummaryThis PR adds support for dynamically updating the ✅ Strengths1. Excellent Test Coverage
2. Type Safety Improvement// Before: if (sendTrackingEvents !== undefined)
// After: if (typeof sendTrackingEvents === 'boolean')This change (src/constructorio.js:179) is more robust and prevents truthy/falsy coercion issues (e.g., 3. Proper PropagationThe implementation correctly updates both the options and the underlying RequestQueue instance via 🔍 Potential Issues & Recommendations1. Architecture Consideration: Direct Property Accessthis.tracker.requests.sendTrackingEvents = sendTrackingEvents;Issue: This directly accesses and mutates an internal property of the RequestQueue instance, bypassing encapsulation. Risk: If RequestQueue changes its internal structure or needs to perform additional logic when sendTrackingEvents changes, this code will break or behave incorrectly. Recommendation: Consider adding a setter method to RequestQueue: // In RequestQueue class (src/utils/request-queue.js)
setSendTrackingEvents(value) {
this.sendTrackingEvents = value;
// Any future logic can be added here
}
// In setClientOptions (src/constructorio.js)
this.tracker.requests.setSendTrackingEvents(sendTrackingEvents);This provides better encapsulation and makes the API more maintainable. 2. Inconsistent Property Naming
Verification Needed: Confirm these are the same property. If they are, the code is correct but could benefit from a comment explaining the relationship. 3. Race Condition Concern// Test: spec/src/constructorio.js:394-423
instance.tracker.trackSessionStart();
setTimeout(() => {
instance.setClientOptions({ sendTrackingEvents: false });
// ...
}, 50);Issue: There's a potential race condition if events are queued but not yet sent when sendTrackingEvents is toggled. Questions:
Recommendation: Document the expected behavior explicitly, possibly in the JSDoc for setClientOptions. 4. Missing JSDoc UpdateThe JSDoc comment (src/constructorio.js:161) correctly documents the parameter but could be enhanced: /**
* @param {boolean} [options.sendTrackingEvents] - Indicates if tracking events should be dispatched.
* Changes are applied immediately and affect
* all subsequent tracking calls.
*/🔒 SecurityNo security concerns identified. The type checking prevents injection or unexpected behavior from invalid inputs. ⚡ PerformanceNo performance concerns. The changes are minimal and only execute when setClientOptions is called. 🧪 Test QualityThe tests are well-structured and follow existing patterns in the codebase:
Minor Suggestion: The test at line 394 (spec/src/constructorio.js:394) could be slightly more explicit about what it's testing with a better description. 📋 Action ItemsHigh Priority:
Low Priority:
✅ ConclusionThis is a well-implemented feature with excellent test coverage. The code quality is good and follows the project's conventions (airbnb-base ESLint config). The primary concern is the architectural pattern of directly accessing internal properties, which could be improved for long-term maintainability. Otherwise, this is ready to merge after addressing the action items. Overall Rating: 8.5/10 Great work! 🚀 |
Adds support for dynamically updating the
sendTrackingEventsoption viasetClientOptions()to enable/disable tracking at runtime. Updates are now propagated to the RequestQueue instance, ensuring tracking behavior immediately reflects the new value.