Skip to content

Conversation

daniel-graham-amplitude
Copy link
Collaborator

Summary

  • Add a test page for Marketing Attribution
  • Make a small fix to exclude the "port" when checking if a domain matches "excludeReferrer"

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

Copy link
Contributor

@Copilot Copilot AI left a 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 a test page for Marketing Attribution functionality and fixes a domain matching issue in the isExcludedReferrer function. The fix ensures that domains with ports are properly handled when checking against excluded referrer patterns.

  • Added a comprehensive HTML test page for testing marketing attribution with various UTM parameters and scenarios
  • Fixed port handling in referrer domain exclusion logic by stripping port numbers before comparison
  • Added test coverage for the port handling fix

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test-server/autocapture/marketing-attribution.html New test page with UI for testing marketing attribution functionality
packages/analytics-browser/src/attribution/helpers.ts Fixed isExcludedReferrer to strip ports from domains before comparison
packages/analytics-browser/test/attribution/helpers.test.ts Added test cases for port handling in referrer exclusion

Comment on lines +65 to +67
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,
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

promptless bot commented Jul 28, 2025

✅ No documentation updates required.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Comment bugbot run to trigger another review on this PR

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,
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

@daniel-graham-amplitude daniel-graham-amplitude changed the title fix build issues related to types fix(analytics-browser): exclude "port" when checking "excludeReferrer" in marketing attribution Jul 28, 2025
@Mercy811
Copy link
Contributor

Mercy811 commented Aug 4, 2025

Hi @daniel-graham-amplitude, is this from a customer ticket? http's default port is 80 and https default port is 443. Most of the time, in production, URL has no port. A port appears in a url usually for development or testing. If you're supporting this, we should also fix the ipv6 parsing error.

@daniel-graham-amplitude
Copy link
Collaborator Author

@Mercy811 this is just for development purposes. I was trying to test out attribution to see how excludeReferrer works and it wasn't working because of the port issue. I'll move this to draft for now and pick it up later as it isn't a high priority.

@daniel-graham-amplitude daniel-graham-amplitude marked this pull request as draft August 5, 2025 16:18
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