Socket
Socket
Sign inDemoInstall

@nuxtjs/plausible

Package Overview
Dependencies
Maintainers
7
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuxtjs/plausible

Nuxt 3 module to natively integrate Plausible analytics


Version published
Maintainers
7
Created
Source

Nuxt Plausible module

Nuxt Plausible

npm version

Nuxt 3 module to integrate the Plausible tracker.

Features

Setup

# pnpm
pnpm add -D @nuxtjs/plausible

# npm
npm i -D @nuxtjs/plausible

Basic Usage

Add @nuxtjs/plausible to the modules section of your Nuxt configuration:

// `nuxt.config.ts`
export default defineNuxtConfig({
  modules: ['@nuxtjs/plausible']
})

Done! Plausible will now run in your application's client.

ℹ️ By default, @nuxtjs/plausible will use window.location.hostname for the Plausible domain configuration key, which will suit most users.

Configuration

All supported module options can be configured using the plausible key in your Nuxt configuration:

export default defineNuxtConfig({
  modules: ['@nuxtjs/plausible'],

  plausible: {
    domain: 'example.com'
  }
})

Runtime Config

Alternatively, leveraging automatically replaced public runtime config values by matching environment variables at runtime, set your desired option in your project's .env file:

# Sets the `plausible.domain` option to `example.com`
NUXT_PUBLIC_PLAUSIBLE_DOMAIN=example.com

With this setup, you can omit the plausible key in your Nuxt configuration.

Module Options

OptionTypeDefaultDescription
hashModebooleanfalseWhether page views shall be tracked when the URL hash changes. Enable this if your Nuxt app has the hashMode router option enabled.
trackLocalhostbooleanWhether events shall be tracked when running the site locally.false
domainstring'window.location.hostname'The domain to bind tracking event to.
apiHoststringThe API host where the events will be sent to.https://plausible.io
autoPageviewsbooleantrueTrack the current page and all further pages automatically. Disable this if you want to manually manage pageview tracking.
autoOutboundTrackingbooleanfalseTrack all outbound link clicks automatically. If enabled, a MutationObserver automagically detects link nodes throughout the application and binds click events to them.

Composables

As with other composables in the Nuxt 3 ecosystem, they are auto-imported and can be used in your application's components.

ℹ️ Since the Plausible instance is available in the client only, executing the composables on the server will have no effect.

useTrackEvent

Track a custom event. Track your defined goals by passing the goal's name as the argument eventName.

Type Declarations

function useTrackEvent(
  eventName: string,
  options?: EventOptions,
  eventData?: PlausibleOptions
): void

Example

// Tracks the `signup` goal
useTrackEvent('signup')

// Tracks the `Download` goal passing a `method` property.
useTrackEvent('Download', { props: { method: 'HTTP' } })

useTrackPageview

Manually track a page view.

Pass optional event data to be sent with the eventData argument. Defaults to the current page's data merged with the default options provided during the Plausible initialization.

Type Declarations

function useTrackPageview(
  eventData?: PlausibleOptions,
  options?: EventOptions
): void

💻 Development

  1. Clone this repository
  2. Enable Corepack using corepack enable
  3. Install dependencies using pnpm install
  4. Run pnpm run dev:prepare
  5. Start development server using pnpm run dev

Similar Packages

Credits

License

MIT License © 2022-2023 Johann Schopplich

Keywords

FAQs

Package last updated on 08 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc