Skip to content

Add af and referrer to default referral query parameters#286

Merged
yosriady merged 1 commit into
mainfrom
claude/intelligent-hamilton-msd8hp
Jun 17, 2026
Merged

Add af and referrer to default referral query parameters#286
yosriady merged 1 commit into
mainfrom
claude/intelligent-hamilton-msd8hp

Conversation

@yosriady

@yosriady yosriady commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Expanded the default referral code query parameters to include af (affiliate) and referrer parameters, in addition to the existing ref, referral, and refcode parameters. This allows the SDK to capture more common referral attribution sources out of the box.

Key Changes

  • Added af and referrer to default referral parameters: Extended DEFAULT_REFERRAL_PARAMS constant to include these additional attribution parameters in the order: ref, referral, refcode, af, referrer
  • Centralized parameter definitions: Created DEFAULT_REFERRAL_PARAMS constant in src/event/constants.ts to serve as the single source of truth for default referral parameters
  • Updated page properties exclusion: Modified PAGE_PROPERTIES_EXCLUDED_FIELDS to use the new DEFAULT_REFERRAL_PARAMS constant instead of hardcoding individual parameter names
  • Updated EventFactory: Replaced hardcoded default parameter list with reference to DEFAULT_REFERRAL_PARAMS constant
  • Updated ReferralOptions documentation: Updated JSDoc to reflect the new default parameters and provided a more realistic example
  • Added comprehensive test coverage: Added new test suite "Referral code parameter (default query params)" with tests for:
    • Each individual parameter being captured into context.ref
    • Proper separation of ?referrer query parameter from document.referrer
    • Parameter precedence (first parameter in the list wins)
    • Updated existing test to verify af parameter is excluded from page properties

Implementation Details

  • Parameters are checked in order, with the first present parameter supplying the referral code
  • The referrer parameter is intentionally included to capture referral codes, while being kept separate from the document.referrer property (which represents the external entry URL)
  • All referral parameters are excluded from page event properties to prevent them from polluting analytics data
  • The constant is kept in sync with the ReferralOptions.queryParams JSDoc default value

https://claude.ai/code/session_01NE7oDonRuxxDrNLe9Kfme3


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Add `af` and `referrer` to the default referral tracking query
parameters checked on the landing-page URL, alongside the existing
`ref`, `referral`, and `refcode`. So `?af=CODE` and `?referrer=CODE`
are now captured as the `ref` traffic source out of the box.

Centralize the default list as DEFAULT_REFERRAL_PARAMS in
event/constants.ts (mirroring the CLICK_ID_PARAMS pattern) so the
extraction list and the page-properties exclusion set share one source
of truth and can't drift. EventFactory consumes it for the default,
and it is spread into PAGE_PROPERTIES_EXCLUDED_FIELDS.

Update the ReferralOptions.queryParams @default doc and add tests
covering extraction of every default param into context.ref, the
?referrer-vs-document.referrer distinction, and default ordering.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NE7oDonRuxxDrNLe9Kfme3

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request extracts the default referral parameters into a shared constant DEFAULT_REFERRAL_PARAMS and expands the default list to include af and referrer. It also updates the excluded page properties, documentation, and adds comprehensive unit tests for the new default parameters. The feedback suggests simplifying the ternary expression in EventFactory.ts using optional chaining to improve readability.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/event/EventFactory.ts
Comment on lines 195 to +197
const referralParams = !this.options?.referral
? defaultParams // No referral config at all → use defaults
: (this.options.referral.queryParams ?? defaultParams); // Has config → use queryParams or defaults
? DEFAULT_REFERRAL_PARAMS // No referral config at all → use defaults
: (this.options.referral.queryParams ?? DEFAULT_REFERRAL_PARAMS); // Has config → use queryParams or defaults

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This ternary expression can be simplified and made more readable by using optional chaining (?.) directly. This avoids the negated ternary check and redundant references to DEFAULT_REFERRAL_PARAMS.

    const referralParams = this.options?.referral?.queryParams ?? DEFAULT_REFERRAL_PARAMS;

@yosriady yosriady merged commit 7520492 into main Jun 17, 2026
11 checks passed
@yosriady yosriady deleted the claude/intelligent-hamilton-msd8hp branch June 17, 2026 03:04
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.

2 participants