From 97ec1efce2bdffd7eeadbbb024fc6f3ffaebfb1e Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 8 Jun 2018 19:50:41 +0200 Subject: Add GA events --- src/InstallNotification.vue | 10 ++++++++++ src/IntroBox.vue | 2 +- src/RouterParamMixin.js | 2 ++ src/index.html | 7 ------- src/index.js | 18 ++++++++++++++++-- 5 files changed, 29 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/InstallNotification.vue b/src/InstallNotification.vue index 22e7a8c..a60ec9c 100644 --- a/src/InstallNotification.vue +++ b/src/InstallNotification.vue @@ -29,15 +29,25 @@ export default Vue.component('install-notification', { }, methods: { promptInstall: function(p) { + this.$ga.event('PWA', 'available'); p.preventDefault(); this.deferredPrompt = p; + this.deferredPrompt.userChoice.then((choiceResult) => { + this.$ga.event('PWA', 'popup', choiceResult.outcome); + this.deferredPrompt = null; + }); + }, + installed: function(e) { + this.$ga.event('PWA', 'installed'); }, }, created: function() { window.addEventListener('beforeinstallprompt', this.promptInstall); + window.addEventListener('appinstalled', this.installed); }, destroyed: function() { window.removeEventListener('beforeinstallprompt', this.promptInstall); + window.removeEventListener('appinstalled', this.installed); }, }); diff --git a/src/IntroBox.vue b/src/IntroBox.vue index 918a6de..d146f2f 100644 --- a/src/IntroBox.vue +++ b/src/IntroBox.vue @@ -13,7 +13,7 @@ The data can be imprecise and can be contrary to your personal experience.

- This site shares visitor data with Google Analytics and Google AdSense which store cookies. If you do not want that, you can use the Google Analytics opt out service and opt out of targeted advertisements. + This site shares visitor data with Google Analytics and Google AdSense which store cookies. If you do not want that, you can opt out of Google Analytics and opt out of targeted advertisements.

diff --git a/src/RouterParamMixin.js b/src/RouterParamMixin.js index 62f5cd9..6172d55 100644 --- a/src/RouterParamMixin.js +++ b/src/RouterParamMixin.js @@ -5,6 +5,7 @@ export default { return this.$route.query.actor || '*Kensei*'; }, set: function(value) { + this.$ga.event('Hero', 'update', value); const query = Object.assign({}, this.$route.query, { actor: value }); this.$router.push({ query }); }, @@ -14,6 +15,7 @@ export default { return this.$route.query.mode || 'blitz_pvp_ranked'; }, set: function(value) { + this.$ga.event('Mode', 'update', value); const query = Object.assign({}, this.$route.query, { mode: value }); this.$router.push({ query }); }, diff --git a/src/index.html b/src/index.html index d4e5348..c0e4ea1 100644 --- a/src/index.html +++ b/src/index.html @@ -18,13 +18,6 @@ enable_page_level_ads: true }); - - diff --git a/src/index.js b/src/index.js index 18eb719..9f511cf 100644 --- a/src/index.js +++ b/src/index.js @@ -3,6 +3,7 @@ import VueRouter from 'vue-router'; import Buefy from 'buefy' import 'buefy/lib/buefy.css' import Ads from 'vue-google-adsense'; +import VueAnalytics from 'vue-analytics' import App from './App.vue'; import ModeTab from './ModeTab.vue'; @@ -12,8 +13,8 @@ import ModeTab from './ModeTab.vue'; Vue.use(VueRouter); Vue.use(Buefy); -Vue.use(require('vue-script2')) -Vue.use(Ads.Adsense) +Vue.use(require('vue-script2')); +Vue.use(Ads.Adsense); const router = new VueRouter({ routes: [ { @@ -23,14 +24,27 @@ const router = new VueRouter({ } ] }); +Vue.use(VueAnalytics, { + id: 'UA-118868480-1', + router, + debug: { + sendHitTask: process.env.NODE_ENV === 'production', + enabled: process.env.NODE_ENV !== 'production', + } +}); + new Vue({ router, el: '#app', render: h => h(App), mounted: function() { + if (window.matchMedia('(display-mode: standalone)').matches || window.navigator.standalone === true) { + this.$ga.event('PWA', 'started'); + } if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/service-worker.js').then((registration) => { if (typeof registration.update == 'function') { + this.$ga.event('PWA', 'update'); registration.update(); } }); -- cgit v1.3.1