add events for startup and app-ready

This commit is contained in:
Sean Yesmunt 2019-10-02 14:20:25 -04:00
parent a0e0684d14
commit 7628a04f6a
2 changed files with 28 additions and 0 deletions

View file

@ -20,6 +20,8 @@ type Analytics = {
emailProvidedEvent: () => void, emailProvidedEvent: () => void,
emailVerifiedEvent: () => void, emailVerifiedEvent: () => void,
rewardEligibleEvent: () => void, rewardEligibleEvent: () => void,
startupEvent: () => void,
readyEvent: number => void,
}; };
let analyticsEnabled: boolean = true; let analyticsEnabled: boolean = true;
@ -104,6 +106,13 @@ const analytics: Analytics = {
rewardEligibleEvent: () => { rewardEligibleEvent: () => {
sendGaEvent('Engagement', 'Reward-Eligible'); sendGaEvent('Engagement', 'Reward-Eligible');
}, },
startupEvent: () => {
sendGaEvent('Startup', 'Startup');
},
readyEvent: (timeToReady: number) => {
sendGaEvent('Startup', 'App-Ready');
sendGaTimingEvent('Startup', 'App-Ready', timeToReady);
},
}; };
function sendGaEvent(category, action) { function sendGaEvent(category, action) {
@ -115,6 +124,16 @@ function sendGaEvent(category, action) {
} }
} }
function sendGaTimingEvent(category: string, action: string, timeInMs: number) {
if (analyticsEnabled && isProduction) {
ReactGA.timing({
category,
variable: action,
value: timeInMs,
});
}
}
// Initialize google analytics // Initialize google analytics
// Set `debug: true` for debug info // Set `debug: true` for debug info
// Will change once we have separate ids for desktop/web // Will change once we have separate ids for desktop/web
@ -129,6 +148,7 @@ ElectronCookies.enable({
ReactGA.initialize(UA_ID, { ReactGA.initialize(UA_ID, {
testMode: process.env.NODE_ENV !== 'production', testMode: process.env.NODE_ENV !== 'production',
cookieDomain: 'auto', cookieDomain: 'auto',
siteSpeedSampleRate: 100,
// un-comment to see events as they are sent to google // un-comment to see events as they are sent to google
// debug: true, // debug: true,
}); });

View file

@ -29,12 +29,16 @@ import { ConnectedRouter, push } from 'connected-react-router';
import cookie from 'cookie'; import cookie from 'cookie';
import { formatLbryUriForWeb } from 'util/uri'; import { formatLbryUriForWeb } from 'util/uri';
import { PersistGate } from 'redux-persist/integration/react'; import { PersistGate } from 'redux-persist/integration/react';
import analytics from 'analytics';
// Import our app styles // Import our app styles
// If a style is not necessary for the initial page load, it should be removed from `all.scss` // If a style is not necessary for the initial page load, it should be removed from `all.scss`
// and loaded dynamically in the component that consumes it // and loaded dynamically in the component that consumes it
import 'scss/all.scss'; import 'scss/all.scss';
const startTime = Date.now();
analytics.startupEvent();
const APPPAGEURL = 'lbry://?'; const APPPAGEURL = 'lbry://?';
// @if TARGET='app' // @if TARGET='app'
const { autoUpdater } = remote.require('electron-updater'); const { autoUpdater } = remote.require('electron-updater');
@ -231,6 +235,10 @@ function AppWrapper() {
app.store.dispatch(doBlackListedOutpointsSubscribe()); app.store.dispatch(doBlackListedOutpointsSubscribe());
app.store.dispatch(doFilteredOutpointsSubscribe()); app.store.dispatch(doFilteredOutpointsSubscribe());
window.sessionStorage.setItem('loaded', 'y'); window.sessionStorage.setItem('loaded', 'y');
const appReadyTime = Date.now();
const timeToStart = appReadyTime - startTime;
analytics.readyEvent(timeToStart);
} }
}, [readyToLaunch, haveLaunched]); }, [readyToLaunch, haveLaunched]);