add analytics for version/email/reward eligibility

This commit is contained in:
Sean Yesmunt 2019-08-14 12:28:13 -04:00
parent 70fc454647
commit e589a87298
5 changed files with 64 additions and 11 deletions

View file

@ -126,7 +126,7 @@
"json-loader": "^0.5.4",
"lbry-format": "https://github.com/lbryio/lbry-format.git",
"lbry-redux": "lbryio/lbry-redux#4e093983eaf3d9e7513119657d731b808ead74a6",
"lbryinc": "lbryio/lbryinc#a93596c51c8fb0a226cb84df04c26a6bb60a45fb",
"lbryinc": "lbryio/lbryinc#1ce266b3c52654190b955e9c869b8e302aa5c585",
"lint-staged": "^7.0.2",
"localforage": "^1.7.1",
"lodash-es": "^4.17.14",

View file

@ -3,6 +3,7 @@ import { Lbryio } from 'lbryinc';
import ReactGA from 'react-ga';
import { history } from './store';
// @if TARGET='app'
import Native from 'native';
import ElectronCookies from '@exponent/electron-cookies';
// @endif
@ -15,6 +16,9 @@ type Analytics = {
apiLogView: (string, string, string, ?number, ?() => void) => void,
apiLogPublish: () => void,
tagFollowEvent: (string, boolean, string) => void,
emailProvidedEvent: () => void,
emailVerifiedEvent: () => void,
rewardEligibleEvent: () => void,
};
let analyticsEnabled: boolean = true;
@ -26,11 +30,18 @@ const analytics: Analytics = {
},
setUser: userId => {
if (analyticsEnabled && userId) {
ReactGA.event({
category: 'User',
action: 'userId',
value: userId,
ReactGA.set({
userId,
});
// @if TARGET='app'
Native.getAppVersionInfo().then(({ localVersion }) => {
ReactGA.event({
category: 'Desktop-Version',
action: localVersion,
});
});
// @endif
}
},
toggle: (enabled: boolean): void => {
@ -92,6 +103,30 @@ const analytics: Analytics = {
});
}
},
emailProvidedEvent: () => {
if (analyticsEnabled && isProduction) {
ReactGA.event({
category: 'Engagement',
action: 'Email-Provided',
});
}
},
emailVerifiedEvent: () => {
if (analyticsEnabled && isProduction) {
ReactGA.event({
category: 'Engagement',
action: 'Email-Verified',
});
}
},
rewardEligibleEvent: () => {
if (analyticsEnabled && isProduction) {
ReactGA.event({
category: 'Engagement',
action: 'Reward-Eligible',
});
}
},
};
// Initialize google analytics

View file

@ -12,6 +12,7 @@ import useKonamiListener from 'util/enhanced-layout';
import Yrbl from 'component/yrbl';
import FileViewer from 'component/fileViewer';
import { withRouter } from 'react-router';
import usePrevious from 'util/use-previous';
export const MAIN_WRAPPER_CLASS = 'main-wrapper';
@ -21,7 +22,7 @@ type Props = {
language: string,
theme: string,
accessToken: ?string,
user: ?{ id: string, has_verified_email: boolean },
user: ?{ id: string, has_verified_email: boolean, is_reward_approved: boolean },
location: { pathname: string },
fetchRewards: () => void,
fetchRewardedContent: () => void,
@ -35,7 +36,10 @@ function App(props: Props) {
const isEnhancedLayout = useKonamiListener();
const userId = user && user.id;
const hasVerifiedEmail = user && user.has_verified_email;
const isRewardApproved = user && user.is_reward_approved;
const previousUserId = usePrevious(userId);
const previousHasVerifiedEmail = usePrevious(hasVerifiedEmail);
const previousRewardApproved = usePrevious(isRewardApproved);
const { pathname } = props.location;
const urlParts = pathname.split('/');
const claimName = urlParts[1];
@ -65,10 +69,22 @@ function App(props: Props) {
}, [theme]);
useEffect(() => {
if (userId) {
if (previousUserId === undefined && userId) {
analytics.setUser(userId);
}
}, [userId]);
}, [previousUserId, userId]);
useEffect(() => {
if (previousHasVerifiedEmail !== undefined && hasVerifiedEmail) {
analytics.emailVerifiedEvent();
}
}, [previousHasVerifiedEmail, hasVerifiedEmail]);
useEffect(() => {
if (previousRewardApproved !== undefined && isRewardApproved) {
analytics.rewardEligibleEvent();
}
}, [previousRewardApproved, isRewardApproved]);
// @if TARGET='web'
useEffect(() => {

View file

@ -3,6 +3,7 @@ import * as React from 'react';
import { FormField, Form } from 'component/common/form';
import Button from 'component/button';
import { Lbryio } from 'lbryinc';
import analytics from 'analytics';
type Props = {
cancelButton: React.Node,
@ -37,6 +38,7 @@ class UserEmailNew extends React.PureComponent<Props, State> {
const { email } = this.state;
const { addUserEmail } = this.props;
addUserEmail(email);
analytics.emailProvidedEvent();
// @if TARGET='web'
Lbryio.call('user_tag', 'edit', { add: 'lbrytv' });

View file

@ -6771,9 +6771,9 @@ lbry-redux@lbryio/lbry-redux#4e093983eaf3d9e7513119657d731b808ead74a6:
reselect "^3.0.0"
uuid "^3.3.2"
lbryinc@lbryio/lbryinc#a93596c51c8fb0a226cb84df04c26a6bb60a45fb:
lbryinc@lbryio/lbryinc#1ce266b3c52654190b955e9c869b8e302aa5c585:
version "0.0.1"
resolved "https://codeload.github.com/lbryio/lbryinc/tar.gz/a93596c51c8fb0a226cb84df04c26a6bb60a45fb"
resolved "https://codeload.github.com/lbryio/lbryinc/tar.gz/1ce266b3c52654190b955e9c869b8e302aa5c585"
dependencies:
reselect "^3.0.0"