Compare commits

...

1 Commits

Author SHA1 Message Date
Phillip Thelen
c46bc2b0e5 Disable Amplitude on client for dev environment 2024-01-22 13:48:48 +01:00
2 changed files with 24 additions and 10 deletions

View File

@@ -8,9 +8,11 @@ import Vue from 'vue';
import getStore from '@/store'; import getStore from '@/store';
const IS_PRODUCTION = process.env.NODE_ENV === 'production'; // eslint-disable-line no-process-env const IS_PRODUCTION = process.env.NODE_ENV === 'production'; // eslint-disable-line no-process-env
const { AMPLITUDE_KEY } = process.env; // eslint-disable-line no-process-env const { AMPLITUDE_KEY, LOG_AMPLITUDE_EVENTS } = process.env; // eslint-disable-line no-process-env
const { GA_ID } = process.env; // eslint-disable-line no-process-env const { GA_ID } = process.env; // eslint-disable-line no-process-env
const ENABLE_AMPLITUDE = LOG_AMPLITUDE_EVENTS !== 'false' && AMPLITUDE_KEY !== undefined;
const REQUIRED_FIELDS = ['hitType', 'eventCategory', 'eventAction']; const REQUIRED_FIELDS = ['hitType', 'eventCategory', 'eventAction'];
const ALLOWED_HIT_TYPES = [ const ALLOWED_HIT_TYPES = [
'pageview', 'pageview',
@@ -78,7 +80,12 @@ function _gatherUserStats (properties) {
export function setUser () { export function setUser () {
const store = getStore(); const store = getStore();
const user = store.state.user.data; const user = store.state.user.data;
if (ENABLE_AMPLITUDE) {
console.log(LOG_AMPLITUDE_EVENTS)
console.log(AMPLITUDE_KEY)
console.log('Setting Amplitude user ID to', user._id);
amplitude.getInstance().setUserId(user._id); amplitude.getInstance().setUserId(user._id);
}
window.ga('set', { userId: user._id }); window.ga('set', { userId: user._id });
} }
@@ -91,7 +98,10 @@ export function track (properties, options = {}) {
const trackOnClient = options && options.trackOnClient === true; const trackOnClient = options && options.trackOnClient === true;
// Track events on the server by default // Track events on the server by default
if (trackOnClient === true) { if (trackOnClient === true) {
if (ENABLE_AMPLITUDE) {
console.log('Tracking Amplitude event', properties.eventAction);
amplitude.getInstance().logEvent(properties.eventAction, properties); amplitude.getInstance().logEvent(properties.eventAction, properties);
}
window.ga('send', properties); window.ga('send', properties);
} else { } else {
const store = getStore(); const store = getStore();
@@ -105,10 +115,12 @@ export function updateUser (properties = {}) {
Vue.nextTick(() => { Vue.nextTick(() => {
_gatherUserStats(properties); _gatherUserStats(properties);
if (ENABLE_AMPLITUDE) {
forEach(properties, (value, key) => { forEach(properties, (value, key) => {
const identify = new amplitude.Identify().set(key, value); const identify = new amplitude.Identify().set(key, value);
amplitude.getInstance().identify(identify); amplitude.getInstance().identify(identify);
}); });
}
window.ga('set', properties); window.ga('set', properties);
}); });
@@ -118,9 +130,10 @@ export function setup () {
// Setup queues until the real scripts are loaded // Setup queues until the real scripts are loaded
/* eslint-disable */ /* eslint-disable */
if (ENABLE_AMPLITUDE) {
// Amplitude // Amplitude
amplitude.getInstance().init(AMPLITUDE_KEY); amplitude.getInstance().init(AMPLITUDE_KEY);
}
// Google Analytics (aka Universal Analytics) // Google Analytics (aka Universal Analytics)
window['GoogleAnalyticsObject'] = 'ga'; window['GoogleAnalyticsObject'] = 'ga';

View File

@@ -27,6 +27,7 @@ const envVars = [
'GOOGLE_CLIENT_ID', 'GOOGLE_CLIENT_ID',
'APPLE_AUTH_CLIENT_ID', 'APPLE_AUTH_CLIENT_ID',
'AMPLITUDE_KEY', 'AMPLITUDE_KEY',
'LOG_AMPLITUDE_EVENTS',
'LOGGLY_CLIENT_TOKEN', 'LOGGLY_CLIENT_TOKEN',
'TRUSTED_DOMAINS', 'TRUSTED_DOMAINS',
// TODO necessary? if yes how not to mess up with vue cli? 'NODE_ENV' // TODO necessary? if yes how not to mess up with vue cli? 'NODE_ENV'