@skyanalytics/vue2
v1.1.1
Published
SkyAnalytics Vue-2 is an adapter for [SkyAnalytics]
Downloads
84
Readme
SkyAnalytics Vue-2
SkyAnalytics Vue-2 is an adapter for SkyAnalytics that allows you to track your website's traffic and user behavior.
Installation
npm install @skyanalytics/vue2
Usage
import Vue from 'vue'
import SkyAnalytics from '@skyanalytics/vue2'
Vue.use(SkyAnalytics, {
key: 'source_key',
host: 'http://localhost:3000',
enabled: true // default is true
})
Directives
<button v-sk-analytics="{ event: 'click', data: { key: 'value' } }">Click me</button>
Methods
this.$skyAnalytics.event('event', { key: 'value' })
Composable
import { useAnalytics } from '@skyanalytics/vue2'
useAnalytics.event('event', { key: 'value' })
useAnalytics.navigate('page', { key: 'value' })
useAnalytics.metadata({ key: 'value' })
Vue-Router
import Vue from 'vue'
import VueRouter from 'vue-router'
import SkyAnalytics, { useAnalytics } from '@skyanalytics/vue2'
Vue.use(VueRouter)
Vue.use(SkyAnalytics, {
key: 'source_key',
host: 'http://localhost:3000',
enabled: true // default is true
})
const router = new VueRouter({
routes: []
})
router.beforeEach((to, from, next) => {
Vue.prototype.$skyAnalytics.navigation({ name: to.name })
// or
const analytics = useAnalytics()
analytics.navigate(to.name)
next()
})
[!WARNING]
Use with caution, the methods$skyAnalytics
make sure that the instance is initialized and the plugin is enabled. Otherwise, it will throw an error.