Bug 1515153 - make osx attributions work with both utm and plain params, r=mossop

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Shane Caraveo 2018-12-21 16:46:20 +00:00
Родитель 5b6cacf4cc
Коммит e194dff2bf
2 изменённых файлов: 14 добавлений и 7 удалений

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

@ -98,11 +98,14 @@ var AttributionCode = {
let referrer = attributionSvc.getReferrerUrl(appPath);
let params = new URL(referrer).searchParams;
for (let key of ATTR_CODE_KEYS) {
let utm_key = `utm_${key}`;
if (params.has(utm_key)) {
let value = params.get(utm_key);
if (value && ATTR_CODE_VALUE_REGEX.test(value)) {
gCachedAttrData[key] = value;
// We support the key prefixed with utm_ or not, but intentionally
// choose non-utm params over utm params.
for (let paramKey of [`utm_${key}`, key]) {
if (params.has(paramKey)) {
let value = params.get(paramKey);
if (value && ATTR_CODE_VALUE_REGEX.test(value)) {
gCachedAttrData[key] = value;
}
}
}
}

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

@ -5,6 +5,7 @@
"use strict";
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource:///modules/AttributionCode.jsm");
add_task(async function test_attribution() {
let appPath = Services.dirsvc.get("GreD", Ci.nsIFile).parent.parent.path;
@ -15,8 +16,8 @@ add_task(async function test_attribution() {
let referrer = attributionSvc.getReferrerUrl(appPath);
equal(referrer, "", "force an empty referrer url");
// Set a url referrer
let url = "http://example.com";
// Set a url referrer, testing both utm and non-utm codes
let url = "http://example.com?content=foo&utm_source=bar&utm_content=baz";
attributionSvc.setReferrerUrl(appPath, url, true);
referrer = attributionSvc.getReferrerUrl(appPath);
equal(referrer, url, "overwrite referrer url");
@ -25,4 +26,7 @@ add_task(async function test_attribution() {
attributionSvc.setReferrerUrl(appPath, "http://test.com", false);
referrer = attributionSvc.getReferrerUrl(appPath);
equal(referrer, url, "referrer url is not changed");
let result = await AttributionCode.getAttrDataAsync();
Assert.deepEqual(result, {content: "foo", source: "bar"}, "parsed attributes match");
});