diff --git a/app/analytics/index.js b/app/analytics/index.js index 0d9a022ca0..1a47348ec9 100644 --- a/app/analytics/index.js +++ b/app/analytics/index.js @@ -1,5 +1,6 @@ import * as segment from './segment'; import * as google from './google'; +import {ipcRenderer} from 'electron'; let initialized = false; export async function init (accountId) { @@ -15,6 +16,10 @@ export async function init (accountId) { } catch (e) { // Just to be extra safe } + + ipcRenderer.on('analytics-track-event', (_, args) => { + trackEvent(...args); + }); } export function trackEvent (...args) { diff --git a/app/main.development.js b/app/main.development.js index 4d7a1fecbd..8a0d0c5100 100644 --- a/app/main.development.js +++ b/app/main.development.js @@ -144,6 +144,15 @@ function showUpdateNotification () { hasPromptedForUpdates = true; } +function trackEvent (...args) { + const window = BrowserWindow.getFocusedWindow(); + if (!window || !window.webContents) { + return; + } + + window.webContents.send('analytics-track-event', args); +} + function showDownloadModal (version) { hasPromptedForUpdates = true; @@ -275,9 +284,23 @@ function createWindow () { } }); - mainWindow.on('resize', e => saveBounds()); - mainWindow.on('move', e => saveBounds()); - mainWindow.on('unresponsive', e => showUnresponsiveModal()); + let _resizeTimeout = null; + mainWindow.on('resize', e => { + saveBounds(); + + clearTimeout(_resizeTimeout); + _resizeTimeout = setTimeout(() => { + trackEvent('Window', 'Resize'); + }, 1000); + }); + mainWindow.on('move', e => { + saveBounds(); + trackEvent('Window', 'Move'); + }); + mainWindow.on('unresponsive', e => { + showUnresponsiveModal(); + trackEvent('Window', 'Unresponsive'); + }); // and load the app.html of the app. mainWindow.loadURL(`file://${__dirname}/main.html`); @@ -288,6 +311,7 @@ function createWindow () { // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. mainWindow = null; + trackEvent('Window', 'Close'); }); require('electron-context-menu')({}); @@ -314,6 +338,7 @@ function createWindow () { } window.webContents.send('toggle-preferences'); + trackEvent('App Menu', 'Preferences'); } }, { @@ -386,6 +411,7 @@ function createWindow () { const zoomFactor = 1; window.webContents.setZoomFactor(zoomFactor); saveZoomFactor(zoomFactor); + trackEvent('App Menu', 'Zoom Reset'); } }, { @@ -401,6 +427,7 @@ function createWindow () { window.webContents.setZoomFactor(zoomFactor); saveZoomFactor(zoomFactor); + trackEvent('App Menu', 'Zoom In'); } }, { @@ -415,6 +442,7 @@ function createWindow () { const zoomFactor = Math.max(0.5, getZoomFactor() - 0.05); window.webContents.setZoomFactor(zoomFactor); saveZoomFactor(zoomFactor); + trackEvent('App Menu', 'Zoom Out'); } }, { @@ -427,6 +455,7 @@ function createWindow () { } window.webContents.send('toggle-sidebar'); + trackEvent('App Menu', 'Toggle Sidebar'); } } ] @@ -449,13 +478,15 @@ function createWindow () { { label: "Contact Support", click: () => { + trackEvent('App Menu', 'Contact'); shell.openExternal('mailto:support@insomnia.rest'); } }, { label: "Insomnia Help", accelerator: "CmdOrCtrl+?", - click: () => { + click: (e) => { + trackEvent('App Menu', 'Help'); shell.openExternal('http://docs.insomnia.rest'); } } diff --git a/app/main.html b/app/main.html index 4bac4c04b4..2dd176d476 100644 --- a/app/main.html +++ b/app/main.html @@ -3,8 +3,6 @@