Bug 1546248 - Add attribution parameters to AMO links r=mstriemer

Differential Revision: https://phabricator.services.mozilla.com/D29479

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Rob Wu 2019-05-09 14:22:17 +00:00
Родитель 07b06b75fa
Коммит 163dcef402
2 изменённых файлов: 36 добавлений и 5 удалений

Просмотреть файл

@ -162,6 +162,31 @@ function nl2br(text) {
return frag;
}
/**
* Adds UTM parameters to a given URL, if it is an AMO URL.
*
* @param {string} contentAttribute
* Identifies the part of the UI with which the link is associated.
* @param {string} url
* @returns {string}
* The url with UTM parameters if it is an AMO URL.
* Otherwise the url in unmodified form.
*/
function formatAmoUrl(contentAttribute, url) {
let parsedUrl = new URL(url);
let domain = `.${parsedUrl.hostname}`;
if (!domain.endsWith(".addons.mozilla.org") &&
// For testing: addons-dev.allizom.org and addons.allizom.org
!domain.endsWith(".allizom.org")) {
return url;
}
parsedUrl.searchParams.set("utm_source", "firefox-browser");
parsedUrl.searchParams.set("utm_medium", "firefox-browser");
parsedUrl.searchParams.set("utm_content", contentAttribute);
return parsedUrl.href;
}
// A wrapper around an item from the "results" array from AMO's discovery API.
// See https://addons-server.readthedocs.io/en/latest/topics/api/discovery.html
class DiscoAddonWrapper {
@ -1182,7 +1207,8 @@ class RecommendedAddonCard extends HTMLElement {
});
// This is intentionally a link to the add-on listing instead of the
// author page, because the add-on listing provides more relevant info.
authorInfo.querySelector("a").href = addon.amoListingUrl;
authorInfo.querySelector("a").href =
formatAmoUrl("discopane-entry-link", addon.amoListingUrl);
authorInfo.hidden = false;
}
}
@ -1698,9 +1724,10 @@ class DiscoveryPane extends HTMLElement {
"personalized-extension-recommendations", "tab");
break;
case "open-amo":
windowRoot.ownerGlobal.openTrustedLinkIn(
Services.urlFormatter.formatURLPref("extensions.getAddons.link.url"),
"tab");
let amoUrl =
Services.urlFormatter.formatURLPref("extensions.getAddons.link.url");
amoUrl = formatAmoUrl("find-more-link-bottom", amoUrl);
windowRoot.ownerGlobal.openTrustedLinkIn(amoUrl, "tab");
break;
}
}

Просмотреть файл

@ -21,7 +21,7 @@ const {
// The response must contain at least one theme, and one extension.
const API_RESPONSE_FILE = RELATIVE_DIR + "discovery/api_response.json";
const AMO_TEST_HOST = "addons.example.com";
const AMO_TEST_HOST = "rewritten-for-testing.addons.allizom.org";
const ArrayBufferInputStream =
Components.Constructor("@mozilla.org/io/arraybuffer-input-stream;1",
@ -320,6 +320,10 @@ add_task(async function discopane_with_real_api_data() {
checkContent(".disco-addon-author [data-l10n-name='author']",
expectations.authorName);
let amoListingLink = card.querySelector(".disco-addon-author a");
ok(amoListingLink.search.includes("utm_source=firefox-browser"),
`Listing link should have attribution parameter, url=${amoListingLink}`);
let actions = getVisibleActions(card);
is(actions.length, 1, "Card should only have one install button");
let installButton = actions[0];