Skip to content

Commit 6e4e34a

Browse files
bmeurerDevtools-frontend LUCI CQ
authored andcommitted
Add docs traffic from DevTools must include utm_medium=referral.
This ensures that we also pass `utm_medium` correctly. Fixed: 416414182 Bug: 402611137 Change-Id: Id6945c55df97396072cbe3004c0e745e55f33be9 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6519593 Reviewed-by: Kim-Anh Tran <kimanh@chromium.org> Commit-Queue: Kim-Anh Tran <kimanh@chromium.org> Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
1 parent 9f4644e commit 6e4e34a

File tree

6 files changed

+61
-27
lines changed

6 files changed

+61
-27
lines changed

front_end/models/trace/insights/NetworkDependencyTree.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const UIStrings = {
5757
* @description Description of the table of the detected preconnect origins.
5858
*/
5959
preconnectOriginsTableDescription:
60-
'[preconnect](https://developer.chrome.com/docs/lighthouse/performance/uses-rel-preconnect/?utm_source=lighthouse&utm_medium=devtools) hints help the browser establish a connection earlier in the page load, saving time when the first request for that origin is made. The following are the origins that the page preconnected to.',
60+
'[preconnect](https://developer.chrome.com/docs/lighthouse/performance/uses-rel-preconnect/?utm_source=devtools&utm_medium=referral) hints help the browser establish a connection earlier in the page load, saving time when the first request for that origin is made. The following are the origins that the page preconnected to.',
6161
/**
6262
* @description Text status indicating that there isn't any preconnected origins.
6363
*/
@@ -78,7 +78,7 @@ export const UIStrings = {
7878
* @description Description of the table that recommends preconnecting to the origins to save time.
7979
*/
8080
estSavingTableDescription:
81-
'Add [preconnect](https://developer.chrome.com/docs/lighthouse/performance/uses-rel-preconnect/?utm_source=lighthouse&utm_medium=devtools) hints to your most important origins, but try to use fewer than 4.',
81+
'Add [preconnect](https://developer.chrome.com/docs/lighthouse/performance/uses-rel-preconnect/?utm_source=devtools&utm_medium=referral) hints to your most important origins, but try to use fewer than 4.',
8282
/**
8383
* @description Label for a column in a data table; entries will be the origin of a web resource
8484
*/

front_end/panels/application/ApplicationPanelSidebar.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,7 @@ export class ApplicationPanelSidebar extends UI.Widget.VBox implements SDK.Targe
407407
panel, i18nString(UIStrings.localStorage), i18nString(UIStrings.noLocalStorage),
408408
i18nString(UIStrings.localStorageDescription), 'local-storage');
409409
this.localStorageListTreeElement.setLink(
410-
'https://developer.chrome.com/docs/devtools/storage/localstorage/?utm_source=devtools' as
411-
Platform.DevToolsPath.UrlString);
410+
'https://developer.chrome.com/docs/devtools/storage/localstorage/' as Platform.DevToolsPath.UrlString);
412411
const localStorageIcon = IconButton.Icon.create('table');
413412
this.localStorageListTreeElement.setLeadingIcons([localStorageIcon]);
414413

@@ -417,8 +416,7 @@ export class ApplicationPanelSidebar extends UI.Widget.VBox implements SDK.Targe
417416
panel, i18nString(UIStrings.sessionStorage), i18nString(UIStrings.noSessionStorage),
418417
i18nString(UIStrings.sessionStorageDescription), 'session-storage');
419418
this.sessionStorageListTreeElement.setLink(
420-
'https://developer.chrome.com/docs/devtools/storage/sessionstorage/?utm_source=devtools' as
421-
Platform.DevToolsPath.UrlString);
419+
'https://developer.chrome.com/docs/devtools/storage/sessionstorage/' as Platform.DevToolsPath.UrlString);
422420
const sessionStorageIcon = IconButton.Icon.create('table');
423421
this.sessionStorageListTreeElement.setLeadingIcons([sessionStorageIcon]);
424422

@@ -428,25 +426,22 @@ export class ApplicationPanelSidebar extends UI.Widget.VBox implements SDK.Targe
428426
panel, i18nString(UIStrings.extensionStorage), i18nString(UIStrings.noExtensionStorage),
429427
i18nString(UIStrings.extensionStorageDescription), 'extension-storage');
430428
this.extensionStorageListTreeElement.setLink(
431-
'https://developer.chrome.com/docs/extensions/reference/api/storage/?utm_source=devtools' as
432-
Platform.DevToolsPath.UrlString);
429+
'https://developer.chrome.com/docs/extensions/reference/api/storage/' as Platform.DevToolsPath.UrlString);
433430
const extensionStorageIcon = IconButton.Icon.create('table');
434431
this.extensionStorageListTreeElement.setLeadingIcons([extensionStorageIcon]);
435432

436433
storageTreeElement.appendChild(this.extensionStorageListTreeElement);
437434

438435
this.indexedDBListTreeElement = new IndexedDBTreeElement(panel);
439436
this.indexedDBListTreeElement.setLink(
440-
'https://developer.chrome.com/docs/devtools/storage/indexeddb/?utm_source=devtools' as
441-
Platform.DevToolsPath.UrlString);
437+
'https://developer.chrome.com/docs/devtools/storage/indexeddb/' as Platform.DevToolsPath.UrlString);
442438
storageTreeElement.appendChild(this.indexedDBListTreeElement);
443439

444440
this.cookieListTreeElement = new ExpandableApplicationPanelTreeElement(
445441
panel, i18nString(UIStrings.cookies), i18nString(UIStrings.noCookies), i18nString(UIStrings.cookiesDescription),
446442
'cookies');
447443
this.cookieListTreeElement.setLink(
448-
'https://developer.chrome.com/docs/devtools/storage/cookies/?utm_source=devtools' as
449-
Platform.DevToolsPath.UrlString);
444+
'https://developer.chrome.com/docs/devtools/storage/cookies/' as Platform.DevToolsPath.UrlString);
450445
const cookieIcon = IconButton.Icon.create('cookie');
451446
this.cookieListTreeElement.setLeadingIcons([cookieIcon]);
452447
storageTreeElement.appendChild(this.cookieListTreeElement);

front_end/panels/application/BackgroundServiceView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ export class BackgroundServiceView extends UI.Widget.VBox {
444444
}
445445

446446
private createLearnMoreLink(): Platform.DevToolsPath.UrlString {
447-
let url = 'https://developer.chrome.com/docs/devtools/javascript/background-services/?utm_source=devtools';
447+
let url = 'https://developer.chrome.com/docs/devtools/javascript/background-services/';
448448

449449
switch (this.serviceName) {
450450
case Protocol.BackgroundService.ServiceName.BackgroundFetch:

front_end/panels/application/ServiceWorkerCacheTreeElement.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ export class ServiceWorkerCacheTreeElement extends ExpandableApplicationPanelTre
4949
resourcesPanel, i18nString(UIStrings.cacheStorage), i18nString(UIStrings.noCacheStorage),
5050
i18nString(UIStrings.cacheStorageDescription), 'cache-storage');
5151
const icon = IconButton.Icon.create('database');
52-
this.setLink(
53-
'https://developer.chrome.com/docs/devtools/storage/cache/?utm_source=devtools' as
54-
Platform.DevToolsPath.UrlString);
52+
this.setLink('https://developer.chrome.com/docs/devtools/storage/cache/' as Platform.DevToolsPath.UrlString);
5553
this.setLeadingIcons([icon]);
5654
this.swCacheModels = new Set();
5755
this.swCacheTreeElements = new Set();

front_end/ui/legacy/UIUtils.test.ts

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
// found in the LICENSE file.
44

55
import * as Host from '../../core/host/host.js';
6-
import * as Platform from '../../core/platform/platform.js';
76
import type * as Root from '../../core/root/root.js';
87
import {updateHostConfig} from '../../testing/EnvironmentHelpers.js';
98

109
import * as UI from './legacy.js';
1110

12-
const {urlString} = Platform.DevToolsPath;
13-
1411
describe('UIUtils', () => {
1512
describe('openInNewTab', () => {
1613
const {openInNewTab} = UI.UIUtils;
@@ -45,7 +42,13 @@ describe('UIUtils', () => {
4542

4643
openInNewTab(url);
4744

48-
sinon.assert.calledOnceWithExactly(stub, urlString`${url}`);
45+
sinon.assert.calledOnceWithMatch(stub, sinon.match(value => {
46+
try {
47+
return new URL(value).searchParams.get('utm_source') === 'unittests';
48+
} catch {
49+
return false;
50+
}
51+
}, 'doesn\'t have `utm_source=unittests` search parameter'));
4952
stub.restore();
5053
}
5154
});
@@ -64,8 +67,13 @@ describe('UIUtils', () => {
6467

6568
openInNewTab(url);
6669

67-
sinon.assert.calledOnce(stub);
68-
assert.strictEqual(new URL(stub.args[0][0]).searchParams.get('utm_source'), 'devtools');
70+
sinon.assert.calledOnceWithMatch(stub, sinon.match(value => {
71+
try {
72+
return new URL(value).searchParams.get('utm_source') === 'devtools';
73+
} catch {
74+
return false;
75+
}
76+
}, 'doesn\'t have `utm_source=devtools` search parameter'));
6977
stub.restore();
7078
}
7179
});
@@ -93,13 +101,43 @@ describe('UIUtils', () => {
93101

94102
openInNewTab(url);
95103

96-
sinon.assert.calledOnce(stub);
97-
assert.strictEqual(new URL(stub.args[0][0]).searchParams.get('utm_campaign'), channel);
104+
sinon.assert.calledOnceWithMatch(stub, sinon.match(value => {
105+
try {
106+
return new URL(value).searchParams.get('utm_campaign') === channel;
107+
} catch {
108+
return false;
109+
}
110+
}, `doesn't have \`utm_campaign=${channel}\` search parameter`));
98111
stub.restore();
99112
}
100113
}
101114
});
102115

116+
it('adds `utm_medium=referral` search parameter to Google documentation set links', () => {
117+
const URLs = [
118+
'http://developer.chrome.com/docs/devtools/workspaces/',
119+
'http://developers.google.com/learn/',
120+
'http://web.dev/',
121+
'https://developer.chrome.com/docs/devtools/',
122+
'https://developers.google.com/community/',
123+
'https://web.dev/baseline/',
124+
];
125+
for (const url of URLs) {
126+
const stub = sinon.stub(InspectorFrontendHostInstance, 'openInNewTab');
127+
128+
openInNewTab(url);
129+
130+
sinon.assert.calledOnceWithMatch(stub, sinon.match(value => {
131+
try {
132+
return new URL(value).searchParams.get('utm_medium') === 'referral';
133+
} catch {
134+
return false;
135+
}
136+
}, 'doesn\'t have `utm_medium=referral` search parameter'));
137+
stub.restore();
138+
}
139+
});
140+
103141
it('correctly preserves anchors', () => {
104142
updateHostConfig({channel: 'stable'});
105143
const stub = sinon.stub(InspectorFrontendHostInstance, 'openInNewTab');

front_end/ui/legacy/UIUtils.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,13 +1985,16 @@ export function measuredScrollbarWidth(document?: Document|null): number {
19851985
export function openInNewTab(url: URL|string): void {
19861986
url = new URL(`${url}`);
19871987
if (['developer.chrome.com', 'developers.google.com', 'web.dev'].includes(url.hostname)) {
1988-
if (!url.searchParams.has('utm_source')) {
1989-
url.searchParams.append('utm_source', 'devtools');
1990-
}
19911988
const {channel} = Root.Runtime.hostConfig;
19921989
if (!url.searchParams.has('utm_campaign') && typeof channel === 'string') {
19931990
url.searchParams.append('utm_campaign', channel);
19941991
}
1992+
if (!url.searchParams.has('utm_medium')) {
1993+
url.searchParams.append('utm_medium', 'referral');
1994+
}
1995+
if (!url.searchParams.has('utm_source')) {
1996+
url.searchParams.append('utm_source', 'devtools');
1997+
}
19951998
}
19961999
Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(Platform.DevToolsPath.urlString`${url}`);
19972000
}

0 commit comments

Comments
 (0)