Bug 1515153 - Make osx attributions work with both utm and plain params. r=mossop, a=RyanVM
authorShane Caraveo <scaraveo@mozilla.com>
Fri, 21 Dec 2018 16:46:20 +0000
changeset 509163 d47021d7e1bc85218b5753acae4a2d9446981392
parent 509162 f8cd4d3f58883d56ebfb750ce2f7d277a3949841
child 509164 d67ea56c71a28696c059691f5779916d72f6bc97
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop, RyanVM
bugs1515153
milestone65.0
Bug 1515153 - Make osx attributions work with both utm and plain params. r=mossop, a=RyanVM 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");
 });