Unite the analytics!

This commit is contained in:
Gregory Schier 2016-11-09 17:34:03 -08:00
parent 073dfd3ada
commit b4ebc21b53
13 changed files with 45 additions and 32 deletions

View File

@ -1,9 +1,9 @@
import * as constants from './constants'; import * as constants from '../constants';
import {isDevelopment} from './appInfo'; import {isDevelopment} from '../appInfo';
let _sessionId = null; let _sessionId = null;
export function initAnalytics (accountId = null) { export function init (accountId = null) {
if (isDevelopment()) { if (isDevelopment()) {
console.log('-- Not initializing analytics for dev --'); console.log('-- Not initializing analytics for dev --');
return; return;
@ -63,5 +63,5 @@ function _injectGoogleAnalyticsScript () {
a.async = 1; a.async = 1;
a.src = g; a.src = g;
m.parentNode.insertBefore(a, m) m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga'); })(window, document, 'script', 'https://www.google-analytics.com/segment.js', 'ga');
} }

View File

@ -0,0 +1,19 @@
import * as segment from './segment';
import * as google from './google';
export function initAnalytics(accountId) {
segment.init();
google.init(accountId);
}
export function trackEvent (...args) {
google.trackEvent(...args)
}
export function setAccountId (accountId) {
google.setAccountId(accountId);
}
export function trackLegacyEvent (event, properties) {
segment.trackLegacyEvent(event, properties)
}

View File

@ -1,13 +1,13 @@
import Analytics from 'analytics-node'; import Analytics from 'analytics-node';
import {getAppVersion} from './appInfo'; import {getAppVersion} from '../appInfo';
import {SEGMENT_WRITE_KEY} from './constants'; import {SEGMENT_WRITE_KEY} from '../constants';
import {isDevelopment} from './appInfo'; import {isDevelopment} from '../appInfo';
import * as models from './models'; import * as models from '../models';
let analytics = null; let analytics = null;
let userId = null; let userId = null;
export async function initLegacyAnalytics () { export async function init () {
if (isDevelopment()) { if (isDevelopment()) {
console.log('-- Not initializing Legacy analytics in dev --'); console.log('-- Not initializing Legacy analytics in dev --');
return; return;
@ -20,7 +20,7 @@ export async function initLegacyAnalytics () {
userId = stats._id; userId = stats._id;
// Recurse now that we have a userId // Recurse now that we have a userId
return await initLegacyAnalytics(); return await init();
} }
analytics.identify({ analytics.identify({

View File

@ -1,7 +1,7 @@
import srp from 'srp'; import srp from 'srp';
import * as crypt from './crypt'; import * as crypt from './crypt';
import * as util from '../backend/fetch'; import * as util from '../backend/fetch';
import * as analytics from '../backend/ganalytics'; import {trackEvent, setAccountId} from '../backend/analytics';
const NO_SESSION = '__NO_SESSION__'; const NO_SESSION = '__NO_SESSION__';
@ -46,7 +46,7 @@ export async function signup (firstName, lastName, rawEmail, rawPassphrase) {
const response = await util.post('/auth/signup', account); const response = await util.post('/auth/signup', account);
analytics.trackEvent('Session', 'Signup'); trackEvent('Session', 'Signup');
return response; return response;
} }
@ -139,8 +139,8 @@ export async function login (rawEmail, rawPassphrase) {
); );
// Set the ID for Google Analytics // Set the ID for Google Analytics
analytics.setAccountId(accountId); setAccountId(accountId);
analytics.trackEvent('Session', 'Login'); trackEvent('Session', 'Login');
} }
export async function subscribe (tokenId, planId) { export async function subscribe (tokenId, planId) {
@ -149,7 +149,7 @@ export async function subscribe (tokenId, planId) {
quantity: 1, quantity: 1,
plan: planId, plan: planId,
}); });
analytics.trackEvent('Session', 'Subscribe', planId, 1); trackEvent('Session', 'Subscribe', planId, 1);
return response; return response;
} }
@ -259,7 +259,7 @@ export function isLoggedIn () {
export async function logout () { export async function logout () {
await util.post('/auth/logout'); await util.post('/auth/logout');
unsetSessionData(); unsetSessionData();
analytics.trackEvent('Session', 'Logout'); trackEvent('Session', 'Logout');
} }
/** /**
@ -267,7 +267,7 @@ export async function logout () {
*/ */
export async function cancelAccount () { export async function cancelAccount () {
await util.del('/api/billing/subscriptions'); await util.del('/api/billing/subscriptions');
analytics.trackEvent('Session', 'Cancel Account'); trackEvent('Session', 'Cancel Account');
} }
/** /**

View File

@ -1,9 +1,8 @@
import React, {Component, PropTypes} from 'react'; import React, {Component, PropTypes} from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
import Dropdown from './base/Dropdown'; import Dropdown from './base/Dropdown';
import MethodTag from './tags/MethodTag';
import {METHODS, DEBOUNCE_MILLIS} from '../../backend/constants'; import {METHODS, DEBOUNCE_MILLIS} from '../../backend/constants';
import {trackEvent} from '../../backend/ganalytics'; import {trackEvent} from '../../backend/analytics';
import {isMac} from '../../backend/appInfo'; import {isMac} from '../../backend/appInfo';

View File

@ -18,7 +18,7 @@ import {
import {REQUEST_TIME_TO_SHOW_COUNTER, MOD_SYM} from '../../backend/constants'; import {REQUEST_TIME_TO_SHOW_COUNTER, MOD_SYM} from '../../backend/constants';
import {getSetCookieHeaders} from '../../backend/util'; import {getSetCookieHeaders} from '../../backend/util';
import {cancelCurrentRequest} from '../../backend/network'; import {cancelCurrentRequest} from '../../backend/network';
import {trackEvent} from '../../backend/ganalytics'; import {trackEvent} from '../../backend/analytics';
class ResponsePane extends Component { class ResponsePane extends Component {
constructor (props) { constructor (props) {

View File

@ -8,7 +8,7 @@ import * as session from '../../../sync/session';
import {showModal} from './index'; import {showModal} from './index';
import SignupModal from './SignupModal'; import SignupModal from './SignupModal';
import * as sync from '../../../sync'; import * as sync from '../../../sync';
import {trackEvent} from '../../../backend/ganalytics'; import {trackEvent} from '../../../backend/analytics';
class LoginModal extends Component { class LoginModal extends Component {
constructor (props) { constructor (props) {

View File

@ -1,5 +1,4 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import Modal from '../base/Modal'; import Modal from '../base/Modal';
import ModalBody from '../base/ModalBody'; import ModalBody from '../base/ModalBody';
import ModalHeader from '../base/ModalHeader'; import ModalHeader from '../base/ModalHeader';
@ -8,7 +7,7 @@ import * as session from '../../../sync/session';
import {showModal} from './index'; import {showModal} from './index';
import LoginModal from './LoginModal'; import LoginModal from './LoginModal';
import * as sync from '../../../sync'; import * as sync from '../../../sync';
import {trackEvent} from '../../../backend/ganalytics'; import {trackEvent} from '../../../backend/analytics';
class SignupModal extends Component { class SignupModal extends Component {
constructor (props) { constructor (props) {

View File

@ -10,7 +10,7 @@ import * as session from '../../../sync/session';
import * as syncStorage from '../../../sync/storage'; import * as syncStorage from '../../../sync/storage';
import * as sync from '../../../sync'; import * as sync from '../../../sync';
import * as models from '../../../backend/models'; import * as models from '../../../backend/models';
import {trackEvent} from '../../../backend/ganalytics'; import {trackEvent} from '../../../backend/analytics';
class SyncModal extends Component { class SyncModal extends Component {
constructor (props) { constructor (props) {

View File

@ -38,10 +38,9 @@ import * as RequestActions from '../redux/modules/requests';
import * as db from '../../backend/database'; import * as db from '../../backend/database';
import * as models from '../../backend/models'; import * as models from '../../backend/models';
import {importCurl} from '../../backend/export/curl'; import {importCurl} from '../../backend/export/curl';
import {trackLegacyEvent} from '../../backend/analytics';
import {getAppVersion} from '../../backend/appInfo'; import {getAppVersion} from '../../backend/appInfo';
import {toggleModal, showModal} from '../components/modals'; import {toggleModal, showModal} from '../components/modals';
import {trackEvent} from '../../backend/ganalytics'; import {trackEvent, trackLegacyEvent} from '../../backend/analytics';
class App extends Component { class App extends Component {

View File

@ -12,8 +12,7 @@ import {initStore} from './redux/initstore';
import {initDB} from '../backend/database'; import {initDB} from '../backend/database';
import {initSync} from '../sync'; import {initSync} from '../sync';
import {getAppVersion} from '../backend/appInfo'; import {getAppVersion} from '../backend/appInfo';
import {initLegacyAnalytics} from '../backend/analytics'; import {initAnalytics} from '../backend/analytics';
import {initAnalytics} from '../backend/ganalytics';
import * as session from '../sync/session'; import * as session from '../sync/session';
import * as models from '../backend/models'; import * as models from '../backend/models';
@ -33,7 +32,6 @@ const accountId = session.getAccountId();
await initSync(); await initSync();
await initStore(store.dispatch); await initStore(store.dispatch);
await initAnalytics(accountId); await initAnalytics(accountId);
await initLegacyAnalytics();
console.log('-- Rendering App --'); console.log('-- Rendering App --');
render( render(
<Provider store={store}><App /></Provider>, <Provider store={store}><App /></Provider>,

View File

@ -3,7 +3,7 @@ import {combineReducers} from 'redux';
import fs from 'fs'; import fs from 'fs';
import {importJSON, exportJSON} from '../../../backend/export/database'; import {importJSON, exportJSON} from '../../../backend/export/database';
import {trackEvent} from '../../../backend/ganalytics'; import {trackEvent} from '../../../backend/analytics';
import AlertModal from '../../components/modals/AlertModal'; import AlertModal from '../../components/modals/AlertModal';
import {showModal} from '../../components/modals/index'; import {showModal} from '../../components/modals/index';
import PaymentModal from '../../components/modals/PaymentModal'; import PaymentModal from '../../components/modals/PaymentModal';

View File

@ -1,8 +1,7 @@
import {combineReducers} from 'redux'; import {combineReducers} from 'redux';
import {trackLegacyEvent} from '../../../backend/analytics';
import * as network from '../../../backend/network'; import * as network from '../../../backend/network';
import {trackEvent} from '../../../backend/ganalytics'; import {trackEvent, trackLegacyEvent} from '../../../backend/analytics';
export const REQUEST_SEND_START = 'requests/start'; export const REQUEST_SEND_START = 'requests/start';
export const REQUEST_SEND_STOP = 'requests/stop'; export const REQUEST_SEND_STOP = 'requests/stop';