npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@plainapps/analytics-vue

v1.0.2

Published

Vue composables and plugin for Plain Web Analytics - privacy-focused, cookie-free analytics

Readme

@plainapps/analytics-vue

Vue composables and plugin for Plain Web Analytics - privacy-focused, cookie-free web analytics.

Features

  • 🎯 Vue 3 Composition API - Native Vue 3 composables
  • 🔌 Plugin support - Global installation with Vue plugin
  • 📊 Automatic pageviews - Track pageviews automatically or manually
  • 🎯 Event tracking - Track custom events and goal conversions
  • 🛤️ Vue Router integration - Built-in support for route change tracking
  • 🌐 Nuxt 3 compatible - Works seamlessly with Nuxt 3
  • Lightweight - Tree-shakeable, zero dependencies beyond core
  • 📝 TypeScript - Full TypeScript support with type definitions

Installation

npm install @plainapps/analytics-vue
# or
yarn add @plainapps/analytics-vue
# or
pnpm add @plainapps/analytics-vue

Quick Start

Option 1: Plugin (Recommended)

Install the plugin in your Vue app:

// main.ts
import { createApp } from 'vue';
import { createPlainAnalytics } from '@plainapps/analytics-vue';
import App from './App.vue';

const app = createApp(App);

app.use(createPlainAnalytics({
  siteId: 'pwa_site_abc123',  // Your site key
}));

app.mount('#app');

Then use composables in your components:

<script setup lang="ts">
import { usePlainAnalytics, useTrackEvent } from '@plainapps/analytics-vue';

// Access full context
const { trackEvent, trackGoal, isInitialized } = usePlainAnalytics();

// Or use specialized composables
const { track, isReady } = useTrackEvent();

function handleSignup() {
  track('signup_click', { source: 'homepage' });
}
</script>

<template>
  <button @click="handleSignup" :disabled="!isReady">
    Sign Up
  </button>
</template>

Option 2: Standalone Composable

Use without the plugin:

<script setup lang="ts">
import { usePlainAnalytics } from '@plainapps/analytics-vue';

const { trackEvent, isInitialized } = usePlainAnalytics({
  siteId: 'pwa_site_abc123',
});

function handleClick() {
  trackEvent('button_click', { button: 'cta' });
}
</script>

Vue Router Integration

Track pageviews on route changes:

<!-- App.vue or a layout component -->
<script setup lang="ts">
import { usePageViews } from '@plainapps/analytics-vue';
import { useRoute } from 'vue-router';

const route = useRoute();

// Track pageviews when route changes
usePageViews(() => route.fullPath);
</script>

Nuxt 3 Integration

Create a client-side plugin:

// plugins/analytics.client.ts
import { createPlainAnalytics } from '@plainapps/analytics-vue';

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(createPlainAnalytics({
    siteId: 'pwa_site_abc123',
  }));
});

Track route changes in your app:

<!-- app.vue or layouts/default.vue -->
<script setup lang="ts">
import { usePageViews } from '@plainapps/analytics-vue';

const route = useRoute();
usePageViews(() => route.fullPath);
</script>

API Reference

Plugin

createPlainAnalytics(options)

Creates a Vue plugin for Plain Web Analytics.

interface PlainAnalyticsPluginOptions {
  siteId: string;           // Required: Your site key
  apiEndpoint?: string;     // Custom API endpoint
  autoPageview?: boolean;   // Auto-track initial pageview (default: true)
  hashMode?: boolean;       // Track hash changes (default: false)
  debug?: boolean;          // Enable debug logging (default: false)
}

Composables

usePlainAnalytics()

Access the analytics context from the plugin.

const {
  isInitialized,    // Ref<boolean> - Whether analytics is ready
  isEnabled,        // Ref<boolean> - Whether tracking is enabled
  config,           // Ref<AnalyticsConfig | null> - Current configuration
  trackPageview,    // (url?: string) => void - Track a pageview
  trackEvent,       // (name: string, properties?: EventProperties) => void
  trackGoal,        // (goalId: string, options?: GoalOptions) => void
  setEnabled,       // (enabled: boolean) => void - Enable/disable tracking
} = usePlainAnalytics();

usePlainAnalytics(options)

Create a standalone analytics instance (no plugin required).

const { trackEvent, isInitialized } = usePlainAnalytics({
  siteId: 'pwa_site_abc123',
});

usePageViews(source, options?)

Track pageviews when a reactive source changes.

const route = useRoute();
usePageViews(() => route.fullPath, {
  trackOnMount: false,  // Track initial pageview (default: false)
});

useTrackEvent()

Get a track function for custom events.

const { track, isReady } = useTrackEvent();

track('button_click', { button: 'signup' });

useTrackOnMount(eventName, properties?)

Track an event when the component mounts.

// Track product views
useTrackOnMount('product_view', { product_id: 'abc123' });

useTrackGoal()

Get a function for tracking goal conversions.

const trackGoal = useTrackGoal();

// Track a purchase with revenue (in cents)
trackGoal('purchase', { revenue: 9900 });

Examples

Track a Button Click

<script setup lang="ts">
import { useTrackEvent } from '@plainapps/analytics-vue';

const { track } = useTrackEvent();

function handleAddToCart(productId: string) {
  track('add_to_cart', { product_id: productId });
}
</script>

<template>
  <button @click="handleAddToCart('prod-123')">
    Add to Cart
  </button>
</template>

Track a Form Submission

<script setup lang="ts">
import { usePlainAnalytics } from '@plainapps/analytics-vue';

const { trackEvent, trackGoal } = usePlainAnalytics();

async function handleSubmit() {
  const success = await submitForm();
  
  if (success) {
    trackEvent('form_submit', { form: 'contact' });
    trackGoal('lead_capture');
  }
}
</script>

Track E-commerce Purchase

<script setup lang="ts">
import { useTrackGoal } from '@plainapps/analytics-vue';

const trackGoal = useTrackGoal();

async function handleCheckout(cart: Cart) {
  const order = await processPayment(cart);
  
  // Track purchase with revenue in cents
  trackGoal('purchase', {
    revenue: order.total * 100,
    properties: {
      order_id: order.id,
      items: cart.items.length,
    },
  });
}
</script>

Conditional Tracking

<script setup lang="ts">
import { usePlainAnalytics } from '@plainapps/analytics-vue';

const { setEnabled, isEnabled } = usePlainAnalytics();

function handleConsentChange(consent: boolean) {
  setEnabled(consent);
}
</script>

<template>
  <div>
    <label>
      <input type="checkbox" :checked="isEnabled" @change="handleConsentChange($event.target.checked)" />
      Allow analytics
    </label>
  </div>
</template>

Global Properties Access

The plugin also exposes analytics via $analytics on the app instance:

<script>
export default {
  methods: {
    trackWithOptions() {
      this.$analytics.trackEvent('legacy_event', { source: 'options-api' });
    }
  }
}
</script>

Vite Configuration

No special configuration needed. Just install and use:

// vite.config.ts
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
  plugins: [vue()],
});

TypeScript

Full TypeScript support is included. Import types as needed:

import type {
  PlainAnalyticsContext,
  PlainAnalyticsPluginOptions,
  EventProperties,
  Goal,
} from '@plainapps/analytics-vue';

License

MIT