This commit is contained in:
Julien Nahum
2023-10-19 10:46:04 +02:00
parent 199a0190ad
commit be6bc867fe
16 changed files with 394 additions and 262 deletions

View File

@@ -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])
}
})
})
}

View File

@@ -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

View File

@@ -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