mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
Add analytics tracking to main process
This commit is contained in:
parent
6a136bd76a
commit
82f1c23a02
@ -1,5 +1,6 @@
|
|||||||
import * as segment from './segment';
|
import * as segment from './segment';
|
||||||
import * as google from './google';
|
import * as google from './google';
|
||||||
|
import {ipcRenderer} from 'electron';
|
||||||
|
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
export async function init (accountId) {
|
export async function init (accountId) {
|
||||||
@ -15,6 +16,10 @@ export async function init (accountId) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Just to be extra safe
|
// Just to be extra safe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ipcRenderer.on('analytics-track-event', (_, args) => {
|
||||||
|
trackEvent(...args);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function trackEvent (...args) {
|
export function trackEvent (...args) {
|
||||||
|
@ -144,6 +144,15 @@ function showUpdateNotification () {
|
|||||||
hasPromptedForUpdates = true;
|
hasPromptedForUpdates = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trackEvent (...args) {
|
||||||
|
const window = BrowserWindow.getFocusedWindow();
|
||||||
|
if (!window || !window.webContents) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.webContents.send('analytics-track-event', args);
|
||||||
|
}
|
||||||
|
|
||||||
function showDownloadModal (version) {
|
function showDownloadModal (version) {
|
||||||
hasPromptedForUpdates = true;
|
hasPromptedForUpdates = true;
|
||||||
|
|
||||||
@ -275,9 +284,23 @@ function createWindow () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.on('resize', e => saveBounds());
|
let _resizeTimeout = null;
|
||||||
mainWindow.on('move', e => saveBounds());
|
mainWindow.on('resize', e => {
|
||||||
mainWindow.on('unresponsive', e => showUnresponsiveModal());
|
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.
|
// and load the app.html of the app.
|
||||||
mainWindow.loadURL(`file://${__dirname}/main.html`);
|
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
|
// in an array if your app supports multi windows, this is the time
|
||||||
// when you should delete the corresponding element.
|
// when you should delete the corresponding element.
|
||||||
mainWindow = null;
|
mainWindow = null;
|
||||||
|
trackEvent('Window', 'Close');
|
||||||
});
|
});
|
||||||
|
|
||||||
require('electron-context-menu')({});
|
require('electron-context-menu')({});
|
||||||
@ -314,6 +338,7 @@ function createWindow () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.webContents.send('toggle-preferences');
|
window.webContents.send('toggle-preferences');
|
||||||
|
trackEvent('App Menu', 'Preferences');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -386,6 +411,7 @@ function createWindow () {
|
|||||||
const zoomFactor = 1;
|
const zoomFactor = 1;
|
||||||
window.webContents.setZoomFactor(zoomFactor);
|
window.webContents.setZoomFactor(zoomFactor);
|
||||||
saveZoomFactor(zoomFactor);
|
saveZoomFactor(zoomFactor);
|
||||||
|
trackEvent('App Menu', 'Zoom Reset');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -401,6 +427,7 @@ function createWindow () {
|
|||||||
window.webContents.setZoomFactor(zoomFactor);
|
window.webContents.setZoomFactor(zoomFactor);
|
||||||
|
|
||||||
saveZoomFactor(zoomFactor);
|
saveZoomFactor(zoomFactor);
|
||||||
|
trackEvent('App Menu', 'Zoom In');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -415,6 +442,7 @@ function createWindow () {
|
|||||||
const zoomFactor = Math.max(0.5, getZoomFactor() - 0.05);
|
const zoomFactor = Math.max(0.5, getZoomFactor() - 0.05);
|
||||||
window.webContents.setZoomFactor(zoomFactor);
|
window.webContents.setZoomFactor(zoomFactor);
|
||||||
saveZoomFactor(zoomFactor);
|
saveZoomFactor(zoomFactor);
|
||||||
|
trackEvent('App Menu', 'Zoom Out');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -427,6 +455,7 @@ function createWindow () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.webContents.send('toggle-sidebar');
|
window.webContents.send('toggle-sidebar');
|
||||||
|
trackEvent('App Menu', 'Toggle Sidebar');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -449,13 +478,15 @@ function createWindow () {
|
|||||||
{
|
{
|
||||||
label: "Contact Support",
|
label: "Contact Support",
|
||||||
click: () => {
|
click: () => {
|
||||||
|
trackEvent('App Menu', 'Contact');
|
||||||
shell.openExternal('mailto:support@insomnia.rest');
|
shell.openExternal('mailto:support@insomnia.rest');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Insomnia Help",
|
label: "Insomnia Help",
|
||||||
accelerator: "CmdOrCtrl+?",
|
accelerator: "CmdOrCtrl+?",
|
||||||
click: () => {
|
click: (e) => {
|
||||||
|
trackEvent('App Menu', 'Help');
|
||||||
shell.openExternal('http://docs.insomnia.rest');
|
shell.openExternal('http://docs.insomnia.rest');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>Insomnia</title>
|
<title>Insomnia</title>
|
||||||
<script>
|
|
||||||
</script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
Loading…
Reference in New Issue
Block a user