Remove matomo + restore GA (#63)
This commit is contained in:
commit
3b442531ef
7 changed files with 46 additions and 117 deletions
|
@ -26,8 +26,6 @@ WELCOME_VERSION=1.0
|
||||||
# STRIPE_PUBLIC_KEY='pk_test_NoL1JWL7i1ipfhVId5KfDZgo'
|
# STRIPE_PUBLIC_KEY='pk_test_NoL1JWL7i1ipfhVId5KfDZgo'
|
||||||
|
|
||||||
# Analytics
|
# Analytics
|
||||||
MATOMO_URL=https://analytics.lbry.com/
|
|
||||||
MATOMO_ID=4
|
|
||||||
|
|
||||||
# OG
|
# OG
|
||||||
OG_TITLE_SUFFIX=| lbry.tv
|
OG_TITLE_SUFFIX=| lbry.tv
|
||||||
|
|
2
.github/workflows/node.js.yml
vendored
2
.github/workflows/node.js.yml
vendored
|
@ -41,8 +41,6 @@ jobs:
|
||||||
yarn compile:web
|
yarn compile:web
|
||||||
env:
|
env:
|
||||||
# UI
|
# UI
|
||||||
MATOMO_URL: https://analytics.lbry.com/
|
|
||||||
MATOMO_ID: 4
|
|
||||||
WELCOME_VERSION: 1.0
|
WELCOME_VERSION: 1.0
|
||||||
DOMAIN: odysee.com
|
DOMAIN: odysee.com
|
||||||
URL: https://odysee.com
|
URL: https://odysee.com
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
require('dotenv-defaults').config({ silent: false });
|
require('dotenv-defaults').config({ silent: false });
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
MATOMO_URL: process.env.MATOMO_URL,
|
|
||||||
MATOMO_ID: process.env.MATOMO_ID,
|
|
||||||
WEBPACK_WEB_PORT: process.env.WEBPACK_WEB_PORT,
|
WEBPACK_WEB_PORT: process.env.WEBPACK_WEB_PORT,
|
||||||
WEBPACK_ELECTRON_PORT: process.env.WEBPACK_ELECTRON_PORT,
|
WEBPACK_ELECTRON_PORT: process.env.WEBPACK_ELECTRON_PORT,
|
||||||
WEB_SERVER_PORT: process.env.WEB_SERVER_PORT,
|
WEB_SERVER_PORT: process.env.WEB_SERVER_PORT,
|
||||||
|
|
|
@ -85,7 +85,6 @@
|
||||||
"@babel/preset-flow": "^7.12.1",
|
"@babel/preset-flow": "^7.12.1",
|
||||||
"@babel/preset-react": "^7.0.0",
|
"@babel/preset-react": "^7.0.0",
|
||||||
"@babel/register": "^7.0.0",
|
"@babel/register": "^7.0.0",
|
||||||
"@datapunt/matomo-tracker-js": "^0.1.4",
|
|
||||||
"@exponent/electron-cookies": "^2.0.0",
|
"@exponent/electron-cookies": "^2.0.0",
|
||||||
"@hot-loader/react-dom": "^16.13",
|
"@hot-loader/react-dom": "^16.13",
|
||||||
"@reach/auto-id": "^0.13.0",
|
"@reach/auto-id": "^0.13.0",
|
||||||
|
|
|
@ -1,6 +1,19 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html dir="ltr">
|
<html dir="ltr">
|
||||||
<head>
|
<head>
|
||||||
|
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||||
|
<script async src="https://www.googletagmanager.com/gtag/js?id=G-BB8DNPB73F"></script>
|
||||||
|
<script>
|
||||||
|
window.dataLayer = window.dataLayer || [];
|
||||||
|
function gtag(){dataLayer.push(arguments);}
|
||||||
|
gtag('consent', 'default', {
|
||||||
|
'ad_storage': 'denied',
|
||||||
|
'analytics_storage': 'denied',
|
||||||
|
});
|
||||||
|
gtag('js', new Date());
|
||||||
|
gtag('config', 'G-BB8DNPB73F');
|
||||||
|
</script>
|
||||||
|
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta http-equiv="Pragma" content="no-cache" />
|
<meta http-equiv="Pragma" content="no-cache" />
|
||||||
|
|
136
ui/analytics.js
136
ui/analytics.js
|
@ -1,15 +1,7 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { Lbryio } from 'lbryinc';
|
import { Lbryio } from 'lbryinc';
|
||||||
import * as Sentry from '@sentry/browser';
|
import * as Sentry from '@sentry/browser';
|
||||||
import MatomoTracker from '@datapunt/matomo-tracker-js';
|
|
||||||
import { history } from './store';
|
|
||||||
import { SDK_API_PATH } from './index';
|
import { SDK_API_PATH } from './index';
|
||||||
// @if TARGET='app'
|
|
||||||
import Native from 'native';
|
|
||||||
import ElectronCookies from '@exponent/electron-cookies';
|
|
||||||
import { generateInitialUrl } from 'util/url';
|
|
||||||
// @endif
|
|
||||||
import { MATOMO_ID, MATOMO_URL } from 'config';
|
|
||||||
// import getConnectionSpeed from 'util/detect-user-bandwidth';
|
// import getConnectionSpeed from 'util/detect-user-bandwidth';
|
||||||
|
|
||||||
// let userDownloadBandwidthInBitsPerSecond;
|
// let userDownloadBandwidthInBitsPerSecond;
|
||||||
|
@ -24,23 +16,13 @@ const isProduction = process.env.NODE_ENV === 'production';
|
||||||
const devInternalApis = process.env.LBRY_API_URL && process.env.LBRY_API_URL.includes('dev');
|
const devInternalApis = process.env.LBRY_API_URL && process.env.LBRY_API_URL.includes('dev');
|
||||||
|
|
||||||
export const SHARE_INTERNAL = 'shareInternal';
|
export const SHARE_INTERNAL = 'shareInternal';
|
||||||
const SHARE_THIRD_PARTY = 'shareThirdParty';
|
|
||||||
|
|
||||||
const WATCHMAN_BACKEND_ENDPOINT = 'https://watchman.na-backend.odysee.com/reports/playback';
|
const WATCHMAN_BACKEND_ENDPOINT = 'https://watchman.na-backend.odysee.com/reports/playback';
|
||||||
const SEND_DATA_TO_WATCHMAN_INTERVAL = 10; // in seconds
|
const SEND_DATA_TO_WATCHMAN_INTERVAL = 10; // in seconds
|
||||||
|
|
||||||
// @if TARGET='app'
|
|
||||||
if (isProduction) {
|
|
||||||
ElectronCookies.enable({
|
|
||||||
origin: 'https://lbry.tv',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// @endif
|
|
||||||
|
|
||||||
type Analytics = {
|
type Analytics = {
|
||||||
error: (string) => Promise<any>,
|
error: (string) => Promise<any>,
|
||||||
sentryError: ({} | string, {}) => Promise<any>,
|
sentryError: ({} | string, {}) => Promise<any>,
|
||||||
pageView: (string, ?string) => void,
|
|
||||||
setUser: (Object) => void,
|
setUser: (Object) => void,
|
||||||
toggleInternal: (boolean, ?boolean) => void,
|
toggleInternal: (boolean, ?boolean) => void,
|
||||||
apiLogView: (string, string, string, ?number, ?() => void) => Promise<any>,
|
apiLogView: (string, string, string, ?number, ?() => void) => Promise<any>,
|
||||||
|
@ -84,10 +66,6 @@ type LogPublishParams = {
|
||||||
|
|
||||||
let internalAnalyticsEnabled: boolean = IS_WEB || false;
|
let internalAnalyticsEnabled: boolean = IS_WEB || false;
|
||||||
// let thirdPartyAnalyticsEnabled: boolean = IS_WEB || false;
|
// let thirdPartyAnalyticsEnabled: boolean = IS_WEB || false;
|
||||||
// @if TARGET='app'
|
|
||||||
if (window.localStorage.getItem(SHARE_INTERNAL) === 'true') internalAnalyticsEnabled = true;
|
|
||||||
// if (window.localStorage.getItem(SHARE_THIRD_PARTY) === 'true') thirdPartyAnalyticsEnabled = true;
|
|
||||||
// @endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the mobile device type viewing the data
|
* Determine the mobile device type viewing the data
|
||||||
|
@ -266,7 +244,7 @@ const analytics: Analytics = {
|
||||||
bitrateAsBitsPerSecond = videoBitrate;
|
bitrateAsBitsPerSecond = videoBitrate;
|
||||||
|
|
||||||
sendPromMetric('time_to_start', timeToStartVideo);
|
sendPromMetric('time_to_start', timeToStartVideo);
|
||||||
sendMatomoEvent('Media', 'TimeToStart', claimId, timeToStartVideo);
|
sendGaEvent('video_time_to_start', { claim_id: claimId, time: timeToStartVideo });
|
||||||
},
|
},
|
||||||
error: (message) => {
|
error: (message) => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
@ -292,45 +270,17 @@ const analytics: Analytics = {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
pageView: (path, search) => {
|
|
||||||
if (internalAnalyticsEnabled) {
|
|
||||||
const params: { href: string, customDimensions?: Array<{ id: number, value: ?string }> } = { href: `${path}` };
|
|
||||||
const dimensions = [];
|
|
||||||
const searchParams = search && new URLSearchParams(search);
|
|
||||||
|
|
||||||
if (searchParams && searchParams.get('src')) {
|
|
||||||
dimensions.push({ id: 1, value: searchParams.get('src') });
|
|
||||||
}
|
|
||||||
if (dimensions.length) {
|
|
||||||
params['customDimensions'] = dimensions;
|
|
||||||
}
|
|
||||||
MatomoInstance.trackPageView(params);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
setUser: (userId) => {
|
setUser: (userId) => {
|
||||||
if (internalAnalyticsEnabled && userId) {
|
if (internalAnalyticsEnabled && userId && window.gtag) {
|
||||||
window._paq.push(['setUserId', String(userId)]);
|
window.gtag('set', { user_id: userId });
|
||||||
// @if TARGET='app'
|
|
||||||
Native.getAppVersionInfo().then(({ localVersion }) => {
|
|
||||||
sendMatomoEvent('Version', 'Desktop-Version', localVersion);
|
|
||||||
});
|
|
||||||
// @endif
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
toggleInternal: (enabled: boolean): void => {
|
toggleInternal: (enabled: boolean): void => {
|
||||||
// Always collect analytics on lbry.tv
|
// Always collect analytics on Odysee for now.
|
||||||
// @if TARGET='app'
|
|
||||||
internalAnalyticsEnabled = enabled;
|
|
||||||
window.localStorage.setItem(SHARE_INTERNAL, enabled);
|
|
||||||
// @endif
|
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleThirdParty: (enabled: boolean): void => {
|
toggleThirdParty: (enabled: boolean): void => {
|
||||||
// Always collect analytics on lbry.tv
|
// Always collect analytics on Odysee for now.
|
||||||
// @if TARGET='app'
|
|
||||||
// thirdPartyAnalyticsEnabled = enabled;
|
|
||||||
window.localStorage.setItem(SHARE_THIRD_PARTY, enabled);
|
|
||||||
// @endif
|
|
||||||
},
|
},
|
||||||
|
|
||||||
apiLogView: (uri, outpoint, claimId, timeToStart) => {
|
apiLogView: (uri, outpoint, claimId, timeToStart) => {
|
||||||
|
@ -387,56 +337,57 @@ const analytics: Analytics = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
adsFetchedEvent: () => {
|
adsFetchedEvent: () => {
|
||||||
sendMatomoEvent('Media', 'AdsFetched');
|
sendGaEvent('ad_fetched');
|
||||||
},
|
},
|
||||||
adsReceivedEvent: (response) => {
|
adsReceivedEvent: (response) => {
|
||||||
sendMatomoEvent('Media', 'AdsReceived', JSON.stringify(response));
|
sendGaEvent('ad_received', { response: JSON.stringify(response) });
|
||||||
},
|
},
|
||||||
adsErrorEvent: (response) => {
|
adsErrorEvent: (response) => {
|
||||||
sendMatomoEvent('Media', 'AdsError', JSON.stringify(response));
|
sendGaEvent('ad_error', { response: JSON.stringify(response) });
|
||||||
},
|
},
|
||||||
playerLoadedEvent: (embedded) => {
|
playerLoadedEvent: (embedded) => {
|
||||||
sendMatomoEvent('Player', 'Loaded', embedded ? 'embedded' : 'onsite');
|
sendGaEvent('player', { action: 'loaded', type: embedded ? 'embedded' : 'onsite' });
|
||||||
},
|
},
|
||||||
playerStartedEvent: (embedded) => {
|
playerStartedEvent: (embedded) => {
|
||||||
sendMatomoEvent('Player', 'Started', embedded ? 'embedded' : 'onsite');
|
sendGaEvent('player', { action: 'started', type: embedded ? 'embedded' : 'onsite' });
|
||||||
},
|
},
|
||||||
tagFollowEvent: (tag, following) => {
|
tagFollowEvent: (tag, following) => {
|
||||||
sendMatomoEvent('Tag', following ? 'Tag-Follow' : 'Tag-Unfollow', tag);
|
sendGaEvent(following ? 'tag_follow' : 'tag_unfollow', { tag });
|
||||||
},
|
},
|
||||||
channelBlockEvent: (uri, blocked, location) => {
|
channelBlockEvent: (uri, blocked, location) => {
|
||||||
sendMatomoEvent(blocked ? 'Channel-Hidden' : 'Channel-Unhidden', uri);
|
sendGaEvent(blocked ? 'channel_hidden' : 'channel_unhidden', { uri });
|
||||||
},
|
},
|
||||||
emailProvidedEvent: () => {
|
emailProvidedEvent: () => {
|
||||||
sendMatomoEvent('Engagement', 'Email-Provided');
|
sendGaEvent('engagement', { type: 'email_provided' });
|
||||||
},
|
},
|
||||||
emailVerifiedEvent: () => {
|
emailVerifiedEvent: () => {
|
||||||
sendMatomoEvent('Engagement', 'Email-Verified');
|
sendGaEvent('engagement', { type: 'email_verified' });
|
||||||
},
|
},
|
||||||
rewardEligibleEvent: () => {
|
rewardEligibleEvent: () => {
|
||||||
sendMatomoEvent('Engagement', 'Reward-Eligible');
|
sendGaEvent('engagement', { type: 'reward_eligible' });
|
||||||
},
|
},
|
||||||
openUrlEvent: (url: string) => {
|
openUrlEvent: (url: string) => {
|
||||||
sendMatomoEvent('Engagement', 'Open-Url', url);
|
sendGaEvent('engagement', { type: 'open_url', url });
|
||||||
},
|
},
|
||||||
trendingAlgorithmEvent: (trendingAlgorithm: string) => {
|
trendingAlgorithmEvent: (trendingAlgorithm: string) => {
|
||||||
sendMatomoEvent('Engagement', 'Trending-Algorithm', trendingAlgorithm);
|
sendGaEvent('engagement', { type: 'trending_algorithm', trending_algorithm: trendingAlgorithm });
|
||||||
},
|
},
|
||||||
startupEvent: () => {
|
startupEvent: () => {
|
||||||
sendMatomoEvent('Startup', 'Startup');
|
// TODO: This can be removed (use the automated 'session_start' instead).
|
||||||
|
// sendGaEvent('startup', 'startup');
|
||||||
},
|
},
|
||||||
readyEvent: (timeToReady: number) => {
|
readyEvent: (timeToReadyMs: number) => {
|
||||||
sendMatomoEvent('Startup', 'App-Ready', 'Time', timeToReady);
|
sendGaEvent('startup_app_ready', { time_to_ready_ms: timeToReadyMs });
|
||||||
},
|
},
|
||||||
purchaseEvent: (purchaseInt: number) => {
|
purchaseEvent: (purchaseInt: number) => {
|
||||||
sendMatomoEvent('Purchase', 'Purchase-Complete', 'someLabel', purchaseInt);
|
// https://developers.google.com/analytics/devguides/collection/ga4/reference/events#purchase
|
||||||
|
sendGaEvent('purchase', { value: purchaseInt });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function sendMatomoEvent(category, action, name, value) {
|
function sendGaEvent(event: string, params?: { [string]: string | number }) {
|
||||||
if (internalAnalyticsEnabled) {
|
if (internalAnalyticsEnabled && isProduction && window.gtag) {
|
||||||
const event = { category, action, name, value };
|
window.gtag('event', event, params);
|
||||||
MatomoInstance.trackEvent(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,35 +400,12 @@ function sendPromMetric(name: string, value?: number) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const MatomoInstance = new MatomoTracker({
|
// Activate
|
||||||
urlBase: MATOMO_URL,
|
if (internalAnalyticsEnabled && isProduction && window.gtag) {
|
||||||
siteId: MATOMO_ID, // optional, default value: `1`
|
window.gtag('consent', 'update', {
|
||||||
// heartBeat: { // optional, enabled by default
|
ad_storage: 'granted',
|
||||||
// active: true, // optional, default value: true
|
analytics_storage: 'granted',
|
||||||
// seconds: 10 // optional, default value: `15
|
|
||||||
// },
|
|
||||||
// linkTracking: false // optional, default value: true
|
|
||||||
});
|
|
||||||
|
|
||||||
// Manually call the first page view
|
|
||||||
// React Router doesn't include this on `history.listen`
|
|
||||||
// @if TARGET='web'
|
|
||||||
analytics.pageView(window.location.pathname + window.location.search, window.location.search);
|
|
||||||
// @endif
|
|
||||||
|
|
||||||
// @if TARGET='app'
|
|
||||||
analytics.pageView(
|
|
||||||
window.location.pathname.split('.html')[1] + window.location.search || generateInitialUrl(window.location.hash)
|
|
||||||
);
|
|
||||||
// @endif;
|
|
||||||
|
|
||||||
// Listen for url changes and report
|
|
||||||
// This will include search queries
|
|
||||||
history.listen((location) => {
|
|
||||||
const { pathname, search } = location;
|
|
||||||
|
|
||||||
const page = `${pathname}${search}`;
|
|
||||||
analytics.pageView(page, search);
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export default analytics;
|
export default analytics;
|
||||||
|
|
|
@ -1264,11 +1264,6 @@
|
||||||
"@babel/helper-validator-identifier" "^7.14.9"
|
"@babel/helper-validator-identifier" "^7.14.9"
|
||||||
to-fast-properties "^2.0.0"
|
to-fast-properties "^2.0.0"
|
||||||
|
|
||||||
"@datapunt/matomo-tracker-js@^0.1.4":
|
|
||||||
version "0.1.4"
|
|
||||||
resolved "https://registry.yarnpkg.com/@datapunt/matomo-tracker-js/-/matomo-tracker-js-0.1.4.tgz#1226f0964d2c062bf9392e9c2fd89838262b10df"
|
|
||||||
integrity sha512-bi8/guszgciSNLJQIFgph27AzkiCF1DmLBxtmJE3CsLxfc0aTgI2vMg3EFoLv13Mu8HLaCs27Z7vbttlD6jp5w==
|
|
||||||
|
|
||||||
"@develar/schema-utils@~2.6.5":
|
"@develar/schema-utils@~2.6.5":
|
||||||
version "2.6.5"
|
version "2.6.5"
|
||||||
resolved "https://registry.yarnpkg.com/@develar/schema-utils/-/schema-utils-2.6.5.tgz#3ece22c5838402419a6e0425f85742b961d9b6c6"
|
resolved "https://registry.yarnpkg.com/@develar/schema-utils/-/schema-utils-2.6.5.tgz#3ece22c5838402419a6e0425f85742b961d9b6c6"
|
||||||
|
|
Loading…
Reference in a new issue