WIP
This commit is contained in:
30
resources/js/plugins/amplitude.js
vendored
30
resources/js/plugins/amplitude.js
vendored
@@ -1,12 +1,11 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
// Log event function used to log event. Can be used when not using the directive.
|
||||
Vue.prototype.$logEvent = function (eventName, eventData) {
|
||||
const logEvent = function (eventName, eventData) {
|
||||
if (!window.amplitude) return
|
||||
if (eventData && typeof eventData !== 'object') {
|
||||
throw new Error('Amplitude event value must be an object.')
|
||||
}
|
||||
|
||||
console.log('in', window.config.production)
|
||||
if (!window.config.production) {
|
||||
console.log('[DEBUG] Amplitude logged event:', eventName, eventData)
|
||||
} else {
|
||||
@@ -22,16 +21,21 @@ function hookLogEvent (binding) {
|
||||
}
|
||||
const eventName = modifiers[0]
|
||||
|
||||
Vue.prototype.$logEvent(eventName, binding.value)
|
||||
logEvent(eventName, binding.value)
|
||||
}
|
||||
|
||||
// Register directive to log event
|
||||
const registeredListeners = {}
|
||||
Vue.directive('track', {
|
||||
beforeMount (el, binding, vnode) {
|
||||
registeredListeners[el] = () => {
|
||||
hookLogEvent(binding)
|
||||
// Used in vue-plugins.js
|
||||
export function registerLogEventOnApp (app) {
|
||||
app.config.globalProperties.$logEvent = logEvent
|
||||
|
||||
// Register directive to log event
|
||||
const registeredListeners = {}
|
||||
app.directive('track', {
|
||||
beforeMount (el, binding, vnode) {
|
||||
registeredListeners[el] = () => {
|
||||
hookLogEvent(binding)
|
||||
}
|
||||
el.addEventListener('click', registeredListeners[el])
|
||||
}
|
||||
el.addEventListener('click', registeredListeners[el])
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
16
resources/js/plugins/index.js
vendored
16
resources/js/plugins/index.js
vendored
@@ -1,5 +1,17 @@
|
||||
import './axios'
|
||||
import './vue-plugins'
|
||||
import './amplitude'
|
||||
import { registerLogEventOnApp } from './amplitude'
|
||||
import './vapor'
|
||||
import './sentry'
|
||||
|
||||
import Notifications from 'vue3-vt-notifications'
|
||||
import { createMetaManager } from 'vue-meta'
|
||||
|
||||
function registerPlugin (app) {
|
||||
const metaManager = createMetaManager()
|
||||
|
||||
app.use(Notifications)
|
||||
app.use(metaManager)
|
||||
registerLogEventOnApp(app)
|
||||
return app
|
||||
}
|
||||
export default registerPlugin
|
||||
|
||||
9
resources/js/plugins/vue-plugins.js
vendored
9
resources/js/plugins/vue-plugins.js
vendored
@@ -1,9 +0,0 @@
|
||||
import Notifications from 'vue3-vt-notifications'
|
||||
import Meta from 'vue-meta'
|
||||
|
||||
function registerPlugin (app) {
|
||||
app.use(Notifications)
|
||||
app.use(Meta)
|
||||
return app
|
||||
}
|
||||
export default registerPlugin
|
||||
Reference in New Issue
Block a user