All Projects → moritzsternemann → vue-plausible

moritzsternemann / vue-plausible

Licence: MIT license
Plausible Analytics Vue.js Plugin and NuxtJS Module

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to vue-plausible

nuxt-prune-html
🔌⚡ Nuxt module to prune html before sending it to the browser (it removes elements matching CSS selector(s)), useful for boosting performance showing a different HTML for bots/audits by removing all the scripts with dynamic rendering
Stars: ✭ 69 (-35.51%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
date-fns-module
Modern JavaScript date utility library - date-fns for Nuxt.js
Stars: ✭ 68 (-36.45%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-mail
Adds email sending capability to a Nuxt.js app. Adds a server route, an injected variable, and uses nodemailer to send emails.
Stars: ✭ 62 (-42.06%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-stripejs
💳 NuxtJS module for Stripe.js which loads only when required and w/ retry mechanism
Stars: ✭ 17 (-84.11%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
global-components
Module to register global components for Nuxt.js
Stars: ✭ 57 (-46.73%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-jsonld
A Nuxt.js module to manage JSON-LD in Vue component.
Stars: ✭ 198 (+85.05%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
yamlful
YAML-based HTTP client code generation
Stars: ✭ 77 (-28.04%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-ghost
Easy Ghost content API integration with Nuxt.js.
Stars: ✭ 27 (-74.77%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-feature-toggle
The nuxt feature toggle module
Stars: ✭ 78 (-27.1%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-babel
Use normal .babelrc file with your Nuxt app
Stars: ✭ 32 (-70.09%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
supabase
An easy way to integrate Supabase with NuxtJS
Stars: ✭ 39 (-63.55%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-gsap-module
GSAP module for Nuxt.js
Stars: ✭ 183 (+71.03%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-humans-txt
🧑🏻👩🏻 "We are people, not machines" - An initiative to know the creators of a website. Contains the information about humans to the web building - A Nuxt Module to statically integrate and generate a humans.txt author file - Based on the HumansTxt Project.
Stars: ✭ 27 (-74.77%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-stencil
Easy Stencil.js component library integration with Nuxt.js.
Stars: ✭ 16 (-85.05%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-modules
AX2's Nuxt modules
Stars: ✭ 30 (-71.96%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-winston-log
Nuxt module for logging SSR errors using winston
Stars: ✭ 41 (-61.68%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
applicationinsights-module
Application Insights module for NuxtJS
Stars: ✭ 14 (-86.92%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-speedkit
nuxt-speedkit will help you to improve the lighthouse performance score (100/100) of your website.
Stars: ✭ 401 (+274.77%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
separate-env-module
Tear your variables apart!
Stars: ✭ 53 (-50.47%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
k-domains
A simple module to manage multiple subdomains with just one project
Stars: ✭ 41 (-61.68%)
Mutual labels:  nuxt, nuxtjs, nuxt-module

Plausible Analytics for Vue.js and NuxtJS

NPM

Vue.js plugin and NuxtJS module for Plausible Analytics

Installation

Using npm:

npm install vue-plausible

Using yarn:

yarn add vue-plausible

Vue.js Plugin

import Vue from 'vue'
import { VuePlausible } from 'vue-plausible'

Vue.use(VuePlausible, {
  // see configuration section
})

To enable automatic page view tracking for SPAs, call the enableAutoPageviews() method. To enable automatic outbound link tracking, call the enableAutoOutboundTracking() method.

NuxtJS Module

// nuxt.config.js

// optional when using nuxt.config.ts
/// <reference types="vue-plausible" />

export default {
  modules: [
    'vue-plausible'
  ]
}

Module Options

Add a plausible section to nuxt.config.js to set the module options:

// nuxt.config.js

export default {
  plausible: {
    // see configuration section
  }
}

Runtime Config

To use dynamic environment variables in production, use publicRuntimeConfig. Otherwise, the configuration options passed in nuxt.config.js will be read once and bundled during the build only. See the configuration section for all available options.

// nuxt.config.js

export default {
  buildModules: [
    'vue-plausible'
  ],
  plausible: { // Use as fallback if no runtime config is available at runtime
    domain: process.env.PLAUSIBLE_DOMAIN
  },
  publicRuntimeConfig: {
    plausible: {
      domain: process.env.PLAUSIBLE_DOMAIN,
      apiHost: process.env.PLAUSIBLE_API_HOST
    }
  }
}

Usage

vue-plausible is based on the official plausible-tracker package.

Configuration

Configuration options are inherited from plausible-tracker:

Option Type Description Default
domain string Your site's domain name, as declared by you in Plausible's settings. location.hostname
hashMode boolean Enables tracking based on URL hash changes. false
trackLocalhost boolean Enables tracking on localhost. false
apiHost string Plausible's API host to use. Change this if you are self-hosting. https://plausible.io
enableAutoPageviews boolean Enables automatic pageview tracking in SPAs. Learn more true
enableAutoOutboundTracking boolean Enables automatic outbound link click tracking. Learn more false

Integration

The plausible-tracker package provides various methods to track specific events, for example trackPageview() and trackEvent(). You can find all the available methods and options in the plausible-tracker documentation. The Plausible instance is exposed to your Vue.js or NuxtJS app in the following ways:

  • Vue.$plausible (Vue.js only)
  • this.$plausible inside Vue components
  • context.app.$plausible inside asyncData, fetch, plugins, middleware, nuxtServerInit (NuxtJS only)
  • this.$plausible inside Vuex stores (NuxtJS only)

Proxying

To use proxying as described in the Plausible 'Using a proxy' documentation, you need to adjust the apiHost configuration option accordingly. Using vue-plausible only requires to proxy the /api/event endpoint since the frontend code is already bundled from plausible-tracker.

Please note that event endpoint path always ends with /api/event. See the following example:

plausible: {
  apiHost: 'https://<yourdomain.com>/stats' // Reports events to https://<yourdomain.com>/stats/api/event
}

Opt out

To exclude yourself from the analytics, plausible-tracker offers an opt-out mechanism that can be activated by setting the localStorage.plausible_ignore value to true.

More information can be found in the Plausible documentation.

Author

I'm Moritz Sternemann, a computer-science student at Technical University of Munich.

License

This project is available under the MIT license. See the LICENSE file for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].