send ga event for tag follow/unfollow and also for user id #2645
4 changed files with 42 additions and 8 deletions
|
@ -14,6 +14,7 @@ type Analytics = {
|
||||||
toggle: (boolean, ?boolean) => void,
|
toggle: (boolean, ?boolean) => void,
|
||||||
apiLogView: (string, string, string, ?number, ?() => void) => void,
|
apiLogView: (string, string, string, ?number, ?() => void) => void,
|
||||||
apiLogPublish: () => void,
|
apiLogPublish: () => void,
|
||||||
|
tagFollowEvent: (string, boolean, string) => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
let analyticsEnabled: boolean = true;
|
let analyticsEnabled: boolean = true;
|
||||||
|
@ -23,12 +24,14 @@ const analytics: Analytics = {
|
||||||
ReactGA.pageview(path);
|
ReactGA.pageview(path);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setUser: user => {
|
setUser: userId => {
|
||||||
// Commented out because currently there is some delay before we know the user
|
if (analyticsEnabled && userId) {
|
||||||
// We should retrieve this server side so we have it immediately
|
ReactGA.event({
|
||||||
// if (analyticsEnabled && user.id) {
|
category: 'User',
|
||||||
// ReactGA.set('userId', user.id);
|
action: 'userId',
|
||||||
// }
|
value: userId,
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
toggle: (enabled: boolean): void => {
|
toggle: (enabled: boolean): void => {
|
||||||
// Always collect analytics on lbry.tv
|
// Always collect analytics on lbry.tv
|
||||||
|
@ -78,6 +81,15 @@ const analytics: Analytics = {
|
||||||
Lbryio.call('feedback', 'search', { query, vote });
|
Lbryio.call('feedback', 'search', { query, vote });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
tagFollowEvent: (tag, following, location) => {
|
||||||
|
if (analyticsEnabled) {
|
||||||
|
ReactGA.event({
|
||||||
|
category: 'Tag',
|
||||||
|
action: following ? 'follow' : 'unfollow',
|
||||||
|
value: tag,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize google analytics
|
// Initialize google analytics
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
|
import analytics from 'analytics';
|
||||||
import Router from 'component/router/index';
|
import Router from 'component/router/index';
|
||||||
import ModalRouter from 'modal/modalRouter';
|
import ModalRouter from 'modal/modalRouter';
|
||||||
import ReactModal from 'react-modal';
|
import ReactModal from 'react-modal';
|
||||||
|
@ -16,15 +17,17 @@ type Props = {
|
||||||
pageTitle: ?string,
|
pageTitle: ?string,
|
||||||
language: string,
|
language: string,
|
||||||
theme: string,
|
theme: string,
|
||||||
|
user: ?{ id: string },
|
||||||
fetchRewards: () => void,
|
fetchRewards: () => void,
|
||||||
fetchRewardedContent: () => void,
|
fetchRewardedContent: () => void,
|
||||||
fetchTransactions: () => void,
|
fetchTransactions: () => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
function App(props: Props) {
|
function App(props: Props) {
|
||||||
const { theme, fetchRewards, fetchRewardedContent, fetchTransactions } = props;
|
const { theme, fetchRewards, fetchRewardedContent, fetchTransactions, user } = props;
|
||||||
const appRef = useRef();
|
const appRef = useRef();
|
||||||
const isEnhancedLayout = useKonamiListener();
|
const isEnhancedLayout = useKonamiListener();
|
||||||
|
const userId = user && user.id;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
ReactModal.setAppElement(appRef.current);
|
ReactModal.setAppElement(appRef.current);
|
||||||
|
@ -41,6 +44,12 @@ function App(props: Props) {
|
||||||
document.documentElement.setAttribute('data-mode', theme);
|
document.documentElement.setAttribute('data-mode', theme);
|
||||||
}, [theme]);
|
}, [theme]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (userId) {
|
||||||
|
analytics.setUser(userId);
|
||||||
|
}
|
||||||
|
}, [userId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={appRef} onContextMenu={e => openContextMenu(e)}>
|
<div ref={appRef} onContextMenu={e => openContextMenu(e)}>
|
||||||
<Header />
|
<Header />
|
||||||
|
|
|
@ -6,6 +6,7 @@ import Tag from 'component/tag';
|
||||||
import TagsSearch from 'component/tagsSearch';
|
import TagsSearch from 'component/tagsSearch';
|
||||||
import usePersistedState from 'util/use-persisted-state';
|
import usePersistedState from 'util/use-persisted-state';
|
||||||
import { useTransition, animated } from 'react-spring';
|
import { useTransition, animated } from 'react-spring';
|
||||||
|
import analytics from 'analytics';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
showClose: boolean,
|
showClose: boolean,
|
||||||
|
@ -56,6 +57,10 @@ export default function TagSelect(props: Props) {
|
||||||
onRemove(tag);
|
onRemove(tag);
|
||||||
} else {
|
} else {
|
||||||
doToggleTagFollow(tag.name);
|
doToggleTagFollow(tag.name);
|
||||||
|
|
||||||
|
const wasFollowing = followedTags.map(tag => tag.name).includes(tag.name);
|
||||||
|
const nowFollowing = !wasFollowing;
|
||||||
|
analytics.tagFollowEvent(tag.name, nowFollowing, 'tag-select');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import Page from 'component/page';
|
||||||
import ClaimListDiscover from 'component/claimListDiscover';
|
import ClaimListDiscover from 'component/claimListDiscover';
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
import useHover from 'util/use-hover';
|
import useHover from 'util/use-hover';
|
||||||
|
import analytics from 'analytics';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
location: { search: string },
|
location: { search: string },
|
||||||
|
@ -33,11 +34,18 @@ function TagsPage(props: Props) {
|
||||||
label = __('Unfollow');
|
label = __('Unfollow');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleFollowClick() {
|
||||||
|
doToggleTagFollow(tag);
|
||||||
|
|
||||||
|
const nowFollowing = !isFollowing;
|
||||||
|
analytics.tagFollowEvent(tag, nowFollowing, 'tag-page');
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<ClaimListDiscover
|
<ClaimListDiscover
|
||||||
tags={tags}
|
tags={tags}
|
||||||
meta={<Button ref={buttonRef} button="link" onClick={() => doToggleTagFollow(tag)} label={label} />}
|
meta={<Button ref={buttonRef} button="link" onClick={handleFollowClick} label={label} />}
|
||||||
/>
|
/>
|
||||||
</Page>
|
</Page>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue