Add tracking on keyboard shortcut usage
Change-Id: Iba518b7c3505ec3183994575e5cb3e158cf32395
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 495f8ab..db979f5 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
@@ -511,6 +511,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;
},
@@ -591,10 +596,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 c1e317a..3dc3dc9 100644
--- a/polygerrit-ui/app/elements/gr-app-element.js
+++ b/polygerrit-ui/app/elements/gr-app-element.js
@@ -127,6 +127,8 @@
e => this._handleLocationChange(e));
this.addEventListener('rpc-log',
e => this._handleRpcLog(e));
+ this.addEventListener('shortcut-triggered',
+ e => this._handleShortcutTriggered(e));
}
/** @override */
@@ -356,6 +358,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',