Bug 1515153 - make osx attributions work with both utm and plain params, r=mossop
authorShane Caraveo <scaraveo@mozilla.com>
Fri, 21 Dec 2018 16:46:20 +0000
changeset 451689 fc056f8fe673616637f3dee8888bbabd55927aec
parent 451688 9ce856703a5a3a5a84b61f86f149c75109e863be
child 451690 2f98a1c651b314896f199db5083f01284d89889a
push id35251
push userccoroiu@mozilla.com
push dateFri, 21 Dec 2018 21:54:30 +0000
treeherdermozilla-central@74101900e7d4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1515153
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1515153 - make osx attributions work with both utm and plain params, r=mossop Differential Revision: https://phabricator.services.mozilla.com/D14884
browser/components/attribution/AttributionCode.jsm
browser/components/attribution/test/xpcshell/test_attribution.js
--- a/browser/components/attribution/AttributionCode.jsm
+++ b/browser/components/attribution/AttributionCode.jsm
@@ -93,21 +93,24 @@ var AttributionCode = {
       } else if (AppConstants.platform == "macosx") {
         try {
           let appPath = Services.dirsvc.get("GreD", Ci.nsIFile).parent.parent.path;
           let attributionSvc = Cc["@mozilla.org/mac-attribution;1"]
                                   .getService(Ci.nsIMacAttributionService);
           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;
+                }
               }
             }
           }
         } catch (ex) {
           // No attributions
         }
       }
       return gCachedAttrData;
--- a/browser/components/attribution/test/xpcshell/test_attribution.js
+++ b/browser/components/attribution/test/xpcshell/test_attribution.js
@@ -1,28 +1,32 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 "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;
   let attributionSvc = Cc["@mozilla.org/mac-attribution;1"]
                          .getService(Ci.nsIMacAttributionService);
 
   attributionSvc.setReferrerUrl(appPath, "", true);
   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");
 
   // Does not overwrite existing properties.
   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");
 });