Skip to content

using attributionDetails to store referrer#46096

Merged
johnjeremiah merged 4 commits into
mainfrom
jj-fix-referral-fieldupdate
May 23, 2026
Merged

using attributionDetails to store referrer#46096
johnjeremiah merged 4 commits into
mainfrom
jj-fix-referral-fieldupdate

Conversation

@johnjeremiah
Copy link
Copy Markdown
Contributor

@johnjeremiah johnjeremiah commented May 22, 2026

Not seeing referrer data in SFDC, making this code consistent to troubleshoot

Summary by CodeRabbit

  • Refactor
    • Standardized referrer attribution so referrer URLs are consistently captured from attribution data and applied for both new and existing contacts in the Salesforce integration, improving accuracy of marketing attribution and recent referrer tracking.

Review Change Stack

@johnjeremiah johnjeremiah requested a review from eashaw May 22, 2026 20:01
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e39f2c84-672e-4e77-8a7d-2bdc508200e2

📥 Commits

Reviewing files that changed from the base of the PR and between eb10972 and cf61924.

📒 Files selected for processing (1)
  • website/api/helpers/salesforce/update-or-create-contact-and-account.js

Walkthrough

This 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

  • fleetdm/fleet#45807: Also modifies the same helper to persist the marketing cookie's referrer into Salesforce contact referrer fields during contact creation and update.
  • fleetdm/fleet#45803: Modifies the same helper's attribution logic to derive referrer-related Salesforce fields from the marketing attribution cookie.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is minimal and lacks required checklist items from the template (changes file, testing, validation). Most sections are incomplete or unchecked. Complete the required checklist items including changes file documentation, testing verification, and security/validation checks as specified in the template.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: using attributionDetails to store referrer data instead of direct cookie access.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jj-fix-referral-fieldupdate

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 194fa57 and 2d3c64a.

📒 Files selected for processing (1)
  • website/api/helpers/salesforce/update-or-create-contact-and-account.js


attributionDetails.initialUrl = marketingAttributionCookie.initialUrl;

attributionDetails.referrer = marketingAttributionCookie.referrer;
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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Suggested change
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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
website/api/helpers/salesforce/update-or-create-contact-and-account.js (1)

265-265: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Fix the incomplete type check in the referrer normalization.

The typeof operator returns a string representing the type (e.g., "string", "object", "undefined"), and any non-empty string is truthy in JavaScript. This means the condition typeof marketingAttributionCookie.referrer always evaluates to true, causing non-string values (objects, arrays, numbers) to be assigned directly to attributionDetails.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

📥 Commits

Reviewing files that changed from the base of the PR and between 2d3c64a and 189a54c.

📒 Files selected for processing (1)
  • website/api/helpers/salesforce/update-or-create-contact-and-account.js

@johnjeremiah johnjeremiah self-assigned this May 22, 2026
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@johnjeremiah
Copy link
Copy Markdown
Contributor Author

@eashaw - troubleshooting why I'm not seeing referral data in SFDC. Starting by making the code the same. In SFDC, everything looks correct

Comment thread website/api/helpers/salesforce/update-or-create-contact-and-account.js Outdated
@fleet-release fleet-release requested a review from eashaw May 22, 2026 22:35
@johnjeremiah johnjeremiah merged commit 365f805 into main May 23, 2026
12 checks passed
@johnjeremiah johnjeremiah deleted the jj-fix-referral-fieldupdate branch May 23, 2026 02:37
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.

3 participants