diff --git a/src/ui/analytics.js b/src/ui/analytics.js index add8400c9..72c9c1a84 100644 --- a/src/ui/analytics.js +++ b/src/ui/analytics.js @@ -20,6 +20,8 @@ type Analytics = { emailProvidedEvent: () => void, emailVerifiedEvent: () => void, rewardEligibleEvent: () => void, + startupEvent: () => void, + readyEvent: number => void, }; let analyticsEnabled: boolean = true; @@ -104,6 +106,13 @@ const analytics: Analytics = { rewardEligibleEvent: () => { sendGaEvent('Engagement', 'Reward-Eligible'); }, + startupEvent: () => { + sendGaEvent('Startup', 'Startup'); + }, + readyEvent: (timeToReady: number) => { + sendGaEvent('Startup', 'App-Ready'); + sendGaTimingEvent('Startup', 'App-Ready', timeToReady); + }, }; 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 // Set `debug: true` for debug info // Will change once we have separate ids for desktop/web @@ -129,6 +148,7 @@ ElectronCookies.enable({ ReactGA.initialize(UA_ID, { testMode: process.env.NODE_ENV !== 'production', cookieDomain: 'auto', + siteSpeedSampleRate: 100, // un-comment to see events as they are sent to google // debug: true, }); diff --git a/src/ui/index.jsx b/src/ui/index.jsx index 9c5dd76f1..ced3a9629 100644 --- a/src/ui/index.jsx +++ b/src/ui/index.jsx @@ -29,12 +29,16 @@ import { ConnectedRouter, push } from 'connected-react-router'; import cookie from 'cookie'; import { formatLbryUriForWeb } from 'util/uri'; import { PersistGate } from 'redux-persist/integration/react'; +import analytics from 'analytics'; // Import our app styles // 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 import 'scss/all.scss'; +const startTime = Date.now(); +analytics.startupEvent(); + const APPPAGEURL = 'lbry://?'; // @if TARGET='app' const { autoUpdater } = remote.require('electron-updater'); @@ -231,6 +235,10 @@ function AppWrapper() { app.store.dispatch(doBlackListedOutpointsSubscribe()); app.store.dispatch(doFilteredOutpointsSubscribe()); window.sessionStorage.setItem('loaded', 'y'); + + const appReadyTime = Date.now(); + const timeToStart = appReadyTime - startTime; + analytics.readyEvent(timeToStart); } }, [readyToLaunch, haveLaunched]);