Move more analytics to server (#12782)

* track events on the client by default, remove unused ones

* fix lint, remove some calls to updateUser

* remove dead code from guide.js
This commit is contained in:
Matteo Pagliazzi
2020-11-13 15:42:46 +01:00
committed by GitHub
parent 41de90e578
commit d3ba0346af
12 changed files with 11 additions and 53 deletions

View File

@@ -232,7 +232,7 @@ export default {
eventCategory: 'drop-cap-reached', eventCategory: 'drop-cap-reached',
eventAction: 'click', eventAction: 'click',
eventLabel: 'Drop Cap Reached > Modal > Wiki', eventLabel: 'Drop Cap Reached > Modal > Wiki',
}, { trackOnServer: true }); });
}, },
toLearnMore () { toLearnMore () {
Analytics.track({ Analytics.track({
@@ -240,7 +240,7 @@ export default {
eventCategory: 'drop-cap-reached', eventCategory: 'drop-cap-reached',
eventAction: 'click', eventAction: 'click',
eventLabel: 'Drop Cap Reached > Modal > Subscriptions', eventLabel: 'Drop Cap Reached > Modal > Subscriptions',
}, { trackOnServer: true }); });
this.close(); this.close();
this.$router.push('/user/settings/subscription'); this.$router.push('/user/settings/subscription');

View File

@@ -622,13 +622,6 @@ export default {
await this.$store.dispatch('guilds:join', { groupId: this.group._id, type: 'guild' }); await this.$store.dispatch('guilds:join', { groupId: this.group._id, type: 'guild' });
}, },
clickLeave () { clickLeave () {
Analytics.track({
hitType: 'event',
eventCategory: 'button',
eventAction: 'click',
eventLabel: 'Leave Party',
});
// @TODO: Get challenges and ask to keep or remove // @TODO: Get challenges and ask to keep or remove
if (!window.confirm('Are you sure you want to leave?')) return; // eslint-disable-line no-alert if (!window.confirm('Are you sure you want to leave?')) return; // eslint-disable-line no-alert
const keep = true; const keep = true;

View File

@@ -36,7 +36,7 @@ export default {
eventCategory: 'drop-cap-reached', eventCategory: 'drop-cap-reached',
eventAction: 'click', eventAction: 'click',
eventLabel: 'Drop Cap Reached > Notification Click', eventLabel: 'Drop Cap Reached > Notification Click',
}, { trackOnServer: true }); });
}, },
}, },
}; };

View File

@@ -183,7 +183,7 @@ export default {
eventCategory: 'button', eventCategory: 'button',
eventAction: 'click', eventAction: 'click',
eventLabel: 'User Dropdown > Subscriptions', eventLabel: 'User Dropdown > Subscriptions',
}, { trackOnServer: true }); });
this.$router.push({ name: 'subscription' }); this.$router.push({ name: 'subscription' });
}, },

View File

@@ -386,7 +386,6 @@ import size from 'lodash/size';
import reduce from 'lodash/reduce'; import reduce from 'lodash/reduce';
import moment from 'moment'; import moment from 'moment';
import * as Analytics from '@/libs/analytics';
import spellsMixin from '@/mixins/spells'; import spellsMixin from '@/mixins/spells';
import planGemLimits from '@/../../common/script/libs/planGemLimits'; import planGemLimits from '@/../../common/script/libs/planGemLimits';
import numberInvalid from '@/mixins/numberInvalid'; import numberInvalid from '@/mixins/numberInvalid';
@@ -611,14 +610,6 @@ export default {
} }
}, },
purchaseGems () { purchaseGems () {
if (this.item.key === 'rebirth_orb') {
Analytics.track({
hitType: 'event',
eventCategory: 'button',
eventAction: 'click',
eventLabel: 'Gems > Rebirth',
});
}
this.$root.$emit('bv::show::modal', 'buy-gems'); this.$root.$emit('bv::show::modal', 'buy-gems');
}, },
togglePinned () { togglePinned () {

View File

@@ -286,13 +286,13 @@ export default {
} }
// @TODO duplicate of code in home.vue // @TODO duplicate of code in home.vue
Analytics.track({ Analytics.track({
hitType: 'event', hitType: 'event',
eventCategory: 'button', eventCategory: 'button',
eventAction: 'click', eventAction: 'click',
eventLabel: 'Play', eventLabel: 'Play',
}); });
this.$router.push('/register'); this.$router.push('/register');
}, },
scrollToMobileApp () { scrollToMobileApp () {

View File

@@ -897,13 +897,6 @@ export default {
}, },
}, },
mounted () { mounted () {
Analytics.track({
hitType: 'pageview',
eventCategory: 'page',
eventAction: 'landing page',
page: '/static/home',
});
hello.init({ hello.init({
facebook: process.env.FACEBOOK_KEY, // eslint-disable-line facebook: process.env.FACEBOOK_KEY, // eslint-disable-line
// windows: WINDOWS_CLIENT_ID, // windows: WINDOWS_CLIENT_ID,

View File

@@ -82,7 +82,6 @@
<script> <script>
import moment from 'moment'; import moment from 'moment';
import * as Analytics from '@/libs/analytics';
import { mapState } from '@/libs/store'; import { mapState } from '@/libs/store';
import scoreTask from '@/mixins/scoreTask'; import scoreTask from '@/mixins/scoreTask';
import Task from './task'; import Task from './task';
@@ -181,8 +180,6 @@ export default {
this.isLoading = false; this.isLoading = false;
this.$root.$emit('bv::hide::modal', 'yesterdaily'); this.$root.$emit('bv::hide::modal', 'yesterdaily');
Analytics.updateUser();
}, },
}, },
}; };

View File

@@ -88,14 +88,14 @@ export function track (properties, options = {}) {
if (_doesNotHaveRequiredFields(properties)) return; if (_doesNotHaveRequiredFields(properties)) return;
if (_doesNotHaveAllowedHitType(properties)) return; if (_doesNotHaveAllowedHitType(properties)) return;
const trackOnServer = options && options.trackOnServer === true; const trackOnClient = options && options.trackOnClient === true;
if (trackOnServer === true) { // Track events on the server by default
// Track an event on the server if (trackOnClient === true) {
const store = getStore();
store.dispatch('analytics:trackEvent', properties);
} else {
amplitude.getInstance().logEvent(properties.eventAction, properties); amplitude.getInstance().logEvent(properties.eventAction, properties);
window.ga('send', properties); window.ga('send', properties);
} else {
const store = getStore();
store.dispatch('analytics:trackEvent', properties);
} }
}); });
} }

View File

@@ -143,12 +143,6 @@ export default {
return null; return null;
}, },
hoyo (user) {
// @TODO: What is was the timeout for?
// @TODO move to analytics
window.amplitude.setUserId(user._id);
window.ga('set', { userId: user._id });
},
goto (chapter, page, force) { goto (chapter, page, force) {
if (chapter === 'intro' && this.user.flags.welcomed !== true) { if (chapter === 'intro' && this.user.flags.welcomed !== true) {
// @TODO: Add dispatch User.set({'flags.welcomed': true}); // @TODO: Add dispatch User.set({'flags.welcomed': true});

View File

@@ -1,6 +1,5 @@
import Vue from 'vue'; import Vue from 'vue';
import * as Analytics from '@/libs/analytics';
import notifications from './notifications'; import notifications from './notifications';
import scoreTask from '@/../../common/script/ops/scoreTask'; import scoreTask from '@/../../common/script/ops/scoreTask';
import { mapState } from '@/libs/store'; import { mapState } from '@/libs/store';
@@ -64,7 +63,6 @@ export default {
this.playTaskScoreSound(task, direction); this.playTaskScoreSound(task, direction);
Analytics.updateUser();
const response = await this.$store.dispatch('tasks:score', { const response = await this.$store.dispatch('tasks:score', {
taskId: task._id, taskId: task._id,
direction, direction,

View File

@@ -1,7 +1,6 @@
import Vue from 'vue'; import Vue from 'vue';
import VueRouter from 'vue-router'; import VueRouter from 'vue-router';
import getStore from '@/store'; import getStore from '@/store';
import * as Analytics from '@/libs/analytics';
import handleRedirect from './handleRedirect'; import handleRedirect from './handleRedirect';
import ParentPage from '@/components/parentPage'; import ParentPage from '@/components/parentPage';
@@ -412,13 +411,6 @@ router.beforeEach((to, from, next) => {
}); });
} }
Analytics.track({
hitType: 'pageview',
eventCategory: 'navigation',
eventAction: 'navigate',
page: to.name || to.path,
});
if ((to.name === 'userProfile' || to.name === 'userProfilePage') && from.name !== null) { if ((to.name === 'userProfile' || to.name === 'userProfilePage') && from.name !== null) {
let startingPage = 'profile'; let startingPage = 'profile';
if (to.params.startingPage !== undefined) { if (to.params.startingPage !== undefined) {