This package is a Vue plugin for integrating Segment's `analytics.js` into Vue 2 applications. It provides a `Vue.use()` interface to initialize Segment with a write key (`id`) and can integrate with Vue Router for automatic page tracking. The current stable version is 0.5.4, with the last update in June 2022, indicating an infrequent release cadence focused on maintenance rather than active feature development. Its primary differentiator is its direct plugin integration for Vue 2, making Segment methods available globally via `this.$segment`. However, for modern Vue 3 applications, the official Segment recommendation is `@segment/analytics-vue`, making this package a legacy solution for existing Vue 2 projects.
npm install vue-segment-analyticsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to install and initialize `vue-segment-analytics` with a Vue 2 application, including optional router integration for automatic page tracking and a basic example of manually tracking an event.
For Vue 3 projects, use the official `@segment/analytics-vue` package provided by Segment. For existing Vue 2 projects, ensure your Vue version matches the `^2.0.0` requirement.
For new projects or if migrating to Vue 3, consider using `@segment/analytics-vue`. For ongoing Vue 2 projects, be aware that active feature development for this package is minimal, focusing on maintenance.
Assess the stability and feature set required for your project. If you need advanced features or rapid updates, you might need to contribute or consider alternative integration methods.
Ensure `Vue.use(VueSegmentAnalytics, { id: 'YOUR_SEGMENT_WRITE_KEY' })` is called before instantiating your Vue app. Verify that the component attempting to access `$segment` is part of the Vue instance tree.Double-check your `id` configuration in `Vue.use()`. Ensure it matches your Segment project's Write Key. Use the browser's network tab or Segment's debugger to inspect network requests. Temporarily disable ad blockers during development.
Make sure you have `import Vue from 'vue'` at the top of your main JavaScript file and that you are using Vue 2. If using CommonJS, ensure Vue is properly `require`d and exposed.