From 8d2369f1c05e56bbd4f620677af12f91c31af53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Jim=C3=A9nez?= Date: Tue, 30 Aug 2022 02:35:09 +0200 Subject: [PATCH] fix: remove useless analytics (#577) fix #512 --- app/lib/config.js | 13 ++------ app/lib/trackEvent.js | 36 ----------------------- app/main/components/Cerebro/index.js | 17 ----------- app/main/createWindow.js | 13 ++------ app/main/createWindow/donateDialog.js | 14 +-------- app/package.json | 3 +- app/plugins/core/plugins/Preview/index.js | 6 ---- app/yarn.lock | 20 ------------- package.json | 1 - yarn.lock | 5 ---- 10 files changed, 8 insertions(+), 120 deletions(-) delete mode 100644 app/lib/trackEvent.js diff --git a/app/lib/config.js b/app/lib/config.js index e1fe07cb..254e9975 100644 --- a/app/lib/config.js +++ b/app/lib/config.js @@ -1,7 +1,7 @@ import { app, ipcRenderer } from 'electron' import fs from 'fs' +import path from 'path' import { memoize } from 'cerebro-tools' -import { trackEvent } from './trackEvent' import loadThemes from './loadThemes' const remote = process.type === 'browser' @@ -14,11 +14,11 @@ const electronApp = remote ? remote.app : app // set data directory to ./userdata process.argv.forEach((arg) => { if (arg.toLowerCase() === '-p' || arg.toLowerCase() === '--portable') { - electronApp.setPath('userData', `${process.cwd()}/userdata`) + electronApp.setPath('userData', path.join(process.cwd(), 'userdata')) } }) -const CONFIG_FILE = `${electronApp.getPath('userData')}/config.json` +const CONFIG_FILE = path.join(electronApp.getPath('userData'), 'config.json') const defaultSettings = memoize(() => { const locale = electronApp.getLocale() || 'en-US' @@ -38,7 +38,6 @@ const defaultSettings = memoize(() => { lastShownDonateDialog: null, plugins: {}, isMigratedPlugins: false, - trackingEnabled: true, crashreportingEnabled: true, openAtLogin: true } @@ -85,12 +84,6 @@ const set = (key, value) => { } config[key] = value fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2)) - // Track settings changes - trackEvent({ - category: 'Settings', - event: `Change ${key}`, - label: value - }) if (ipcRenderer) { console.log('notify main process', key, value) diff --git a/app/lib/trackEvent.js b/app/lib/trackEvent.js deleted file mode 100644 index c22a11e7..00000000 --- a/app/lib/trackEvent.js +++ /dev/null @@ -1,36 +0,0 @@ -import ua from 'universal-analytics' -import { machineIdSync } from 'node-machine-id' -import { version as appVersion } from '../package.json' -import config from './config' - -const DEFAULT_CATEGORY = 'Cerebro App' - -const isTrackingEnabled = () => (process.env.NODE_ENV === 'production' && config.get('trackingEnabled')) - -let visitorCache = null - -const visitor = () => { - if (visitorCache) return visitorCache - - if (isTrackingEnabled()) { - try { - visitorCache = ua('UA-87361302-1', machineIdSync(), { strictCidFormat: false }) - } catch (err) { - console.log('[machine-id error]', err) - visitorCache = ua('UA-87361302-1') - } - } - return visitorCache -} - -export const screenView = (screenName) => { - if (isTrackingEnabled()) { - visitor().screenview(screenName, 'Cerebro', appVersion, process.platform) - } -} - -export const trackEvent = ({ category, event, label, value }) => { - if (isTrackingEnabled()) { - visitor().event(category || DEFAULT_CATEGORY, event, label, value).send() - } -} diff --git a/app/main/components/Cerebro/index.js b/app/main/components/Cerebro/index.js index 521641b8..849be675 100644 --- a/app/main/components/Cerebro/index.js +++ b/app/main/components/Cerebro/index.js @@ -10,7 +10,6 @@ import escapeStringRegexp from 'escape-string-regexp' import debounce from 'lodash/debounce' -import { trackEvent } from 'lib/trackEvent' import getWindowPosition from 'lib/getWindowPosition' import { WINDOW_WIDTH, @@ -29,19 +28,6 @@ const remote = process.type === 'browser' ? { getCurrentWindow: BrowserWindow.getFocusedWindow } : require('@electron/remote') -const SHOW_EVENT = { - category: 'Window', - event: 'show' -} - -const SELECT_EVENT = { - category: 'Plugins', - event: 'select' -} - -const trackShowWindow = () => trackEvent(SHOW_EVENT) -const trackSelectItem = (label) => trackEvent({ ...SELECT_EVENT, label }) - /** * Wrap click or mousedown event to custom `select-item` event, * that includes only information about clicked keys (alt, shift, ctrl and meta) @@ -112,7 +98,6 @@ class Cerebro extends Component { window.addEventListener('beforeunload', this.cleanup) this.electronWindow.on('show', this.focusMainInput) this.electronWindow.on('show', this.updateElectronWindow) - this.electronWindow.on('show', trackShowWindow) } componentDidMount() { @@ -268,7 +253,6 @@ class Cerebro extends Component { window.removeEventListener('beforeunload', this.cleanup) this.electronWindow.removeListener('show', this.focusMainInput) this.electronWindow.removeListener('show', this.updateElectronWindow) - this.electronWindow.removeListener('show', trackShowWindow) } focusMainInput() { @@ -290,7 +274,6 @@ class Cerebro extends Component { */ selectItem(item, realEvent) { this.props.actions.reset() - trackSelectItem(item.plugin) const event = wrapEvent(realEvent) item.onSelect(event) if (!event.defaultPrevented) { diff --git a/app/main/createWindow.js b/app/main/createWindow.js index f346394d..b9251601 100644 --- a/app/main/createWindow.js +++ b/app/main/createWindow.js @@ -1,7 +1,8 @@ -import { BrowserWindow, globalShortcut, app, screen, shell } from 'electron' +import { + BrowserWindow, globalShortcut, app, screen, shell +} from 'electron' import debounce from 'lodash/debounce' import EventEmitter from 'events' -import { trackEvent, screenView } from 'lib/trackEvent' import config from 'lib/config' import getWindowPosition from 'lib/getWindowPosition' @@ -176,14 +177,6 @@ export default ({ src, isDev }) => { setTimeout(donateDialog.show, 1000) } - // Track app start event - trackEvent({ - category: 'App Start', - event: config.get('firstStart') ? 'First' : 'Secondary' - }) - - screenView('Search') - // Save in config information, that application has been started config.set('firstStart', false) diff --git a/app/main/createWindow/donateDialog.js b/app/main/createWindow/donateDialog.js index a09bde1e..3132ea66 100644 --- a/app/main/createWindow/donateDialog.js +++ b/app/main/createWindow/donateDialog.js @@ -1,6 +1,5 @@ import { dialog, shell } from 'electron' import config from '../../lib/config' -import { trackEvent } from '../../lib/trackEvent' const now = () => new Date().getTime() const twoWeeksAgo = () => now() - 1000 * 3600 * 24 * 7 @@ -30,15 +29,6 @@ const skipMessages = ["I don't want to see this message again"] export const show = () => { config.set('lastShownDonateDialog', now()) const AB = Math.floor(Math.random() * buttons.length) - const track = (event) => { - trackEvent({ - event, - category: 'Donate Dialog', - label: AB - }) - } - - track('show-dialog') const options = { type: 'info', @@ -53,12 +43,10 @@ export const show = () => { const callback = (id, checkboxChecked) => { if (checkboxChecked) { config.set('skipDonateDialog', true) - track('skip-dialog') } if (id === 1) { - track('choose-donate') donate() - } else { track('cancel') } + } } setTimeout(() => { diff --git a/app/package.json b/app/package.json index 81a35a4e..c0e28b7a 100644 --- a/app/package.json +++ b/app/package.json @@ -20,8 +20,7 @@ "electron-updater": "5.0.1", "fix-path": "3.0.0", "rimraf": "3.0.2", - "semver": "7.3.7", - "universal-analytics": "0.5.3" + "semver": "7.3.7" }, "optionalDependencies": {}, "devDependencies": {} diff --git a/app/plugins/core/plugins/Preview/index.js b/app/plugins/core/plugins/Preview/index.js index 115de4e5..ed4f1f86 100644 --- a/app/plugins/core/plugins/Preview/index.js +++ b/app/plugins/core/plugins/Preview/index.js @@ -1,7 +1,6 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import { KeyboardNav, KeyboardNavItem, Preload } from '@cerebroapp/cerebro-ui' -import { trackEvent } from 'lib/trackEvent' import { client } from 'lib/plugins' import plugins from 'plugins' import ReactMarkdown from 'react-markdown' @@ -38,11 +37,6 @@ class Preview extends Component { pluginAction(plugin, runningAction) { return () => { this.setState({ runningAction }) - trackEvent({ - category: 'Plugins', - event: runningAction, - label: plugin - }) client[runningAction](plugin) } } diff --git a/app/yarn.lock b/app/yarn.lock index fa9a3253..dcdd1317 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -86,13 +86,6 @@ cross-spawn@^4.0.0: lru-cache "^4.0.1" which "^1.2.9" -debug@^4.3.1: - version "4.3.4" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" - integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== - dependencies: - ms "2.1.2" - debug@^4.3.2: version "4.3.2" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.2.tgz#f0a49c18ac8779e31d4a0c6029dfb76873c7428b" @@ -448,24 +441,11 @@ to-regex-range@^5.0.1: dependencies: is-number "^7.0.0" -universal-analytics@0.5.3: - version "0.5.3" - resolved "https://registry.yarnpkg.com/universal-analytics/-/universal-analytics-0.5.3.tgz#ff2d9b850062cdd4a8f652448047982a183c8e96" - integrity sha512-HXSMyIcf2XTvwZ6ZZQLfxfViRm/yTGoRgDeTbojtq6rezeyKB0sTBcKH2fhddnteAHRcHiKgr/ACpbgjGOC6RQ== - dependencies: - debug "^4.3.1" - uuid "^8.0.0" - universalify@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== -uuid@^8.0.0: - version "8.3.2" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" - integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== - which@^1.2.9: version "1.3.1" resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" diff --git a/package.json b/package.json index 61e0ef16..83951698 100644 --- a/package.json +++ b/package.json @@ -182,7 +182,6 @@ "cerebro-tools": "0.1.8", "escape-string-regexp": "5.0.0", "lodash": "4.17.21", - "node-machine-id": "1.1.12", "normalize.css": "8.0.1", "prop-types": "15.8.1", "react": "15.7.0", diff --git a/yarn.lock b/yarn.lock index 88a35ad1..fd0e5b8b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7451,11 +7451,6 @@ node-libs-browser@^2.2.1: util "^0.11.0" vm-browserify "^1.0.1" -node-machine-id@1.1.12: - version "1.1.12" - resolved "https://registry.yarnpkg.com/node-machine-id/-/node-machine-id-1.1.12.tgz#37904eee1e59b320bb9c5d6c0a59f3b469cb6267" - integrity sha512-QNABxbrPa3qEIfrE6GOJ7BYIuignnJw7iQ2YPbc3Nla1HzRJjXzZOiikfF8m7eAMfichLt3M4VgLOetqgDmgGQ== - node-releases@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.1.tgz#3d1d395f204f1f2f29a54358b9fb678765ad2fc5"