diff --git a/app/backend/ganalytics.js b/app/backend/analytics/google.js similarity index 90% rename from app/backend/ganalytics.js rename to app/backend/analytics/google.js index 1b8d277a5..579e1693a 100644 --- a/app/backend/ganalytics.js +++ b/app/backend/analytics/google.js @@ -1,9 +1,9 @@ -import * as constants from './constants'; -import {isDevelopment} from './appInfo'; +import * as constants from '../constants'; +import {isDevelopment} from '../appInfo'; let _sessionId = null; -export function initAnalytics (accountId = null) { +export function init (accountId = null) { if (isDevelopment()) { console.log('-- Not initializing analytics for dev --'); return; @@ -63,5 +63,5 @@ function _injectGoogleAnalyticsScript () { a.async = 1; a.src = g; 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'); } diff --git a/app/backend/analytics/index.js b/app/backend/analytics/index.js new file mode 100644 index 000000000..8ab5eaed0 --- /dev/null +++ b/app/backend/analytics/index.js @@ -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) +} diff --git a/app/backend/analytics.js b/app/backend/analytics/segment.js similarity index 79% rename from app/backend/analytics.js rename to app/backend/analytics/segment.js index 39050ea2f..03f3c9eff 100644 --- a/app/backend/analytics.js +++ b/app/backend/analytics/segment.js @@ -1,13 +1,13 @@ import Analytics from 'analytics-node'; -import {getAppVersion} from './appInfo'; -import {SEGMENT_WRITE_KEY} from './constants'; -import {isDevelopment} from './appInfo'; -import * as models from './models'; +import {getAppVersion} from '../appInfo'; +import {SEGMENT_WRITE_KEY} from '../constants'; +import {isDevelopment} from '../appInfo'; +import * as models from '../models'; let analytics = null; let userId = null; -export async function initLegacyAnalytics () { +export async function init () { if (isDevelopment()) { console.log('-- Not initializing Legacy analytics in dev --'); return; @@ -20,7 +20,7 @@ export async function initLegacyAnalytics () { userId = stats._id; // Recurse now that we have a userId - return await initLegacyAnalytics(); + return await init(); } analytics.identify({ diff --git a/app/sync/session.js b/app/sync/session.js index 0aa4dd271..ef0db10e1 100644 --- a/app/sync/session.js +++ b/app/sync/session.js @@ -1,7 +1,7 @@ import srp from 'srp'; import * as crypt from './crypt'; import * as util from '../backend/fetch'; -import * as analytics from '../backend/ganalytics'; +import {trackEvent, setAccountId} from '../backend/analytics'; 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); - analytics.trackEvent('Session', 'Signup'); + trackEvent('Session', 'Signup'); return response; } @@ -139,8 +139,8 @@ export async function login (rawEmail, rawPassphrase) { ); // Set the ID for Google Analytics - analytics.setAccountId(accountId); - analytics.trackEvent('Session', 'Login'); + setAccountId(accountId); + trackEvent('Session', 'Login'); } export async function subscribe (tokenId, planId) { @@ -149,7 +149,7 @@ export async function subscribe (tokenId, planId) { quantity: 1, plan: planId, }); - analytics.trackEvent('Session', 'Subscribe', planId, 1); + trackEvent('Session', 'Subscribe', planId, 1); return response; } @@ -259,7 +259,7 @@ export function isLoggedIn () { export async function logout () { await util.post('/auth/logout'); unsetSessionData(); - analytics.trackEvent('Session', 'Logout'); + trackEvent('Session', 'Logout'); } /** @@ -267,7 +267,7 @@ export async function logout () { */ export async function cancelAccount () { await util.del('/api/billing/subscriptions'); - analytics.trackEvent('Session', 'Cancel Account'); + trackEvent('Session', 'Cancel Account'); } /** diff --git a/app/ui/components/RequestUrlBar.js b/app/ui/components/RequestUrlBar.js index 4ec72d2e1..de0c7bc73 100644 --- a/app/ui/components/RequestUrlBar.js +++ b/app/ui/components/RequestUrlBar.js @@ -1,9 +1,8 @@ import React, {Component, PropTypes} from 'react'; import classnames from 'classnames'; import Dropdown from './base/Dropdown'; -import MethodTag from './tags/MethodTag'; import {METHODS, DEBOUNCE_MILLIS} from '../../backend/constants'; -import {trackEvent} from '../../backend/ganalytics'; +import {trackEvent} from '../../backend/analytics'; import {isMac} from '../../backend/appInfo'; diff --git a/app/ui/components/ResponsePane.js b/app/ui/components/ResponsePane.js index ddecd366d..29dd021bf 100644 --- a/app/ui/components/ResponsePane.js +++ b/app/ui/components/ResponsePane.js @@ -18,7 +18,7 @@ import { import {REQUEST_TIME_TO_SHOW_COUNTER, MOD_SYM} from '../../backend/constants'; import {getSetCookieHeaders} from '../../backend/util'; import {cancelCurrentRequest} from '../../backend/network'; -import {trackEvent} from '../../backend/ganalytics'; +import {trackEvent} from '../../backend/analytics'; class ResponsePane extends Component { constructor (props) { diff --git a/app/ui/components/modals/LoginModal.js b/app/ui/components/modals/LoginModal.js index 924ea3c35..8db41f0e9 100644 --- a/app/ui/components/modals/LoginModal.js +++ b/app/ui/components/modals/LoginModal.js @@ -8,7 +8,7 @@ import * as session from '../../../sync/session'; import {showModal} from './index'; import SignupModal from './SignupModal'; import * as sync from '../../../sync'; -import {trackEvent} from '../../../backend/ganalytics'; +import {trackEvent} from '../../../backend/analytics'; class LoginModal extends Component { constructor (props) { diff --git a/app/ui/components/modals/SignupModal.js b/app/ui/components/modals/SignupModal.js index ff37a7d3e..4071f33d8 100644 --- a/app/ui/components/modals/SignupModal.js +++ b/app/ui/components/modals/SignupModal.js @@ -1,5 +1,4 @@ import React, {Component} from 'react'; - import Modal from '../base/Modal'; import ModalBody from '../base/ModalBody'; import ModalHeader from '../base/ModalHeader'; @@ -8,7 +7,7 @@ import * as session from '../../../sync/session'; import {showModal} from './index'; import LoginModal from './LoginModal'; import * as sync from '../../../sync'; -import {trackEvent} from '../../../backend/ganalytics'; +import {trackEvent} from '../../../backend/analytics'; class SignupModal extends Component { constructor (props) { diff --git a/app/ui/components/modals/SyncModal.js b/app/ui/components/modals/SyncModal.js index 10fa02f1b..240e38ee8 100644 --- a/app/ui/components/modals/SyncModal.js +++ b/app/ui/components/modals/SyncModal.js @@ -10,7 +10,7 @@ import * as session from '../../../sync/session'; import * as syncStorage from '../../../sync/storage'; import * as sync from '../../../sync'; import * as models from '../../../backend/models'; -import {trackEvent} from '../../../backend/ganalytics'; +import {trackEvent} from '../../../backend/analytics'; class SyncModal extends Component { constructor (props) { diff --git a/app/ui/containers/App.js b/app/ui/containers/App.js index 8a5bc5a25..f5fe385b5 100644 --- a/app/ui/containers/App.js +++ b/app/ui/containers/App.js @@ -38,10 +38,9 @@ import * as RequestActions from '../redux/modules/requests'; import * as db from '../../backend/database'; import * as models from '../../backend/models'; import {importCurl} from '../../backend/export/curl'; -import {trackLegacyEvent} from '../../backend/analytics'; import {getAppVersion} from '../../backend/appInfo'; import {toggleModal, showModal} from '../components/modals'; -import {trackEvent} from '../../backend/ganalytics'; +import {trackEvent, trackLegacyEvent} from '../../backend/analytics'; class App extends Component { diff --git a/app/ui/index.js b/app/ui/index.js index 34fd37720..bc4e0bc52 100644 --- a/app/ui/index.js +++ b/app/ui/index.js @@ -12,8 +12,7 @@ import {initStore} from './redux/initstore'; import {initDB} from '../backend/database'; import {initSync} from '../sync'; import {getAppVersion} from '../backend/appInfo'; -import {initLegacyAnalytics} from '../backend/analytics'; -import {initAnalytics} from '../backend/ganalytics'; +import {initAnalytics} from '../backend/analytics'; import * as session from '../sync/session'; import * as models from '../backend/models'; @@ -33,7 +32,6 @@ const accountId = session.getAccountId(); await initSync(); await initStore(store.dispatch); await initAnalytics(accountId); - await initLegacyAnalytics(); console.log('-- Rendering App --'); render( , diff --git a/app/ui/redux/modules/global.js b/app/ui/redux/modules/global.js index 4fe35e07e..6d73d3672 100644 --- a/app/ui/redux/modules/global.js +++ b/app/ui/redux/modules/global.js @@ -3,7 +3,7 @@ import {combineReducers} from 'redux'; import fs from 'fs'; import {importJSON, exportJSON} from '../../../backend/export/database'; -import {trackEvent} from '../../../backend/ganalytics'; +import {trackEvent} from '../../../backend/analytics'; import AlertModal from '../../components/modals/AlertModal'; import {showModal} from '../../components/modals/index'; import PaymentModal from '../../components/modals/PaymentModal'; diff --git a/app/ui/redux/modules/requests.js b/app/ui/redux/modules/requests.js index 2a1d65f76..64b4a8668 100644 --- a/app/ui/redux/modules/requests.js +++ b/app/ui/redux/modules/requests.js @@ -1,8 +1,7 @@ import {combineReducers} from 'redux'; -import {trackLegacyEvent} from '../../../backend/analytics'; 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_STOP = 'requests/stop';