Skip to content

Commit

Permalink
Use Vue Analytics to track everything
Browse files Browse the repository at this point in the history
  • Loading branch information
EmperorArthur committed Jun 10, 2019
1 parent 1c35a28 commit 8c51fbb
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 93 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"uikit": "^3.1.5",
"vue": "^2.6.10",
"vue-analytics": "^5.17.0",
"vue-router": "^3.0.6",
"vuex": "^3.1.1"
}
Expand Down
13 changes: 10 additions & 3 deletions resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ require('jquery-ui/ui/widgets/tooltip');
//UiKit
require('uikit');

//Google Analytics
require('./googleAnalytics').init();

//Background slide show
require('./background').init();

//Vue and associated pieces
const Vue = require('vue');
const Vuex = require('vuex');
const VueRouter = require('vue-router').default;
import VueAnalytics from 'vue-analytics';

Vue.use(Vuex);
Vue.use(VueRouter);
Expand Down Expand Up @@ -63,6 +61,15 @@ const router = new VueRouter({
],
});

Vue.use(VueAnalytics, {
//If the variable isn't set dynamically, try the compiled in version. If that fails, then fall back to a safe default.
id: window.env.MIX_GOOGLE_ANALYTICS_ID || process.env.MIX_GOOGLE_ANALYTICS_ID || 'UA-463340-1',
// debug: {
// enabled: true,
// sendHitTask: false,
// },
router,
});

//Do an initial check on the creator during the first page load
//This must be done here, so we can wait for the asynchronous call to complete before finishing routing
Expand Down
14 changes: 11 additions & 3 deletions resources/js/components/MainMenu.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div id="mainMenu">
<a href="/api/creator/save">
<button class="popupButton">
<button @click="$ga.event('character', 'save')" class="popupButton">
Save
</button>
</a>
Expand All @@ -20,8 +20,16 @@
</button>
<div class='dropdown-content'>
<ul>
<li><a id="exportPdfButton" href="/export/pdf" target="_blank">PDF</a></li>
<li><a id="exportTxtButton" href="/export/txt" target="_blank">TXT</a></li>
<li>
<a @click="$ga.event('character', 'export', 'pdf')" href="/export/pdf" target="_blank">
PDF
</a>
</li>
<li>
<a @click="$ga.event('character', 'export', 'txt')" href="/export/txt" target="_blank">
TXT
</a>
</li>
</ul>
</div>
</div>
Expand Down
12 changes: 7 additions & 5 deletions resources/js/components/modals/About.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :id="id" class="uk-flex-top" v-on:toggle="shown" uk-modal>
<div :id="id" class="uk-flex-top" v-on:toggle="toggled" uk-modal>
<div class="uk-modal-dialog uk-modal-body uk-margin-auto-vertical game-style">
<button class="uk-modal-close-default" type="button" uk-close></button>
<a href="https://github.com/Eclipse-Phase-Unofficial/ep-character-creator/"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_left_gray_6d6d6d.png" alt="Fork me on GitHub"></a>
Expand Down Expand Up @@ -59,10 +59,12 @@
}
},
methods: {
// This happens whenever the Modal is shown (via UiKit)
shown: function (event) {
ga('set', 'page', '/about');
ga('send', 'pageview');
// This happens whenever the Modal is shown/hidden (via UiKit)
toggled: function (event) {
//This is run before uk-open is applied, so the absence means shown
if(!this.$el.classList.contains('uk-open')) {
this.$ga.page('/about');
}
//Only do this once per run
//TODO: This could be done in VueX and used everywhere
if (!this.version) {
Expand Down
17 changes: 11 additions & 6 deletions resources/js/components/modals/LoadDialog.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :id="id" class="uk-flex-top" v-on:toggle="shown" uk-modal>
<div :id="id" class="uk-flex-top" v-on:toggle="toggled" uk-modal>
<div class="uk-modal-dialog uk-modal-body uk-margin-auto-vertical game-style" style="min-width: 80ch">
<button class="uk-modal-close-default" type="button" uk-close></button>
<div class="uk-text-center">
Expand Down Expand Up @@ -48,7 +48,7 @@
import urls from "../../urls";
export default {
name: "SaveDialog",
name: "LoadDialog",
props: {
id: String
},
Expand All @@ -62,10 +62,12 @@
}
},
methods: {
// This happens whenever the Modal is shown (via UiKit)
shown: function (event) {
ga('set', 'page', '/load');
ga('send', 'pageview');
// This happens whenever the Modal is shown/hidden (via UiKit)
toggled: function (event) {
//This is run before uk-open is applied, so the absence means shown
if(!this.$el.classList.contains('uk-open')) {
this.$ga.page('/load');
}
},
loadCharacter: function (event) {
// Max size of 8MB. If we're hitting this limit there's a problem.
Expand All @@ -87,11 +89,13 @@
})
.then(response => {
endLoading();
this.$ga.event('character', 'load', 'success');
//TODO: Don't reload, just close everything and update as appropriate on load finishing
location.reload();
})
.catch(error => {
endLoading();
this.$ga.event('character', 'load', 'failure');
console.log('Error Loading Character');
console.log(error);
if (error.response){
Expand All @@ -100,6 +104,7 @@
});
}).catch(error => {
endLoading();
this.$ga.event('character', 'load', 'badFile');
alert(error.message);
});
}
Expand Down
14 changes: 9 additions & 5 deletions resources/js/components/modals/NewCharacterModal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :id="id" class="uk-flex-top" v-on:toggle="shown" uk-modal>
<div :id="id" class="uk-flex-top" v-on:toggle="toggled" uk-modal>
<div class="uk-modal-dialog uk-modal-body uk-margin-auto-vertical game-style" style="min-width: 80ch">
<button class="uk-modal-close-default" type="button" uk-close></button>
<div class="uk-text-center">
Expand Down Expand Up @@ -38,10 +38,12 @@
'creationPoints': 1000,
}},
methods: {
// This happens whenever the Modal is shown (via UiKit)
shown: function (event) {
ga('set', 'page', '/new');
ga('send', 'pageview');
// This happens whenever the Modal is shown/hidden (via UiKit)
toggled: function (event) {
//This is run before uk-open is applied, so the absence means shown
if(!this.$el.classList.contains('uk-open')) {
this.$ga.page('/new');
}
},
newCharacter: function (event) {
startLoading();
Expand All @@ -50,11 +52,13 @@
})
.then(response => {
endLoading();
this.$ga.event('character', 'new', 'success');
//TODO: Don't reload, just close everything and update as appropriate on load finishing
location.reload();
})
.catch(error => {
endLoading();
this.$ga.event('character', 'new', 'failure');
console.log('Error Creating Character');
console.log(error);
if (error.response){
Expand Down
30 changes: 16 additions & 14 deletions resources/js/components/modals/ValidationCheck.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :id="id" class="uk-flex-top" v-on:toggle="shown" uk-modal>
<div :id="id" class="uk-flex-top" v-on:toggle="toggled" uk-modal>
<div class="uk-modal-dialog uk-modal-body uk-margin-auto-vertical game-style" style="min-width: 80ch">
<button class="uk-modal-close-default" type="button" uk-close></button>
<div class="uk-text-center">
Expand Down Expand Up @@ -45,19 +45,21 @@
}
}},
methods: {
// This happens whenever the Modal is shown (via UiKit)
shown: function (event) {
ga('set', 'page', '/validate');
ga('send', 'pageview');
axios.get(urls.validate)
.then(response => {
this.isValid = response.data.isValid;
this.validators = response.data.validators;
})
.catch(error => {
console.log('Error Validating data');
console.log(error)
});
// This happens whenever the Modal is shown/hidden (via UiKit)
toggled: function (event) {
//This is run before uk-open is applied, so the absence means shown
if(!this.$el.classList.contains('uk-open')) {
this.$ga.page('/validate');
axios.get(urls.validate)
.then(response => {
this.isValid = response.data.isValid;
this.validators = response.data.validators;
})
.catch(error => {
console.log('Error Validating data');
console.log(error)
});
}
}
}
}
Expand Down
54 changes: 0 additions & 54 deletions resources/js/googleAnalytics.js

This file was deleted.

5 changes: 2 additions & 3 deletions resources/views/main.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ function createDataURI(string $file, string $mimeType = null){
{{--<script src="{{mix('js/app.js')}}" type="text/javascript"></script>--}}
{{--<script src="{{mix('js/legacy.js')}}" type="text/javascript"></script>--}}
<script>
var process = {};
process.env = {};
process.env.MIX_GOOGLE_ANALYTICS_ID = "{{config('epcc.googleAnalyticsId')}}";
window.env = {};
window.env.MIX_GOOGLE_ANALYTICS_ID = "{{config('epcc.googleAnalyticsId')}}";
<?php
//Load order is important here
include public_path('js/manifest.js');
Expand Down
1 change: 1 addition & 0 deletions webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mix.setPublicPath('public/')
'vue',
'vue-router',
'vuex',
'vue-analytics',
'uikit'
// 'vegas', //Causes Errors if here!
])
Expand Down

0 comments on commit 8c51fbb

Please sign in to comment.