Skip to content

Commit

Permalink
feat(App): Remove Google Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Dec 13, 2021
1 parent d0968d1 commit 3840dd6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 42 deletions.
61 changes: 26 additions & 35 deletions src/lib/analytics.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,44 @@
import { app } from '@electron/remote';
import querystring from 'querystring';
// import querystring from 'querystring';

import { STATS_API } from '../config';
import { isDevMode, GA_ID } from '../environment';
// import { STATS_API } from '../config';
// import { isDevMode, GA_ID } from '../environment';

const debug = require('debug')('Franz:Analytics');

/* eslint-disable */
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
const _paq = window._paq = window._paq || [];

_paq.push(['setCustomDimension', 1, app.getVersion()]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);

(function() {
const u="https:////analytics.franzinfra.com/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
const d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
/* eslint-enable */

const GA_LOCAL_STORAGE_KEY = 'gaUid';
// const GA_LOCAL_STORAGE_KEY = 'gaUid';

ga('create', GA_ID, {
storage: 'none',
clientId: localStorage.getItem(GA_LOCAL_STORAGE_KEY),
});
// ga((tracker) => {
// localStorage.setItem(GA_LOCAL_STORAGE_KEY, tracker.get('clientId'));
// });
// ga('set', 'checkProtocolTask', null);
// ga('set', 'version', app.getVersion());

ga((tracker) => {
localStorage.setItem(GA_LOCAL_STORAGE_KEY, tracker.get('clientId'));
});
ga('set', 'checkProtocolTask', null);
ga('set', 'version', app.getVersion());
ga('send', 'App');
// ga('send', 'App');

export function gaPage(page) {
ga('send', 'pageview', page);
_paq.push(['trackPageView']);
debug('GA track page', page);
}

export function gaEvent(category, action, label) {
ga('send', 'event', category, action, label);
// ga('send', 'event', category, action, label);
_paq.push(['trackEvent', category, action, label]);
debug('GA track event', category, action, label);
}

export function statsEvent(key, value) {
const params = {
key,
value: value || key,
platform: process.platform,
version: app.getVersion(),
};

debug('Send Franz stats event', params);

if (!isDevMode) {
window.fetch(`${STATS_API}/event/?${querystring.stringify(params)}`);
}
}
6 changes: 1 addition & 5 deletions src/stores/AppStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Request from './lib/Request';
import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config';
import { isMac } from '../environment';
import locales from '../i18n/translations';
import { gaEvent, gaPage, statsEvent } from '../lib/analytics';
import { gaEvent, gaPage } from '../lib/analytics';
import { getLocale } from '../helpers/i18n-helpers';

import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js';
Expand Down Expand Up @@ -227,8 +227,6 @@ export default class AppStore extends Store {
window.location.reload();
}
}, ms('2s'));

statsEvent('resumed-app');
}
});

Expand All @@ -246,8 +244,6 @@ export default class AppStore extends Store {
localStorage.setItem(CATALINA_NOTIFICATION_HACK_KEY, true);
}
}

statsEvent('app-start');
}

@computed get cacheSize() {
Expand Down
4 changes: 2 additions & 2 deletions src/stores/ServicesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Store from './lib/Store';
import Request from './lib/Request';
import CachedRequest from './lib/CachedRequest';
import { matchRoute } from '../helpers/routing-helpers';
import { gaEvent, statsEvent } from '../lib/analytics';
import { gaEvent } from '../lib/analytics';
import { workspaceStore } from '../features/workspaces';
import { serviceLimitStore } from '../features/serviceLimit';
import { RESTRICTION_TYPES } from '../models/Service';
Expand Down Expand Up @@ -407,7 +407,7 @@ export default class ServicesStore extends Store {
this.actions.todos.toggleTodosFeatureVisibility();
}

statsEvent('activate-service', service.recipe.id);
gaEvent('Service', 'activate-service', service.recipe.id);

this._focusActiveService();
}
Expand Down

0 comments on commit 3840dd6

Please sign in to comment.