Merge pull request #2400 from lbryio/ga

Google analytics
This commit is contained in:
Sean Yesmunt 2019-04-01 13:31:36 -04:00 committed by GitHub
commit 1e5bb72a88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 59 deletions

View file

@ -114,7 +114,6 @@
"make-runnable": "^1.3.6", "make-runnable": "^1.3.6",
"mammoth": "^1.4.6", "mammoth": "^1.4.6",
"mime": "^2.3.1", "mime": "^2.3.1",
"mixpanel-browser": "^2.17.1",
"moment": "^2.22.0", "moment": "^2.22.0",
"node-abi": "^2.5.1", "node-abi": "^2.5.1",
"node-fetch": "^2.3.0", "node-fetch": "^2.3.0",
@ -130,6 +129,7 @@
"react": "^16.8.2", "react": "^16.8.2",
"react-dom": "^16.8.2", "react-dom": "^16.8.2",
"react-feather": "^1.0.8", "react-feather": "^1.0.8",
"react-ga": "^2.5.7",
"react-hot-loader": "^4.7.2", "react-hot-loader": "^4.7.2",
"react-modal": "^3.1.7", "react-modal": "^3.1.7",
"react-paginate": "^5.2.1", "react-paginate": "^5.2.1",

View file

@ -1,48 +1,31 @@
// @flow // @flow
import mixpanel from 'mixpanel-browser';
import { Lbryio } from 'lbryinc'; import { Lbryio } from 'lbryinc';
import isDev from 'electron-is-dev'; import ReactGA from 'react-ga';
import { globalHistory } from '@reach/router';
if (isDev) {
mixpanel.init('691723e855cabb9d27a7a79002216967');
} else {
mixpanel.init('af5c6b8110068fa4f5c4600c81f05e60');
}
type Analytics = { type Analytics = {
track: (string, ?Object) => void, pageView: string => void,
setUser: Object => void, setUser: Object => void,
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,
}; };
let analyticsEnabled: boolean = false; let analyticsEnabled: boolean = true;
const analytics: Analytics = { const analytics: Analytics = {
track: (name, payload) => { pageView: path => {
if (analyticsEnabled) { if (analyticsEnabled) {
if (payload) { ReactGA.pageview(path);
mixpanel.track(name, payload);
} else {
mixpanel.track(name);
}
} }
}, },
setUser: user => { setUser: user => {
if (user.id) { // Commented out because currently there is some delay before we know the user
mixpanel.identify(user.id); // We should retrieve this server side so we have it immediately
} // if (analyticsEnabled && user.id) {
if (user.primary_email) { // ReactGA.set('userId', user.id);
mixpanel.people.set({ // }
$email: 1,
});
}
}, },
toggle: (enabled: boolean, logDisabled: ?boolean): void => { toggle: (enabled: boolean): void => {
if (!enabled && logDisabled) {
mixpanel.track('DISABLED');
}
analyticsEnabled = enabled; analyticsEnabled = enabled;
}, },
apiLogView: (uri, outpoint, claimId, timeToStart, onSuccessCb) => { apiLogView: (uri, outpoint, claimId, timeToStart, onSuccessCb) => {
@ -87,4 +70,21 @@ const analytics: Analytics = {
}, },
}; };
// Initialize google analytics
// Set `debug: true` for debug info
ReactGA.initialize('UA-60403362-12', {
gaOptions: { name: IS_WEB ? 'web' : 'desktop' },
testMode: process.env.NODE_ENV !== 'production',
});
// Manually call the first page view
// Reach Router doesn't include this on `history.listen`
analytics.pageView(window.location.pathname + window.location.search);
// Listen for url changes and report
// This will include search queries/filter options
globalHistory.listen(({ location }) =>
analytics.pageView(window.location.pathname + window.location.search)
);
export default analytics; export default analytics;

View file

@ -4,6 +4,7 @@ import Icon from 'component/common/icon';
import classnames from 'classnames'; import classnames from 'classnames';
import { Link } from '@reach/router'; import { Link } from '@reach/router';
import { formatLbryUriForWeb } from 'util/uri'; import { formatLbryUriForWeb } from 'util/uri';
import { OutboundLink } from 'react-ga';
type Props = { type Props = {
onClick: ?(any) => any, onClick: ?(any) => any,
@ -85,9 +86,14 @@ class Button extends React.PureComponent<Props> {
if (href) { if (href) {
return ( return (
<a href={href} className={combinedClassName}> <OutboundLink
eventLabel="outboundClick"
to={href}
target="_blank"
className={combinedClassName}
>
{content} {content}
</a> </OutboundLink>
); );
} }

View file

@ -93,7 +93,6 @@ class UserHistoryPage extends React.PureComponent<Props, State> {
render() { render() {
const { history = [], page, pageCount } = this.props; const { history = [], page, pageCount } = this.props;
const { itemsSelected } = this.state; const { itemsSelected } = this.state;
const allSelected = Object.keys(itemsSelected).length === history.length; const allSelected = Object.keys(itemsSelected).length === history.length;
const selectHandler = allSelected ? this.unselectAll : this.selectAll; const selectHandler = allSelected ? this.unselectAll : this.selectAll;

View file

@ -173,26 +173,6 @@ document.addEventListener('click', event => {
let { target } = event; let { target } = event;
while (target && target !== document) { while (target && target !== document) {
if (target.matches('a') || target.matches('button')) {
// TODO: Look into using accessiblity labels (this would also make the app more accessible)
const hrefParts = window.location.href.split('#');
// Buttons that we want to track should use `data-id`
// This prevents multiple buttons being grouped together if they have the same text
const element =
target.dataset.id || target.title || (target.textContent && target.textContent.trim());
if (element) {
analytics.track('CLICK', {
target: element,
location: hrefParts.length > 1 ? hrefParts[hrefParts.length - 1] : '/',
});
} else {
analytics.track('UNMARKED_CLICK', {
location: hrefParts.length > 1 ? hrefParts[hrefParts.length - 1] : '/',
source: target.outerHTML,
});
}
}
if (target.matches('a[href^="http"]') || target.matches('a[href^="mailto"]')) { if (target.matches('a[href^="http"]') || target.matches('a[href^="mailto"]')) {
// @if TARGET='app' // @if TARGET='app'
event.preventDefault(); event.preventDefault();

View file

@ -30,7 +30,7 @@ export function doSetDaemonSetting(key, value) {
}; };
Lbry.settings_set(newSettings).then(newSettings); Lbry.settings_set(newSettings).then(newSettings);
Lbry.settings_get().then(settings => { Lbry.settings_get().then(settings => {
analytics.toggle(settings.share_usage_data, true); analytics.toggle(settings.share_usage_data);
dispatch({ dispatch({
type: ACTIONS.DAEMON_SETTINGS_RECEIVED, type: ACTIONS.DAEMON_SETTINGS_RECEIVED,
data: { data: {

View file

@ -6938,11 +6938,6 @@ mixin-object@^2.0.1:
for-in "^0.1.3" for-in "^0.1.3"
is-extendable "^0.1.1" is-extendable "^0.1.1"
mixpanel-browser@^2.17.1:
version "2.26.0"
resolved "https://registry.yarnpkg.com/mixpanel-browser/-/mixpanel-browser-2.26.0.tgz#0f2108d36c8170dab32dd16cabac6eb13138652e"
integrity sha512-aIRtoMvv6B+syslAvYyk+seuYObm0TeOxQz2JZqquZTEa+Kw9cNTVRA+H1s7QY1QFOKrk94gkmLdKJbwcOcG5w==
mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
version "0.5.1" version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
@ -8626,6 +8621,11 @@ react-feather@^1.0.8:
resolved "https://registry.yarnpkg.com/react-feather/-/react-feather-1.1.6.tgz#2a547e3d5cd5e383d3da0128d593cbdb3c1b32f7" resolved "https://registry.yarnpkg.com/react-feather/-/react-feather-1.1.6.tgz#2a547e3d5cd5e383d3da0128d593cbdb3c1b32f7"
integrity sha512-iCofWhTjX+vQwvDmg7o6vg0XrUg1c41yBDZG+l83nz1FiCsleJoUgd3O+kHpOeWMXuPrRIFfCixvcqyOLGOgIg== integrity sha512-iCofWhTjX+vQwvDmg7o6vg0XrUg1c41yBDZG+l83nz1FiCsleJoUgd3O+kHpOeWMXuPrRIFfCixvcqyOLGOgIg==
react-ga@^2.5.7:
version "2.5.7"
resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-2.5.7.tgz#1c80a289004bf84f84c26d46f3a6a6513081bf2e"
integrity sha512-UmATFaZpEQDO96KFjB5FRLcT6hFcwaxOmAJZnjrSiFN/msTqylq9G+z5Z8TYzN/dbamDTiWf92m6MnXXJkAivQ==
react-hot-loader@^4.7.2: react-hot-loader@^4.7.2:
version "4.7.2" version "4.7.2"
resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-4.7.2.tgz#54cd99441c2d594bdc58c90673690c245dcfcaff" resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-4.7.2.tgz#54cd99441c2d594bdc58c90673690c245dcfcaff"