2016-11-10 01:34:03 +00:00
|
|
|
import * as google from './google';
|
2016-11-23 19:49:10 +00:00
|
|
|
import {ipcRenderer} from 'electron';
|
2016-12-05 22:42:40 +00:00
|
|
|
import {getAppVersion, getAppPlatform} from '../common/constants';
|
2016-11-10 01:34:03 +00:00
|
|
|
|
2016-11-10 19:08:45 +00:00
|
|
|
let initialized = false;
|
2016-11-16 18:16:55 +00:00
|
|
|
export async function init (accountId) {
|
2016-11-10 19:08:45 +00:00
|
|
|
if (initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-21 23:37:48 +00:00
|
|
|
await google.init(accountId, getAppPlatform(), getAppVersion());
|
2016-11-10 19:08:45 +00:00
|
|
|
|
2016-12-21 23:37:48 +00:00
|
|
|
initialized = true;
|
2016-11-23 19:49:10 +00:00
|
|
|
|
|
|
|
ipcRenderer.on('analytics-track-event', (_, args) => {
|
|
|
|
trackEvent(...args);
|
|
|
|
});
|
2016-11-10 01:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function trackEvent (...args) {
|
2016-12-08 17:20:10 +00:00
|
|
|
// Do on next tick in case it fails or blocks
|
|
|
|
process.nextTick(() => {
|
2016-11-17 21:22:19 +00:00
|
|
|
google.sendEvent(...args);
|
2016-12-08 17:20:10 +00:00
|
|
|
});
|
2016-11-10 01:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function setAccountId (accountId) {
|
2016-12-08 17:20:10 +00:00
|
|
|
// Do on next tick in case it fails or blocks
|
|
|
|
process.nextTick(() => {
|
2016-11-17 21:22:19 +00:00
|
|
|
google.setUserId(accountId);
|
2016-12-08 17:20:10 +00:00
|
|
|
});
|
2016-11-10 01:34:03 +00:00
|
|
|
}
|