Merge "Add tracking on keyboard shortcut usage"
diff --git a/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html b/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html
index 33561d4..97c792a 100644
--- a/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html
+++ b/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html
@@ -524,6 +524,11 @@
         for (let i = 0; e.path && i < e.path.length; i++) {
           if (e.path[i].tagName === 'GR-OVERLAY') { return true; }
         }
+
+        this.fire('shortcut-triggered', {
+          event: e,
+          goKey: this._inGoKeyMode(),
+        });
         return false;
       },
 
@@ -610,10 +615,14 @@
         this._shortcut_go_key_last_pressed = null;
       },
 
+      _inGoKeyMode() {
+        return this._shortcut_go_key_last_pressed &&
+            (Date.now() - this._shortcut_go_key_last_pressed <=
+                GO_KEY_TIMEOUT_MS);
+      },
+
       _handleGoAction(e) {
-        if (!this._shortcut_go_key_last_pressed ||
-            (Date.now() - this._shortcut_go_key_last_pressed >
-                GO_KEY_TIMEOUT_MS) ||
+        if (!this._inGoKeyMode() ||
             !this._shortcut_go_table.has(e.detail.key) ||
             this.shouldSuppressKeyboardShortcut(e)) {
           return;
diff --git a/polygerrit-ui/app/elements/gr-app-element.js b/polygerrit-ui/app/elements/gr-app-element.js
index e9b994d..7e62b9d 100644
--- a/polygerrit-ui/app/elements/gr-app-element.js
+++ b/polygerrit-ui/app/elements/gr-app-element.js
@@ -136,6 +136,8 @@
           e => this._handleLocationChange(e));
       this.addEventListener('rpc-log',
           e => this._handleRpcLog(e));
+      this.addEventListener('shortcut-triggered',
+          e => this._handleShortcutTriggered(e));
     }
 
     /** @override */
@@ -366,6 +368,22 @@
       this.$.header.unfloat();
     }
 
+    _handleShortcutTriggered(event) {
+      const {event: e, goKey} = event.detail;
+      // eg: {key: "k:keydown", ..., from: "gr-diff-view"}
+      let key = `${e.key}:${e.type}`;
+      if (goKey) key = 'g+' + key;
+      if (e.shiftKey) key = 'shift+' + key;
+      if (e.ctrlKey) key = 'ctrl+' + key;
+      if (e.metaKey) key = 'meta+' + key;
+      if (e.altKey) key = 'alt+' + key;
+      this.$.reporting.reportInteraction('shortcut-triggered', {
+        key,
+        from: event.path && event.path[0]
+          && event.path[0].nodeName || 'unknown',
+      });
+    }
+
     _handlePageError(e) {
       const props = [
         '_showChangeListView',