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

nuxt-fathom

v0.0.2

Published

Fathom analytics Nuxt module

Downloads

5,358

Readme

Nuxt Fathom module

Nuxt Fathom

npm version npm downloads License Nuxt

Nuxt module to integrate Fathom Analytics.

Features

Setup

# pnpm
pnpm add -D nuxt-fathom

# npm
npm i -D nuxt-fathom

# yarn
yarn add -D nuxt-fathom

Basic Usage

Add nuxt-fathom to the modules section of your Nuxt configuration and provide your Fathom site ID.

// `nuxt.config.ts`
export default defineNuxtConfig({
  modules: ["nuxt-fathom"],

  fathom: {
    siteId: "FATHOM_SITE_ID",
  },
});

Tip: you can also use an .env file instead of a fathom key.

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

Configuration

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

export default defineNuxtConfig({
  modules: ['nuxt-fathom'],

  fathom: {
    // The Fathom Analytics site ID to use for tracking
    siteId: string,
    // Additional configuration
    config: {
      manual?: boolean
      auto?: boolean
      honorDNT?: boolean
      canonical?: boolean
      spa?: 'auto' | 'history' | 'hash'
    }
  }
})

Runtime Config

Instead of hard-coding your Fathom Analytics site ID in your Nuxt configuration, you can set your desired option in your project's .env file, leveraging automatically replaced public runtime config values by matching environment variables at runtime.

# Overwrites the `fathom.siteId` module option
NUXT_PUBLIC_FATHOM_SITE_ID=YOUR_SITE_ID

With this setup, you can omit the fathom key in your Nuxt configuration if you only intend to set the site ID.

Module Options

| Property | Type | Description | Default | | ----------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ----------- | | manual | boolean | If you want to manually control page view tracking. | false | | auto | boolean | When false, skips automatically tracking page views on script load. | true | | honorDNT | boolean | When true, honors the DNT header in the visitor's browser. | false | | canonical | boolean | When false, ignores the canonical tag if present. | true | | spa | 'auto', 'history', 'hash' | Accepts one of the following values: auto, history, or hash (see advanced docs). | undefined |

Composables

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

useFathom

The SSR-safe useFathom composable provides access to:

  • The blockTrackingForMe method.
  • The enableTrackingForMe method.
  • The isTrackingEnabled method.
  • The setSite method.
  • The trackEvent method.
  • The trackPageview method.

It can be used as follows:

// Each method is destructurable from the composable
const {
  blockTrackingForMe,
  enableTrackingForMe,
  isTrackingEnabled,
  setSite,
  trackEvent, // The method most likely to be used.
  trackPageview,
} = useFathom();

[!NOTE] Since the fathom instance is available in the client only, any useFathom method calls executed on the server will have no effect.

Development

# Install dependencies
pnpm install

# Generate type stubs
pnpm run dev:prepare

# Develop with the playground
pnpm run dev

# Build the playground
pnpm run dev:build

# Run ESLint
pnpm run lint

# Run Vitest
pnpm run test
pnpm run test:watch

# Release new version
pnpm run release

Credits