From 1dc1923d7b0b3c6afdff2615c0e3dd4e5dbd5d35 Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Fri, 8 Sep 2017 21:23:58 +0200 Subject: [PATCH] Client Analytics (#9023) * start to refactor analytics and some mixins * wip * wip * wip * more analytics * more analytics * more anlytics * fix analytics module * finish analytics * fix env * vue casing --- website/client/app.vue | 18 ++- .../components/achievements/lowHealth.vue | 9 ++ website/client/components/appFooter.vue | 7 + website/client/components/appMenu.vue | 7 + .../client/components/auth/registerLogin.vue | 9 ++ .../components/challenges/challengeModal.vue | 2 + .../components/groups/createPartyModal.vue | 19 ++- website/client/components/groups/group.vue | 25 ++- .../components/groups/groupFormModal.vue | 9 +- .../client/components/groups/inviteModal.vue | 13 +- .../components/groups/startQuestModal.vue | 14 +- .../client/components/notificationMenu.vue | 4 + website/client/components/shops/buyModal.vue | 9 ++ .../client/components/static/groupPlans.vue | 20 +++ website/client/components/static/header.vue | 37 +++-- .../components/static/{front.vue => home.vue} | 14 +- website/client/components/tasks/task.vue | 2 + website/client/libs/analytics.js | 143 ++++++++++++++++++ website/client/main.js | 3 + website/client/mixins/analytics.js | 86 ----------- website/client/mixins/guide.js | 23 ++- website/client/mixins/payments.js | 2 +- website/client/router.js | 12 +- website/client/store/actions/auth.js | 21 --- website/client/store/actions/chat.js | 31 +++- website/client/store/actions/quests.js | 11 +- 26 files changed, 402 insertions(+), 148 deletions(-) rename website/client/components/static/{front.vue => home.vue} (99%) create mode 100644 website/client/libs/analytics.js delete mode 100644 website/client/mixins/analytics.js diff --git a/website/client/app.vue b/website/client/app.vue index b16ff2beab..897be86f33 100644 --- a/website/client/app.vue +++ b/website/client/app.vue @@ -69,6 +69,7 @@ import AppFooter from './components/appFooter'; import notificationsDisplay from './components/notifications'; import snackbars from './components/snackbars/notifications'; import { mapState } from 'client/libs/store'; +import * as Analytics from 'client/libs/analytics'; import BuyModal from './components/shops/buyModal.vue'; import SelectMembersModal from 'client/components/selectMembersModal.vue'; import notifications from 'client/mixins/notifications'; @@ -158,14 +159,27 @@ export default { this.$store.dispatch('tasks:fetchUserTasks'), ]).then(() => { this.isUserLoaded = true; + Analytics.setUser(); + Analytics.updateUser(); }).catch((err) => { console.error('Impossible to fetch user. Clean up localStorage and refresh.', err); // eslint-disable-line no-console }); } // Manage modals - this.$root.$on('show::modal', (modalId, data) => { - if (data && data.fromRoot) return; + this.$root.$on('show::modal', (modalId, data = {}) => { + if (data.fromRoot) return; + + // Track opening of gems modal unless it's been already tracked + // For example the gems button in the menu already tracks the event by itself + if (modalId === 'buy-gems' && data.alreadyTracked !== true) { + Analytics.track({ + hitType: 'event', + eventCategory: 'button', + eventAction: 'click', + eventLabel: 'Gems > Wallet', + }); + } // Get last modal on stack and hide let modalStackLength = this.$store.state.modalStack.length; diff --git a/website/client/components/achievements/lowHealth.vue b/website/client/components/achievements/lowHealth.vue index 7ee8e8d043..feedcfcbd0 100644 --- a/website/client/components/achievements/lowHealth.vue +++ b/website/client/components/achievements/lowHealth.vue @@ -60,6 +60,7 @@ import bModal from 'bootstrap-vue/lib/components/modal'; import Avatar from '../avatar'; import { mapState } from 'client/libs/store'; +import * as Analytics from 'client/libs/analytics'; import percent from '../../../common/script/libs/percent'; import {maxHealth} from '../../../common/script/index'; @@ -84,6 +85,14 @@ export default { return `${Math.ceil(this.user.stats.hp)} / ${this.maxHealth}`; }, }, + mounted () { + Analytics.track({ + hitType: 'event', + eventCategory: 'button', + eventAction: 'click', + eventLabel: 'Health Warning', + }); + }, methods: { close () { this.$root.$emit('hide::modal', 'low-health'); diff --git a/website/client/components/appFooter.vue b/website/client/components/appFooter.vue index b3a4e77f81..c2d894748e 100644 --- a/website/client/components/appFooter.vue +++ b/website/client/components/appFooter.vue @@ -219,6 +219,7 @@ import axios from 'axios'; import moment from 'moment'; import { mapState } from 'client/libs/store'; +import * as Analytics from 'client/libs/analytics'; import gryphon from 'assets/svg/gryphon.svg'; import twitter from 'assets/svg/twitter.svg'; @@ -331,6 +332,12 @@ export default { this.$root.$emit('show::modal', 'modify-inventory'); }, donate () { + Analytics.track({ + hitType: 'event', + eventCategory: 'button', + eventAction: 'click', + eventLabel: 'Gems > Donate', + }); this.$root.$emit('show::modal', 'buy-gems'); }, }, diff --git a/website/client/components/appMenu.vue b/website/client/components/appMenu.vue index 68c215ed35..ff5f15c83c 100644 --- a/website/client/components/appMenu.vue +++ b/website/client/components/appMenu.vue @@ -224,6 +224,7 @@ div diff --git a/website/client/components/static/header.vue b/website/client/components/static/header.vue index b9f32e1c80..420a72b668 100644 --- a/website/client/components/static/header.vue +++ b/website/client/components/static/header.vue @@ -91,20 +91,29 @@ diff --git a/website/client/components/static/front.vue b/website/client/components/static/home.vue similarity index 99% rename from website/client/components/static/front.vue rename to website/client/components/static/home.vue index d3efb36dac..ddafea71f9 100644 --- a/website/client/components/static/front.vue +++ b/website/client/components/static/home.vue @@ -602,6 +602,7 @@