The Vue Umami Plugin integrates Umami analytics by loading the library and injecting it into your application's DOM, allowing you to easily track page views and events.
This library was created to reduce duplication and streamline the integration of Umami analytics into a number of my personal Vue projects. Though, I decided to share it with the community in the hope that others may find it useful for similar purposes, either as-is, or as a starting point.
Given its focused nature, the plugin has limitations and may lack functionality available through the official Umami library API.
- Automatic Page Tracking: Automatically track page views through your Vue router.
- Event Tracking: Easily track custom events with minimal configuration.
- Lazy Loading: The Umami script is loaded only when the document is ready, ensuring minimal impact on performance.
- Queue System: Events are queued until the Umami script is loaded, ensuring no events are lost.
- Vue 3.x
- Vue Router (optional, for automatic page tracking)
To install and use this plugin, you can include the library via npm:
npm install @jaseeey/vue-umami-plugin
To use the Vue Umami Plugin in your project, import it and use it within your Vue application setup:
import { createApp } from 'vue';
import { VueUmamiPlugin } from '@jaseeey/vue-umami-plugin';
import App from './App.vue';
import router from './router';
const app = createApp(App);
app.use(VueUmamiPlugin, {
websiteID: 'YOUR_UMAMI_WEBSITE_ID',
scriptSrc: 'https://us.umami.is/script.js', // Optional
router,
});
app.use(router).mount('#app');
To track custom events:
import { trackUmamiEvent } from 'vue-umami-plugin';
trackUmamiEvent('button-click', { buttonName: 'subscribe' });
import { identifyUmamiSession } from 'vue-umami-plugin';
identifyUmamiSession({
userId: 'alice',
email: 'alice@example.com',
name: 'Alice Smith',
});
Initialises the Umami tracking plugin with specified options.
- Parameters
options
(Object):websiteID
(String): The Umami website ID required for tracking.scriptSrc
(String, optional): Custom URL for the Umami script source, default:https://us.umami.is/script.js
router
(Router, optional): The Vue Router instance for automatic page tracking.
Sends a custom tracking event to Umami.
- Parameters
event
(String): The name of the event to track.eventParams
(Object, optional): Additional parameters for the event; typically includes details like page URL or user actions.
Identifies a user session with Umami.
- Parameters
sessionData
(Object): The session data to identify.
You can contribute to this project by submitting a pull request or reporting issues in the issues section of this repository.
This project is licensed under the MIT License, see the LICENSE file for details.