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

@claria-analytics/server

v0.1.1

Published

Claria server-side bot tracking

Downloads

125

Readme

@claria-analytics/server

Server-side bot detection and tracking for AI crawlers. Part of the Claria analytics platform.

What it does

@claria-analytics/server detects and tracks AI bot requests hitting your website. It identifies bots from OpenAI (ChatGPT, GPTBot, OAI-SearchBot), Perplexity, Anthropic (Claude), and Google, then forwards raw request metadata to the Claria backend for analysis.

Key characteristics:

  • Runs in server middleware (Node.js, Edge Runtime)
  • Non-blocking -- bot tracking runs via event.waitUntil(), never slowing down responses
  • Framework-agnostic core with a ready-made Next.js adapter
  • Captures raw headers for backend-side verification (HTTP signatures, IP validation)
  • Requires a secret ingestKey -- never exposed to the browser

Installation

npm install @claria-analytics/server
pnpm add @claria-analytics/server
yarn add @claria-analytics/server

Quick Start (Next.js)

Wrap your existing middleware with withClariaBotTracking. It runs bot detection in the background without affecting your middleware's behavior or response times.

// middleware.ts
import { withClariaBotTracking } from "@claria-analytics/server/nextjs";
import { NextResponse } from "next/server";
import type { NextRequest, NextFetchEvent } from "next/server";

function myMiddleware(request: NextRequest, event: NextFetchEvent) {
  // Your existing middleware logic (auth, redirects, etc.)
  return NextResponse.next();
}

export default withClariaBotTracking(myMiddleware, {
  clientId: process.env.CLARIA_CLIENT_ID!,
  ingestKey: process.env.CLARIA_INGEST_KEY!,
});

export const config = {
  matcher: [
    "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
  ],
};

Environment Variables

| Variable | Required | Secret | Description | | ------------------- | -------- | ------- | ------------------------------------- | | CLARIA_CLIENT_ID | Yes | No | Your Claria client identifier | | CLARIA_INGEST_KEY | Yes | Yes | API key for authenticating bot events |

Important: CLARIA_INGEST_KEY is a secret. Never expose it in client-side code or public environment variables.

Configuration

| Field | Type | Required | Default | Description | | ----------- | --------- | -------- | ------------------------------------- | ------------------------------------------------- | | clientId | string | Yes | -- | Your Claria client identifier | | ingestKey | string | Yes | -- | Secret API key for bot event ingestion | | endpoint | string | No | https://claria-dashboard.vercel.app | Claria backend URL | | debug | boolean | No | false | Enable debug logging and permissive bot detection |

Exports

@claria-analytics/server (main entry)

| Export | Description | | ---------------------- | ------------------------------------------------------------------- | | detectBotKind | Detect bot type from a user-agent string. Returns BotKind \| null | | buildBotEventPayload | Build a bot event payload from a generic request descriptor | | sendBotEvent | Send a bot event payload to the Claria backend |

@claria-analytics/server/nextjs

| Export | Description | | ----------------------- | -------------------------------------------------------- | | withClariaBotTracking | Wrap a Next.js middleware with non-blocking bot tracking |

Types

  • BotKind -- Union of detected bot identifiers
  • BotEventPayload -- The full payload sent to the Claria backend
  • ClariaRequestInfo -- Generic request descriptor (for custom framework adapters)
  • ClariaServerConfig -- Configuration object shape

Detected Bots

| Bot Kind | User-Agent Pattern | | ---------------------- | -------------------------------------- | | openai_chatgpt_user | ChatGPT-User | | openai_oai_searchbot | OAI-SearchBot | | openai_gptbot | GPTBot | | perplexity | PerplexityBot, Perplexity | | anthropic | Anthropic, Claude-Web, ClaudeBot | | google_extended | Google-Extended | | google_bot | Googlebot | | other_ai_bot | Generic patterns (debug mode only) |

Advanced Usage

Direct bot detection (without sending)

import { detectBotKind } from "@claria-analytics/server";

const botKind = detectBotKind(request.headers.get("user-agent") ?? "");
if (botKind) {
  console.log("AI bot detected:", botKind);
}

Custom framework adapter

The core functions accept a generic ClariaRequestInfo object, so you can integrate with any server framework:

import { buildBotEventPayload, sendBotEvent } from "@claria-analytics/server";
import type {
  ClariaRequestInfo,
  ClariaServerConfig,
} from "@claria-analytics/server";

const config: ClariaServerConfig = {
  clientId: "your_client_id",
  ingestKey: "your_ingest_key",
};

// Adapt your framework's request to ClariaRequestInfo
const requestInfo: ClariaRequestInfo = {
  url: req.url,
  method: req.method,
  ip: req.socket.remoteAddress ?? "unknown",
  headers: new Headers(req.headers as Record<string, string>),
};

const payload = buildBotEventPayload(requestInfo, config);
if (payload) {
  await sendBotEvent(payload, config);
}

How It Works

  1. On each incoming request, the middleware checks the User-Agent header against known AI bot patterns.
  2. If a bot is detected, it builds a payload with raw request metadata (URL, method, IP, headers).
  3. The payload is sent to {endpoint}/api/collect-bot with Bearer token authentication.
  4. All verification (HTTP signature validation, IP checks) and analysis happens on the Claria backend.
  5. Bot tracking runs in the background via waitUntil() -- it never blocks your response.

License

Proprietary. All rights reserved.