Vue SDK
Vue 3 composables and plugin for Entrolytics
Vue SDK
The @entro314labs/entro-vue package provides Vue 3 composables and a plugin for seamless analytics integration with the Composition API and Options API.
Installation
pnpm add @entro314labs/entro-vuenpm install @entro314labs/entro-vueyarn add @entro314labs/entro-vuebun add @entro314labs/entro-vueQuick Start
Install the Plugin
Add the Entrolytics plugin to your Vue app:
import { createApp } from 'vue'
import { createEntrolytics } from '@entro314labs/entro-vue'
import App from './App.vue'
const app = createApp(App)
app.use(createEntrolytics({
websiteId: import.meta.env.VITE_ENTROLYTICS_WEBSITE_ID,
host: import.meta.env.VITE_ENTROLYTICS_HOST,
autoTrack: true,
}))
app.mount('#app')Add Environment Variables
Create a .env file in your project root:
VITE_ENTROLYTICS_WEBSITE_ID=your-website-id
VITE_ENTROLYTICS_HOST=https://cloud.entrolytics.clickTrack Events
Use the useEntrolytics composable in your components:
<script setup lang="ts">
import { useEntrolytics } from '@entro314labs/entro-vue'
const { track } = useEntrolytics()
function handleSignup() {
track('signup', {
plan: 'pro',
source: 'landing-page'
})
}
</script>
<template>
<button @click="handleSignup">
Sign Up for Pro
</button>
</template>Configuration
Plugin Options
interface EntrolyticsOptions {
/** Website ID (required) */
websiteId: string
/** Link ID for link tracking */
linkId?: string
/** Pixel ID for conversion tracking */
pixelId?: string
/** Custom analytics host URL */
host?: string
/** Auto-track page views (default: true) */
autoTrack?: boolean
/** Tag for A/B testing */
tag?: string
/** Restrict to specific domains */
domains?: string[]
/** Strip query params from URLs */
excludeSearch?: boolean
/** Strip hash fragments from URLs */
excludeHash?: boolean
/** Honor Do Not Track */
respectDnt?: boolean
/** Disable on localhost */
ignoreLocalhost?: boolean
}Example Configuration
app.use(createEntrolytics({
websiteId: 'abc-123-def',
host: 'https://analytics.company.com',
autoTrack: true,
domains: ['example.com', 'app.example.com'],
excludeSearch: true,
ignoreLocalhost: true,
}))Composables
useEntrolytics
Main composable for accessing all Entrolytics functionality:
<script setup lang="ts">
import { useEntrolytics } from '@entro314labs/entro-vue'
const {
track, // Track custom events
identify, // Identify users
isLoaded, // Check if script loaded
config, // Access configuration
} = useEntrolytics()
// Track event
function handleClick() {
track('button-click', { location: 'hero' })
}
// Identify user
function handleLogin(user) {
identify(user.id, {
email: user.email,
plan: user.subscription
})
}
</script>useTrackEvent
Specialized composable for event tracking:
<script setup lang="ts">
import { useTrackEvent } from '@entro314labs/entro-vue'
const { track } = useTrackEvent()
function handlePurchase(product) {
track('purchase', {
revenue: product.price,
currency: 'USD',
productId: product.id,
category: product.category
})
}
</script>
<template>
<button @click="handlePurchase(product)">
Buy Now - ${{ product.price }}
</button>
</template>useTrackPageView
Track page views manually or with vue-router:
<script setup lang="ts">
import { useRoute } from 'vue-router'
import { useTrackPageView } from '@entro314labs/entro-vue'
const route = useRoute()
// Auto-track route changes
useTrackPageView(() => route.fullPath)
</script>useIdentify
Identify and track logged-in users:
<script setup lang="ts">
import { watch } from 'vue'
import { useIdentify } from '@entro314labs/entro-vue'
import { useAuthStore } from '@/stores/auth'
const { identify } = useIdentify()
const authStore = useAuthStore()
// Identify user when they log in
watch(() => authStore.user, (user) => {
if (user) {
identify(user.id, {
email: user.email,
name: user.name,
plan: user.subscription,
company: user.company
})
}
})
</script>Vue Router Integration
Automatic Page Tracking
Track page views automatically with Vue Router:
import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({
history: createWebHistory(),
routes: [/* your routes */]
})
// Auto-track page views on route change
router.afterEach((to) => {
// The plugin's autoTrack option handles this automatically
// Or manually track with custom data:
window.$entrolytics?.track('pageview', {
path: to.path,
name: to.name,
params: to.params
})
})
export default routerLayout Component
Create a layout component that tracks page views:
<script setup lang="ts">
import { useRoute } from 'vue-router'
import { useTrackPageView } from '@entro314labs/entro-vue'
const route = useRoute()
// Automatically track page views when route changes
useTrackPageView(() => route.fullPath)
</script>
<template>
<div class="app-layout">
<header>
<Navigation />
</header>
<main>
<router-view />
</main>
<footer>
<Footer />
</footer>
</div>
</template>Options API Support
The plugin also works with Options API:
<script>
export default {
name: 'LegacyComponent',
methods: {
trackButtonClick() {
// Access via global property
this.$entrolytics.track('button-click', {
component: 'legacy',
action: 'click'
})
},
handleLogin(user) {
this.$entrolytics.identify(user.id, {
email: user.email,
role: user.role
})
}
},
mounted() {
// Track component mount
this.$entrolytics.track('component-mounted', {
name: this.$options.name
})
}
}
</script>
<template>
<button @click="trackButtonClick">
Click Me
</button>
</template>Advanced Usage
Framework Examples
Nuxt 3
Create a Nuxt plugin:
import { createEntrolytics } from '@entro314labs/entro-vue'
export default defineNuxtPlugin((nuxtApp) => {
const config = useRuntimeConfig()
nuxtApp.vueApp.use(createEntrolytics({
websiteId: config.public.entrolyticsWebsiteId,
host: config.public.entrolyticsHost,
autoTrack: true,
}))
})Then add to nuxt.config.ts:
export default defineNuxtConfig({
runtimeConfig: {
public: {
entrolyticsWebsiteId: process.env.NUXT_PUBLIC_ENTROLYTICS_WEBSITE_ID,
entrolyticsHost: process.env.NUXT_PUBLIC_ENTROLYTICS_HOST,
}
}
})Vite
Standard Vite + Vue 3 setup:
import { createApp } from 'vue'
import { createEntrolytics } from '@entro314labs/entro-vue'
import App from './App.vue'
const app = createApp(App)
app.use(createEntrolytics({
websiteId: import.meta.env.VITE_ENTROLYTICS_WEBSITE_ID,
host: import.meta.env.VITE_ENTROLYTICS_HOST,
}))
app.mount('#app')Quasar
In your Quasar boot file:
import { boot } from 'quasar/wrappers'
import { createEntrolytics } from '@entro314labs/entro-vue'
export default boot(({ app }) => {
app.use(createEntrolytics({
websiteId: process.env.ENTROLYTICS_WEBSITE_ID,
autoTrack: true,
}))
})TypeScript Support
Full TypeScript support with exported types:
import type {
EntrolyticsOptions,
EntrolyticsInstance,
TrackEventData,
IdentifyTraits,
} from '@entro314labs/entro-vue'
// Type-safe configuration
const options: EntrolyticsOptions = {
websiteId: 'abc-123',
autoTrack: true,
}
// Type-safe event data
const eventData: TrackEventData = {
revenue: 99.99,
currency: 'USD',
productId: 'pro-plan'
}
// Use in component
const { track, identify } = useEntrolytics()
track('purchase', eventData)
identify('user-123', { email: 'user@example.com' })Peer Dependencies
vue:>=3.3.0vue-router:>=4.0.0(optional, for router integration)
Features
- ✅ Vue 3 Composition API support
- ✅ Options API support
- ✅ Vue Router integration
- ✅ Nuxt 3 compatible
- ✅ Auto-track page views
- ✅ TypeScript-first with full type safety
- ✅ SSR support (Nuxt)
- ✅ Tree-shakeable
- ✅ Zero dependencies (besides Vue)