Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/analytics-browser/src/attribution/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ export const isNewCampaign = (
};

export const isExcludedReferrer = (excludeReferrers: (string | RegExp)[] = [], referringDomain = '') => {
// remove port from referringDomain
const referringDomainWithoutPort = referringDomain.split(':')[0];
return excludeReferrers.some((value) =>
value instanceof RegExp ? value.test(referringDomain) : value === referringDomain,
value instanceof RegExp ? value.test(referringDomainWithoutPort) : value === referringDomainWithoutPort,
Comment on lines +65 to +67
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

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

[nitpick] The variable name referringDomainWithoutPort is verbose and could be simplified to domainWithoutPort or domain for better readability.

Copilot uses AI. Check for mistakes.

Copy link

Choose a reason for hiding this comment

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

Bug: IPv6 Address Parsing Error

The referringDomain.split(':')[0] logic for port removal incorrectly truncates IPv6 addresses. Since IPv6 addresses contain colons (e.g., 2001:db8::1 or [2001:db8::1]:8080), this method truncates them (e.g., 2001:db8::1 becomes 2001, [2001:db8::1]:8080 becomes [2001), breaking domain exclusion matching for IPv6 hosts.

Locations (1)

Fix in Cursor Fix in Web

);
};

Expand Down
5 changes: 5 additions & 0 deletions packages/analytics-browser/test/attribution/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ describe('isExcludedReferrer', () => {
test('should return true with regexp excluded referrer', () => {
expect(isExcludedReferrer(getDefaultExcludedReferrers('.amplitude.com'), 'data.amplitude.com')).toEqual(true);
});

test('should return true with regexp excluded referrer and domains on different ports', () => {
expect(isExcludedReferrer([/website\.com$/g], 'website.com:5173')).toEqual(true);
expect(isExcludedReferrer([/website\.com$/g], 'website.com')).toEqual(true);
});
});

describe('createCampaignEvent', () => {
Expand Down
Loading
Loading