using attributionDetails to store referrer#46096
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR normalizes the marketing cookie referrer into attributionDetails.referrer (string-only, otherwise undefined), then uses that normalized value when setting Salesforce contact fields: Source_referrer_url__c and Most_recent_referrer_url__c during new Contact creation, and Most_recent_referrer_url__c during existing Contact updates. Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@website/api/helpers/salesforce/update-or-create-contact-and-account.js`:
- Line 265: Normalize the referrer value before assigning it to
attributionDetails.referrer: ensure marketingAttributionCookie.referrer is
coerced to a safe string (e.g., check typeof and use String(...) or fallback to
'' for null/undefined/non-string inputs) at the point where marketing
attribution is normalized, then assign that sanitized variable to
attributionDetails.referrer so downstream writes to Source_referrer_url__c /
Most_recent_referrer_url__c receive a valid string.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 090efb2c-dfed-423b-8765-fe597dec8e68
📒 Files selected for processing (1)
website/api/helpers/salesforce/update-or-create-contact-and-account.js
|
|
||
| attributionDetails.initialUrl = marketingAttributionCookie.initialUrl; | ||
|
|
||
| attributionDetails.referrer = marketingAttributionCookie.referrer; |
There was a problem hiding this comment.
Normalize referrer to a string before storing it in attributionDetails.
Line 265 copies untrusted cookie data directly; if it’s not a string, downstream writes to Source_referrer_url__c / Most_recent_referrer_url__c can fail Salesforce updates. Reuse a sanitized string at normalization time.
Suggested fix
- attributionDetails.referrer = marketingAttributionCookie.referrer;
+ attributionDetails.referrer = typeof marketingAttributionCookie.referrer === 'string'
+ ? marketingAttributionCookie.referrer
+ : undefined;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| attributionDetails.referrer = marketingAttributionCookie.referrer; | |
| attributionDetails.referrer = typeof marketingAttributionCookie.referrer === 'string' | |
| ? marketingAttributionCookie.referrer | |
| : undefined; |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@website/api/helpers/salesforce/update-or-create-contact-and-account.js` at
line 265, Normalize the referrer value before assigning it to
attributionDetails.referrer: ensure marketingAttributionCookie.referrer is
coerced to a safe string (e.g., check typeof and use String(...) or fallback to
'' for null/undefined/non-string inputs) at the point where marketing
attribution is normalized, then assign that sanitized variable to
attributionDetails.referrer so downstream writes to Source_referrer_url__c /
Most_recent_referrer_url__c receive a valid string.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
website/api/helpers/salesforce/update-or-create-contact-and-account.js (1)
265-265:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winFix the incomplete type check in the referrer normalization.
The
typeofoperator returns a string representing the type (e.g.,"string","object","undefined"), and any non-empty string is truthy in JavaScript. This means the conditiontypeof marketingAttributionCookie.referreralways evaluates totrue, causing non-string values (objects, arrays, numbers) to be assigned directly toattributionDetails.referrer. Lines 507, 508, and 638 then write this unsanitized value to Salesforce URL fields, which can cause update failures.🐛 Proposed fix: Add the missing string comparison
- attributionDetails.referrer = typeof marketingAttributionCookie.referrer ? marketingAttributionCookie.referrer : undefined; + attributionDetails.referrer = typeof marketingAttributionCookie.referrer === 'string' + ? marketingAttributionCookie.referrer + : undefined;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@website/api/helpers/salesforce/update-or-create-contact-and-account.js` at line 265, The conditional assigning attributionDetails.referrer is using typeof without comparing to "string", so it always evaluates truthy and can assign non-string values; change the check to explicitly test typeof marketingAttributionCookie.referrer === "string" before assigning (i.e., set attributionDetails.referrer = typeof marketingAttributionCookie.referrer === "string" ? marketingAttributionCookie.referrer : undefined) to ensure only strings are written to the Salesforce URL fields referenced later.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@website/api/helpers/salesforce/update-or-create-contact-and-account.js`:
- Line 265: The conditional assigning attributionDetails.referrer is using
typeof without comparing to "string", so it always evaluates truthy and can
assign non-string values; change the check to explicitly test typeof
marketingAttributionCookie.referrer === "string" before assigning (i.e., set
attributionDetails.referrer = typeof marketingAttributionCookie.referrer ===
"string" ? marketingAttributionCookie.referrer : undefined) to ensure only
strings are written to the Salesforce URL fields referenced later.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 65ecedbb-3c16-475b-a6d7-f19575ce98e4
📒 Files selected for processing (1)
website/api/helpers/salesforce/update-or-create-contact-and-account.js
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
|
@eashaw - troubleshooting why I'm not seeing referral data in SFDC. Starting by making the code the same. In SFDC, everything looks correct |
Not seeing referrer data in SFDC, making this code consistent to troubleshoot
Summary by CodeRabbit