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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nuxtjs/plausible

v1.0.0

Published

Natively integrates Plausible Analytics into Nuxt

Downloads

18,663

Readme

Nuxt Plausible module

Nuxt Plausible

npm version

Native integration of Plausible Analytics for Nuxt.

Features

  • 🌻 No configuration necessary
  • 📯 Track events and page views manually with composables
  • 📂 .env file support
  • 🧺 Sensible default options
  • 🦾 SSR-ready

Setup

npx nuxi@latest module add 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.

[!TIP] By default, @nuxtjs/plausible will use window.location.hostname for the Plausible domain configuration key, which should suit most use-cases. If you need to customize the domain, you can do so in the module options.

Configuration

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

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

  plausible: {
    // Prevent tracking on localhost
    ignoredHostnames: ['localhost'],
  },
})

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

| Option | Type | Default | Description | | ---------------------- | ---------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | enabled | boolean | true | Whether the tracker shall be enabled. | | hashMode | boolean | false | Whether page views shall be tracked when the URL hash changes. Enable this if your Nuxt app uses the hashMode router option instead of the default history mode. | | domain | string | 'window.location.hostname' | The domain to bind tracking event to. | | ignoredHostnames | string[] | ['localhost'] | Hostnames to ignore when tracking events. | | apiHost | string | https://plausible.io | The API host where the events will be sent to. | | autoPageviews | boolean | true | Track the current page and all further pages automatically. Disable this if you want to manually manage pageview tracking. | | autoOutboundTracking | boolean | false | Track all outbound link clicks automatically. If enabled, a MutationObserver automagically detects link nodes throughout the application and binds click events to them. | | logIgnoredEvents | boolean | false | Log events to the console if they are ignored. |

Composables

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

[!NOTE] 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

Credits

License

MIT License © 2022-PRESENT Johann Schopplich