forked from mirrors/gecko-dev
Bug 1851941 - Add UTM params to addon suggestion URLs. r=daisuke
Depends on D187640 Differential Revision: https://phabricator.services.mozilla.com/D187642
This commit is contained in:
parent
b97ac7a1cf
commit
70f2284cda
4 changed files with 72 additions and 9 deletions
|
|
@ -19,6 +19,11 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
|||
UrlbarView: "resource:///modules/UrlbarView.sys.mjs",
|
||||
});
|
||||
|
||||
const UTM_PARAMS = {
|
||||
utm_medium: "firefox-desktop",
|
||||
utm_source: "firefox-suggest",
|
||||
};
|
||||
|
||||
const VIEW_TEMPLATE = {
|
||||
attributes: {
|
||||
selectable: true,
|
||||
|
|
@ -226,9 +231,19 @@ export class AddonSuggestions extends BaseFeature {
|
|||
return null;
|
||||
}
|
||||
|
||||
// Set UTM params unless they're already defined. This allows remote
|
||||
// settings or Merino to override them if need be.
|
||||
let url = new URL(suggestion.url);
|
||||
for (let [key, value] of Object.entries(UTM_PARAMS)) {
|
||||
if (!url.searchParams.has(key)) {
|
||||
url.searchParams.set(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
const payload = {
|
||||
icon: suggestion.icon,
|
||||
url: suggestion.url,
|
||||
url: url.href,
|
||||
originalUrl: suggestion.url,
|
||||
title: suggestion.title,
|
||||
description: suggestion.description,
|
||||
rating: Number(rating),
|
||||
|
|
|
|||
|
|
@ -107,7 +107,8 @@ add_task(async function basic() {
|
|||
const icon = row.querySelector(".urlbarView-dynamic-addons-icon");
|
||||
Assert.equal(icon.src, merinoSuggestion.icon);
|
||||
const url = row.querySelector(".urlbarView-dynamic-addons-url");
|
||||
Assert.equal(url.textContent, merinoSuggestion.url);
|
||||
const expectedUrl = makeExpectedUrl(merinoSuggestion.url);
|
||||
Assert.equal(url.textContent, expectedUrl);
|
||||
const title = row.querySelector(".urlbarView-dynamic-addons-title");
|
||||
Assert.equal(title.textContent, merinoSuggestion.title);
|
||||
const description = row.querySelector(
|
||||
|
|
@ -139,7 +140,7 @@ add_task(async function basic() {
|
|||
const onLoad = BrowserTestUtils.browserLoaded(
|
||||
gBrowser.selectedBrowser,
|
||||
false,
|
||||
merinoSuggestion.url
|
||||
expectedUrl
|
||||
);
|
||||
EventUtils.synthesizeMouseAtCenter(row, {});
|
||||
await onLoad;
|
||||
|
|
@ -502,3 +503,10 @@ async function doDismissTest(command) {
|
|||
|
||||
UrlbarPrefs.clear("suggest.addons");
|
||||
}
|
||||
|
||||
function makeExpectedUrl(originalUrl) {
|
||||
let url = new URL(originalUrl);
|
||||
url.searchParams.set("utm_medium", "firefox-desktop");
|
||||
url.searchParams.set("utm_source", "firefox-suggest");
|
||||
return url.href;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ const MERINO_SUGGESTIONS = [
|
|||
{
|
||||
provider: "amo",
|
||||
icon: "icon",
|
||||
url: "url",
|
||||
url: "https://example.com/merino-addon",
|
||||
title: "title",
|
||||
description: "description",
|
||||
is_top_pick: true,
|
||||
|
|
@ -65,6 +65,16 @@ const REMOTE_SETTINGS_RESULTS = [
|
|||
description: "Description for the Third Addon",
|
||||
number_of_ratings: 3,
|
||||
},
|
||||
{
|
||||
url: "https://example.com/fourth-addon?utm_medium=aaa&utm_source=bbb",
|
||||
guid: "fourth@addon",
|
||||
icon: "https://example.com/fourth-addon.svg",
|
||||
title: "Fourth Addon",
|
||||
rating: "4.7",
|
||||
keywords: ["fourth", "4th"],
|
||||
description: "Description for the Fourth Addon",
|
||||
number_of_ratings: 4,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
|
@ -425,6 +435,15 @@ add_task(async function remoteSettings() {
|
|||
isTopPick: true,
|
||||
}),
|
||||
},
|
||||
{
|
||||
input: "fourth",
|
||||
expected: makeExpectedResult({
|
||||
suggestion: REMOTE_SETTINGS_RESULTS[0].attachment[3],
|
||||
source: "remote-settings",
|
||||
isTopPick: true,
|
||||
setUtmParams: false,
|
||||
}),
|
||||
},
|
||||
];
|
||||
|
||||
// Disable Merino so we trigger only remote settings suggestions.
|
||||
|
|
@ -496,7 +515,12 @@ add_task(async function showLessFrequently() {
|
|||
});
|
||||
});
|
||||
|
||||
function makeExpectedResult({ suggestion, source, isTopPick }) {
|
||||
function makeExpectedResult({
|
||||
suggestion,
|
||||
source,
|
||||
isTopPick,
|
||||
setUtmParams = true,
|
||||
}) {
|
||||
let provider;
|
||||
let rating;
|
||||
let number_of_ratings;
|
||||
|
|
@ -510,6 +534,16 @@ function makeExpectedResult({ suggestion, source, isTopPick }) {
|
|||
number_of_ratings = suggestion.custom_details.amo.number_of_ratings;
|
||||
}
|
||||
|
||||
let url;
|
||||
if (setUtmParams) {
|
||||
url = new URL(suggestion.url);
|
||||
url.searchParams.set("utm_medium", "firefox-desktop");
|
||||
url.searchParams.set("utm_source", "firefox-suggest");
|
||||
url = url.href;
|
||||
} else {
|
||||
url = suggestion.url;
|
||||
}
|
||||
|
||||
return {
|
||||
isBestMatch: isTopPick,
|
||||
suggestedIndex: isTopPick ? 1 : -1,
|
||||
|
|
@ -520,8 +554,9 @@ function makeExpectedResult({ suggestion, source, isTopPick }) {
|
|||
telemetryType: "amo",
|
||||
dynamicType: "addons",
|
||||
title: suggestion.title,
|
||||
url: suggestion.url,
|
||||
displayUrl: suggestion.url.replace(/^https:\/\//, ""),
|
||||
url,
|
||||
originalUrl: suggestion.url,
|
||||
displayUrl: url.replace(/^https:\/\//, ""),
|
||||
icon: suggestion.icon,
|
||||
description: suggestion.description,
|
||||
rating: Number(rating),
|
||||
|
|
|
|||
|
|
@ -744,6 +744,10 @@ function makeExpectedAdmResult({
|
|||
}
|
||||
|
||||
function makeExpectedAddonResult({ suggestion, source = "remote-settings" }) {
|
||||
let url = new URL(suggestion.url);
|
||||
url.searchParams.set("utm_medium", "firefox-desktop");
|
||||
url.searchParams.set("utm_source", "firefox-suggest");
|
||||
|
||||
return {
|
||||
type: UrlbarUtils.RESULT_TYPE.DYNAMIC,
|
||||
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
|
||||
|
|
@ -755,8 +759,9 @@ function makeExpectedAddonResult({ suggestion, source = "remote-settings" }) {
|
|||
telemetryType: "amo",
|
||||
dynamicType: "addons",
|
||||
title: suggestion.title,
|
||||
url: suggestion.url,
|
||||
displayUrl: suggestion.url.replace(/^https:\/\//, ""),
|
||||
url: url.href,
|
||||
originalUrl: suggestion.url,
|
||||
displayUrl: url.href.replace(/^https:\/\//, ""),
|
||||
icon: suggestion.icon,
|
||||
description: suggestion.description,
|
||||
rating: Number(
|
||||
|
|
|
|||
Loading…
Reference in a new issue