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

@fresh.codes/astro-pirsch-proxy

v1.0.2

Published

An Astro integration that exposes a Pirsch analytics proxy.

Readme

@fresh.codes/astro-pirsch-proxy

An Astro integration that proxies Pirsch Analytics requests through your server.

Requires an adapter for server rendering such as @astro/node.

Installation

npm install @fresh.codes/astro-pirsch-proxy

Usage

Add the integration to your astro.config.mjs:

import { defineConfig } from 'astro/config'
import { loadEnv } from 'vite'
import { pirschProxy } from '@fresh.codes/astro-pirsch-proxy'

const { PIRSCH_ACCESS_TOKEN } = loadEnv(process.env.NODE_ENV, process.cwd(), '')

export default defineConfig({
  integrations: [
    pirschProxy({
      clients: [
        {
          secret: PIRSCH_ACCESS_TOKEN,
        },
      ],
    }),
  ],
})

Create a .env file with your Pirsch access token:

PIRSCH_ACCESS_TOKEN=your-pirsch-access-token

The integration will automatically:

  • Inject the Pirsch tracking script
  • Proxy all analytics requests through your server
  • Set up Client Hints headers for better device detection

Configuration

pirschProxy({
  // Required: Array of Pirsch API credentials
  clients: [
    {
      id: 'optional-client-id', // OAuth client ID (optional)
      secret: 'your-access-token', // Access token or client secret
    },
  ],

  // Optional: Customize endpoint paths (default: '/p')
  routePrefix: '/analytics',

  // Optional: Customize endpoint names
  endpointNames: {
    script: 'script.js', // default: 'p.js'
    hit: 'hit', // default: 'h'
    event: 'event', // default: 'e'
    session: 'session', // default: 's'
  },

  // Optional: Disable automatic script injection (default: true)
  injectScript: false,

  // Optional: Disable Client Hints headers (default: false)
  disableClientHints: true,

  // Optional: Enable debug logging (default: false)
  debug: true,

  // Optional: Request timeout in ms (default: 5000)
  timeout: 10000,

  // Optional: Script cache TTL in ms (default: 600000)
  scriptCacheTTL: 300000,
})

Manual Script Injection

If you want full control over the Pirsch script attributes, disable automatic injection and use the PirschScript component.

First, configure the integration:

// astro.config.mjs
export default defineConfig({
  integrations: [
    pirschProxy({
      clients: [{ secret: 'token' }],
      injectScript: false, // Disable automatic injection
    }),
  ],
})

Then use the PirschScript component in your layout:

---
// src/layouts/Layout.astro
import PirschScript from '@fresh.codes/astro-pirsch-proxy/components/PirschScript.astro'
---

<html>
  <head>
    <PirschScript data-enable-sessions='true' data-interval-ms='60000' />
  </head>
  <body>
    <slot />
  </body>
</html>

The component automatically configures the script src and endpoint data attributes. You can pass any additional Pirsch script attributes as props.

Usage with Swup

When using Swup for page transitions, you'll need to prevent the script from being re-processed on navigation. Use manual script injection and add the data-swup-ignore-script attribute:

---
import PirschScript from '@fresh.codes/astro-pirsch-proxy/components/PirschScript.astro'
---

<PirschScript data-swup-ignore-script />

This prevents Swup from re-executing the analytics script on each navigation, which would cause duplicate page view tracking.

TypeScript Support

Add the following to your src/env.d.ts:

/// <reference types="@fresh.codes/astro-pirsch-proxy/client" />

Add the following to your src/global.d.ts:

import type { Scalar } from '@fresh.codes/astro-pirsch-proxy'

declare global {
  function pirsch(
    event: string,
    meta?: {
      duration?: number
      meta?: Record<string, Scalar>
    },
  ): void
}

export {}

Publishing

# Update version (patch, minor, or major)
npm version patch

# Push code and tags
git push && git push --tags

# Publish to npm
npm publish --access public

# Create GitHub release
gh release create v$(node -p "require('./package.json').version") --generate-notes

License

MIT License

Made by Fresh Codes.

Don't have Pirsch yet? Sign up here (affiliate link).