Bug 1413844 - add utm parameters to about:devtools links;r=pbro draft
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 09 Nov 2017 19:17:35 +0100
changeset 696405 b54123549878f8f0e571e7dadbfb462559634961
parent 696395 c43d7f7aa0f9de62e406d060bb471fa76ab7e80d
child 696435 fc695f08ca3e2f90b76136ee1a301744fb383de2
push id88707
push userjdescottes@mozilla.com
push dateFri, 10 Nov 2017 17:21:33 +0000
reviewerspbro
bugs1413844
milestone58.0a1
Bug 1413844 - add utm parameters to about:devtools links;r=pbro MozReview-Commit-ID: EjgklOeYQ2g
devtools/shim/aboutdevtools/aboutdevtools.js
--- a/devtools/shim/aboutdevtools/aboutdevtools.js
+++ b/devtools/shim/aboutdevtools/aboutdevtools.js
@@ -18,16 +18,22 @@ const TELEMETRY_NOINSTALL_EXITS = "devto
 const MESSAGES = {
   AboutDebugging: "about-debugging-message",
   ContextMenu: "inspect-element-message",
   HamburgerMenu: "menu-message",
   KeyShortcut: "key-shortcut-message",
   SystemMenu: "menu-message",
 };
 
+// Google analytics parameters that should be added to all outgoing links.
+const GA_PARAMETERS = [
+  ["utm_source", "devtools"],
+  ["utm_medium", "onboarding"],
+];
+
 const ABOUTDEVTOOLS_STRINGS = "chrome://devtools-shim/locale/aboutdevtools.properties";
 const aboutDevtoolsBundle = Services.strings.createBundle(ABOUTDEVTOOLS_STRINGS);
 
 const KEY_SHORTCUTS_STRINGS = "chrome://devtools-shim/locale/key-shortcuts.properties";
 const keyShortcutsBundle = Services.strings.createBundle(KEY_SHORTCUTS_STRINGS);
 
 // URL constructor doesn't support about: scheme,
 // we have to use http in order to have working searchParams.
@@ -181,16 +187,24 @@ window.addEventListener("load", function
   document.getElementById("close").addEventListener("click", onCloseButtonClick);
   Services.prefs.addObserver(DEVTOOLS_ENABLED_PREF, updatePage);
 
   let featuresContainer = document.querySelector(".features-list");
   for (let feature of features) {
     featuresContainer.appendChild(createFeatureEl(feature));
   }
 
+  // Add Google Analytics parameters to all the external links.
+  let externalLinks = [...document.querySelectorAll("a.external")];
+  for (let link of externalLinks) {
+    let linkUrl = new URL(link.getAttribute("href"));
+    GA_PARAMETERS.forEach(([key, value]) => linkUrl.searchParams.set(key, value));
+    link.setAttribute("href", linkUrl.href);
+  }
+
   // Update the current page based on the current value of DEVTOOLS_ENABLED_PREF.
   updatePage();
 
   try {
     if (reason) {
       Services.telemetry.getHistogramById(TELEMETRY_OPENED_REASON).add(reason);
     }