-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Not saving click data for internal links when sub-domain changes
- Loading branch information
1 parent
a534bde
commit e8aeaa4
Showing
5 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/components/ActivityCollector/utils/dom/extractDomain.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
Copyright 2024 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
export default uri => { | ||
let fullUrl = uri; | ||
if (!/^https?:\/\//i.test(fullUrl)) { | ||
fullUrl = `${window.location.protocol}//${uri}`; | ||
} | ||
const url = new URL(fullUrl); | ||
return url.hostname; | ||
}; |
19 changes: 19 additions & 0 deletions
19
src/components/ActivityCollector/utils/isDifferentDomains.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
Copyright 2024 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
import extractDomain from "./dom/extractDomain"; | ||
|
||
export default (uri1, uri2) => { | ||
const domain1 = extractDomain(uri1); | ||
const domain2 = extractDomain(uri2); | ||
return domain1 !== domain2; | ||
}; |
32 changes: 32 additions & 0 deletions
32
test/unit/specs/components/ActivityCollector/utils/dom/extractDomain.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Copyright 2024 example. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
import extractDomain from "../../../../../../../src/components/ActivityCollector/utils/dom/extractDomain"; | ||
|
||
describe("ActivityCollector::extractDomain", () => { | ||
it("should extract the domain from a URL", () => { | ||
expect(extractDomain("www.example.com")).toBe("www.example.com"); | ||
expect(extractDomain("http://www.example.com")).toBe("www.example.com"); | ||
expect(extractDomain("https://www.example.com")).toBe("www.example.com"); | ||
expect(extractDomain("https://www.example.com/")).toBe("www.example.com"); | ||
expect(extractDomain("https://www.example.com/cool/page")).toBe( | ||
"www.example.com" | ||
); | ||
}); | ||
|
||
it("should handle URLs without a protocol", () => { | ||
expect(extractDomain("example.com")).toBe("example.com"); | ||
expect(extractDomain("www.example.com")).toBe("www.example.com"); | ||
expect(extractDomain("www.example.com/")).toBe("www.example.com"); | ||
expect(extractDomain("www.example.com/cool/page")).toBe("www.example.com"); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
test/unit/specs/components/ActivityCollector/utils/isDifferentDomains.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Copyright 2024 example. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
import isDifferentDomains from "../../../../../../src/components/ActivityCollector/utils/isDifferentDomains"; | ||
|
||
describe("ActivityCollector::isDifferentDomains", () => { | ||
it("should return true if the domains are different", () => { | ||
expect(isDifferentDomains("www.example.com", "www.example.org")).toBe(true); | ||
}); | ||
|
||
it("should return false if the domains are the same", () => { | ||
expect( | ||
isDifferentDomains("https://www.example.com", "www.example.com") | ||
).toBe(false); | ||
expect(isDifferentDomains("www.example.com", "www.example.com")).toBe( | ||
false | ||
); | ||
}); | ||
}); |