mirror of
https://github.com/Kong/insomnia.git
synced 2026-10-26 08:38:58 -04:00
Add user id to google analytics, and more analytics
This commit is contained in:
1 parent
12b2fb1a30
commit
2833698736
8 files changed
+49
-13
No files matched your search
@@ -3,7 +3,7 @@ import {isDevelopment} from './appInfo';
|
||||
|
||||
let _sessionId = null;
|
||||
|
||||
export function initAnalytics () {
|
||||
export function initAnalytics (accountId = null) {
|
||||
if (isDevelopment()) {
|
||||
console.log('-- Not initializing analytics for dev --');
|
||||
return;
|
||||
@@ -19,7 +19,10 @@ export function initAnalytics () {
|
||||
|
||||
const _sessionId = window.localStorage['gaClientId'];
|
||||
|
||||
window.ga('create', constants.GA_ID, {'storage': 'none', 'clientId': _sessionId});
|
||||
window.ga('create', constants.GA_ID, {
|
||||
'storage': 'none',
|
||||
'clientId': _sessionId
|
||||
});
|
||||
|
||||
// Disable URL protocol check
|
||||
window.ga('set', 'checkProtocolTask', () => null);
|
||||
@@ -30,9 +33,17 @@ export function initAnalytics () {
|
||||
// Track the initial page view
|
||||
window.ga('send', 'pageview');
|
||||
|
||||
if (accountId) {
|
||||
setAccountId(accountId);
|
||||
}
|
||||
|
||||
console.log(`-- Analytics Initialized for ${_sessionId} --`);
|
||||
}
|
||||
|
||||
export function setAccountId (accountId) {
|
||||
window.ga('set', 'userId', accountId);
|
||||
}
|
||||
|
||||
export function trackEvent (category, action, label) {
|
||||
window.ga && window.ga('send', 'event', category, action, label);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import srp from 'srp';
|
||||
import * as crypt from './crypt';
|
||||
import * as util from './util';
|
||||
import * as ganalytics from '../ganalytics';
|
||||
import {trackEvent} from '../ganalytics';
|
||||
|
||||
const NO_SESSION = '__NO_SESSION__';
|
||||
|
||||
@@ -43,7 +45,11 @@ export async function signup (firstName, lastName, rawEmail, rawPassphrase) {
|
||||
account.encPrivateKey = JSON.stringify(encPrivateJWKMessage);
|
||||
account.encSymmetricKey = JSON.stringify(encSymmetricJWKMessage);
|
||||
|
||||
return util.fetchPost('/auth/signup', account);
|
||||
const response = await util.fetchPost('/auth/signup', account);
|
||||
|
||||
trackEvent('Session', 'Signup');
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +136,11 @@ export async function login (rawEmail, rawPassphrase) {
|
||||
JSON.parse(publicKey),
|
||||
JSON.parse(encPrivateKey),
|
||||
);
|
||||
|
||||
// Set the ID for Google Analytics
|
||||
ganalytics.setAccountId(accountId);
|
||||
|
||||
trackEvent('Session', 'Login');
|
||||
}
|
||||
|
||||
export function getPublicKey () {
|
||||
@@ -232,6 +243,7 @@ export function isLoggedIn () {
|
||||
export async function logout () {
|
||||
await util.fetchPost('/auth/logout');
|
||||
unsetSessionData();
|
||||
trackEvent('Session', 'Logout');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -62,16 +62,16 @@ class ResponsePane extends Component {
|
||||
|
||||
remote.dialog.showSaveDialog(options, filename => {
|
||||
if (!filename) {
|
||||
trackEvent('Save Response', 'Cancel');
|
||||
trackEvent('Response', 'Save', 'Cancel');
|
||||
return;
|
||||
}
|
||||
|
||||
fs.writeFile(filename, bodyBuffer, {}, err => {
|
||||
if (err) {
|
||||
console.warn('Failed to save response body', err);
|
||||
trackEvent('Save Response', 'Failure');
|
||||
trackEvent('Response', 'Save', 'Failure');
|
||||
} else {
|
||||
trackEvent('Save Response', 'Success');
|
||||
trackEvent('Response', 'Save', 'Success');
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ import * as session from '../../../backend/sync/session';
|
||||
import {getModal} from './index';
|
||||
import SignupModal from './SignupModal';
|
||||
import * as sync from '../../../backend/sync';
|
||||
import {trackEvent} from '../../../backend/ganalytics';
|
||||
|
||||
class LoginModal extends Component {
|
||||
constructor (props) {
|
||||
@@ -35,7 +36,7 @@ class LoginModal extends Component {
|
||||
|
||||
this.setState({step: 2, loading: false});
|
||||
} catch (e) {
|
||||
this.setState({error: e.message, loading: false})
|
||||
this.setState({error: e.message, loading: false});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +44,8 @@ class LoginModal extends Component {
|
||||
e.preventDefault();
|
||||
|
||||
this.modal.hide();
|
||||
getModal(SignupModal).show()
|
||||
getModal(SignupModal).show();
|
||||
trackEvent('Auth', 'Login', 'Switch');
|
||||
}
|
||||
|
||||
show () {
|
||||
|
||||
@@ -6,7 +6,6 @@ import ModalHeader from '../base/ModalHeader';
|
||||
import ModalBody from '../base/ModalBody';
|
||||
import MethodTag from '../tags/MethodTag';
|
||||
import * as db from '../../../backend/database';
|
||||
import {trackLegacyEvent} from '../../../backend/analytics';
|
||||
|
||||
|
||||
class RequestSwitcherModal extends Component {
|
||||
@@ -165,7 +164,6 @@ class RequestSwitcherModal extends Component {
|
||||
}
|
||||
|
||||
show () {
|
||||
trackEvent('Modal', 'Show', 'Quick Switcher');
|
||||
this.modal.show();
|
||||
this._handleChange('');
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import * as session from '../../../backend/sync/session';
|
||||
import {getModal} from './index';
|
||||
import LoginModal from './LoginModal';
|
||||
import * as sync from '../../../backend/sync';
|
||||
import {trackEvent} from '../../../backend/ganalytics';
|
||||
|
||||
class SignupModal extends Component {
|
||||
constructor (props) {
|
||||
@@ -33,7 +34,7 @@ class SignupModal extends Component {
|
||||
this.setState({step: 2, loading: false});
|
||||
sync.initSync();
|
||||
} catch (e) {
|
||||
this.setState({error: e.message, loading: false})
|
||||
this.setState({error: e.message, loading: false});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +42,8 @@ class SignupModal extends Component {
|
||||
e.preventDefault();
|
||||
|
||||
this.modal.hide();
|
||||
getModal(LoginModal).show()
|
||||
getModal(LoginModal).show();
|
||||
trackEvent('Auth', 'Signup', 'Switch');
|
||||
}
|
||||
|
||||
show () {
|
||||
|
||||
@@ -11,6 +11,7 @@ import * as session from '../../../backend/sync/session';
|
||||
import * as syncStorage from '../../../backend/sync/storage';
|
||||
import * as sync from '../../../backend/sync';
|
||||
import * as db from '../../../backend/database';
|
||||
import {trackEvent} from '../../../backend/ganalytics';
|
||||
|
||||
class SyncModal extends Component {
|
||||
constructor (props) {
|
||||
@@ -40,6 +41,8 @@ class SyncModal extends Component {
|
||||
this.setState({pushingResourceGroups});
|
||||
|
||||
await this._updateModal();
|
||||
|
||||
trackEvent('Sync', 'Push');
|
||||
}
|
||||
|
||||
async _handlePullResourceGroupId (resourceGroupId) {
|
||||
@@ -56,6 +59,8 @@ class SyncModal extends Component {
|
||||
this.setState({pullingResourceGroups});
|
||||
|
||||
await this._updateModal();
|
||||
|
||||
trackEvent('Sync', 'Pull');
|
||||
}
|
||||
|
||||
async _handleSyncModeChange (syncData, e) {
|
||||
@@ -68,10 +73,13 @@ class SyncModal extends Component {
|
||||
|
||||
// Trigger a sync cycle right away
|
||||
await sync.triggerSync();
|
||||
|
||||
trackEvent('Sync', 'Change Mode', syncMode);
|
||||
}
|
||||
|
||||
async _handleReset () {
|
||||
this.hide();
|
||||
trackEvent('Sync', 'Reset');
|
||||
await session.logout();
|
||||
await sync.resetLocalData();
|
||||
await sync.resetRemoteData();
|
||||
|
||||
+4
-1
@@ -17,6 +17,7 @@ import {initSync} from '../backend/sync';
|
||||
import {getAppVersion} from '../backend/appInfo';
|
||||
import {initLegacyAnalytics} from '../backend/analytics';
|
||||
import {initAnalytics} from '../backend/ganalytics';
|
||||
import * as session from '../backend/sync/session';
|
||||
|
||||
// Don't inject component styles (use our own)
|
||||
Tabs.setUseDefaultStyles(false);
|
||||
@@ -25,11 +26,13 @@ export const store = createStore();
|
||||
|
||||
console.log(`-- Loading App v${getAppVersion()} --`);
|
||||
|
||||
const accountId = session.getAccountId();
|
||||
|
||||
(async function () {
|
||||
await initDB();
|
||||
await initSync();
|
||||
await initStore(store.dispatch);
|
||||
await initAnalytics();
|
||||
await initAnalytics(accountId);
|
||||
await initLegacyAnalytics();
|
||||
console.log('-- Rendering App --');
|
||||
render(
|
||||
|
||||
Reference in new issue
Block a user