From 8900038a4a8d117ef66acd64307cf28087939975 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Mon, 4 Nov 2019 13:36:37 -0500 Subject: [PATCH] use new analytics id for non-pb traffic --- src/ui/analytics.js | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/ui/analytics.js b/src/ui/analytics.js index 5540390c5..85da50284 100644 --- a/src/ui/analytics.js +++ b/src/ui/analytics.js @@ -9,6 +9,15 @@ import ElectronCookies from '@exponent/electron-cookies'; const isProduction = process.env.NODE_ENV === 'production'; const devInternalApis = process.env.LBRY_API_URL; +const LBRY_TV_MINUS_PIRATE_BAY_UA_ID = 'UA-60403362-16'; +const LBRY_TV_UA_ID = 'UA-60403362-12'; +const DESKTOP_UA_ID = 'UA-60403362-13'; + +// @if TARGET='app' +ElectronCookies.enable({ + origin: 'https://lbry.tv', +}); +// @endif type Analytics = { pageView: string => void, @@ -157,18 +166,29 @@ function sendGaTimingEvent(category: string, action: string, timeInMs: number) { } } -// Initialize google analytics -// Set `debug: true` for debug info -// Will change once we have separate ids for desktop/web -const UA_ID = IS_WEB ? 'UA-60403362-12' : 'UA-60403362-13'; +let gaTrackers = []; -// @if TARGET='app' -ElectronCookies.enable({ - origin: 'https://lbry.tv', -}); -// @endif +if (!IS_WEB) { + gaTrackers.push({ + trackingId: DESKTOP_UA_ID, + }); +} else { + gaTrackers.push({ + trackingId: LBRY_TV_UA_ID, + }); -ReactGA.initialize(UA_ID, { + const { search } = window.location; + const urlParams = new URLSearchParams(search); + const isPirateBayUser = urlParams.get('tm_source') === 'PB'; + + if (!isPirateBayUser) { + gaTrackers.push({ + trackingId: LBRY_TV_MINUS_PIRATE_BAY_UA_ID, + }); + } +} + +ReactGA.initialize(gaTrackers, { testMode: process.env.NODE_ENV !== 'production', cookieDomain: 'auto', siteSpeedSampleRate: 100,