Skip to content

Commit

Permalink
report: add utm params to web.dev links (#9555)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish authored Aug 14, 2019
1 parent 5eb01d6 commit 506134b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lighthouse-core/report/html/renderer/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ class DOM {
// Otherwise, append any links found.
const url = new URL(segment.linkHref);

const DEVELOPERS_GOOGLE_ORIGIN = 'https://developers.google.com';
if (url.origin === DEVELOPERS_GOOGLE_ORIGIN) {
const DOCS_ORIGINS = ['https://developers.google.com', 'https://web.dev'];
if (DOCS_ORIGINS.includes(url.origin)) {
url.searchParams.set('utm_source', 'lighthouse');
url.searchParams.set('utm_medium', this._lighthouseChannel);
}
Expand Down
9 changes: 8 additions & 1 deletion lighthouse-core/test/report/html/renderer/dom-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ describe('DOM', () => {
assert.equal(result.innerHTML, '<a rel="noopener" target="_blank" href="https://developers.google.com/web/tools/lighthouse/audits/description?utm_source=lighthouse&amp;utm_medium=someChannel">Learn more</a>.');
});

it('doesn\'t append utm params to non https://developers.google.com origins', () => {
it('appends utm params to the URLs with https://web.dev origin', () => {
const text = '[Learn more](https://web.dev/tap-targets/).';

const result = dom.convertMarkdownLinkSnippets(text);
assert.equal(result.innerHTML, '<a rel="noopener" target="_blank" href="https://web.dev/tap-targets/?utm_source=lighthouse&amp;utm_medium=someChannel">Learn more</a>.');
});

it('doesn\'t append utm params to other (non-docs) origins', () => {
const text = '[Learn more](https://example.com/info).';

const result = dom.convertMarkdownLinkSnippets(text);
Expand Down

0 comments on commit 506134b

Please sign in to comment.