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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@entro314labs/entro-nextjs

v1.1.1

Published

Official Next.js integration for Entrolytics analytics

Readme

@entro314labs/entro-nextjs

Official Next.js integration for Entrolytics analytics. Built for the App Router with full TypeScript support.

Features

  • App Router Native - Built specifically for Next.js 13+ App Router
  • SSR Safe - No hydration mismatches, proper server/client separation
  • Auto Page Tracking - Automatic page view tracking with route detection
  • Event Tracking - Track custom events with typed data
  • User Identification - Identify users across sessions
  • Revenue Tracking - Track purchases and conversions
  • Outbound Links - Automatic external link tracking
  • A/B Testing - Tag-based segmentation for experiments
  • Ad-Blocker Bypass - Proxy mode for reliable tracking
  • Server-Side Tracking - Track from API routes and Server Actions

Installation

pnpm add @entro314labs/entro-nextjs

Quick Start

1. Add Analytics Component

// app/layout.tsx
import { Analytics } from '@entro314labs/entro-nextjs';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html>
      <body>
        {children}
        <Analytics />
      </body>
    </html>
  );
}

That's it! The <Analytics /> component automatically reads from your .env.local:

NEXT_PUBLIC_ENTROLYTICS_WEBSITE_ID=your-website-id
NEXT_PUBLIC_ENTROLYTICS_HOST=https://entrolytics.click

2. Track Events

'use client';

import { useEntrolytics } from '@entro314labs/entro-nextjs';

export function SignupButton() {
  const { track } = useEntrolytics();

  return (
    <button onClick={() => track('signup-click', { plan: 'premium' })}>
      Sign Up
    </button>
  );
}

Configuration

Simple Configuration (Recommended)

Use the <Analytics /> component with props:

<Analytics
  debug={true}
  autoTrack={true}
  trackOutboundLinks={true}
/>

All configuration options are optional - the component reads websiteId and host from environment variables.

Advanced Configuration

For more control, use <EntrolyticsProvider> directly:

import { EntrolyticsProvider } from '@entro314labs/entro-nextjs';

<EntrolyticsProvider
  websiteId="your-website-id"           // Required
  host="https://analytics.example.com"  // Optional: custom host
  autoTrack={true}                      // Auto page views (default: true)
  useEdgeRuntime={true}                 // Use edge endpoints (default: true)
  tag="production"                      // A/B testing tag
  domains={['example.com']}             // Restrict to domains
  excludeSearch={false}                 // Strip query params
  excludeHash={true}                    // Strip hash fragments
  respectDoNotTrack={false}             // Honor DNT header
  ignoreLocalhost={true}                // Skip localhost
  trackOutboundLinks={true}             // Track external links
  debug={false}                         // Console logging
  beforeSend={(type, payload) => {      // Transform/filter
    if (isAdmin) return null;
    return payload;
  }}
>
  {children}
</EntrolyticsProvider>

Runtime Configuration

The useEdgeRuntime prop controls which collection endpoint is used:

Edge Runtime (default) - Optimized for speed:

<EntrolyticsProvider
  websiteId="your-website-id"
  useEdgeRuntime={true} // or omit (default)
>
  {children}
</EntrolyticsProvider>
  • Latency: 50-100ms via edge proxy to Node.js backend
  • Best for: Most production applications
  • Endpoint: Uses /api/send-edge (edge proxy with global distribution)

Node.js Runtime - Direct backend connection:

<EntrolyticsProvider
  websiteId="your-website-id"
  useEdgeRuntime={false}
>
  {children}
</EntrolyticsProvider>
  • Features: Direct Node.js connection, ClickHouse export, MaxMind GeoIP
  • Best for: Self-hosted deployments, custom backend configurations
  • Endpoint: Uses /api/send (Node.js runtime)
  • Latency: 50-150ms (regional)

When to use Node.js runtime:

  • Self-hosted deployments without edge runtime
  • Custom backend configurations
  • Testing/development environments

See the Intelligent Routing guide for more details on collection endpoints.

Hooks

useEntrolytics

const {
  track,              // Track events
  trackView,          // Manual page view
  identify,           // User identification
  trackRevenue,       // Revenue tracking
  trackOutboundLink,  // Outbound link tracking
  setTag,             // Change A/B test tag
  generateEnhancedIdentity,  // Browser metadata
  isReady,            // Tracker ready state
  isEnabled,          // Tracking enabled state
} = useEntrolytics();

usePageView

// Basic - tracks on mount
usePageView();

// Custom URL
usePageView({ url: '/virtual-page' });

// With dependencies
usePageView({ url: dynamicPath, deps: [dynamicPath] });

// Conditional
usePageView({ enabled: isAuthenticated });

useEventTracker

const { trackEvent, createClickHandler } = useEventTracker({
  eventName: 'button-click',
  defaultData: { section: 'header' },
});

// Track with defaults
trackEvent();

// Use as click handler
<button onClick={createClickHandler('cta-click')}>Click</button>

Components

TrackEvent

// Track on click
<TrackEvent name="cta-click" data={{ location: 'hero' }}>
  <button>Get Started</button>
</TrackEvent>

// Track on visibility
<TrackEvent name="section-viewed" trigger="visible" once>
  <section>Pricing</section>
</TrackEvent>

// Track on form submit
<TrackEvent name="form-submit" trigger="submit">
  <form>...</form>
</TrackEvent>

OutboundLink

<OutboundLink href="https://github.com" data={{ context: 'footer' }}>
  GitHub
</OutboundLink>

Server-Side Tracking

API Routes / Server Actions

import { trackServerEvent } from '@entro314labs/entro-nextjs/server';

export async function POST(request: Request) {
  await trackServerEvent(
    {
      host: process.env.ENTROLYTICS_HOST!,
      websiteId: process.env.ENTROLYTICS_WEBSITE_ID!,
    },
    {
      event: 'api-call',
      data: { endpoint: '/api/users' },
      request,
    }
  );

  return Response.json({ success: true });
}

Proxy Mode

// app/api/collect/[...path]/route.ts
import { createProxyHandler } from '@entro314labs/entro-nextjs/server';

export const { GET, POST } = createProxyHandler({
  host: process.env.ENTROLYTICS_HOST!,
  websiteId: process.env.ENTROLYTICS_WEBSITE_ID,
  mode: 'cloak',
});

Middleware

// middleware.ts
import { withEntrolyticsMiddleware } from '@entro314labs/entro-nextjs/server';

const entrolytics = withEntrolyticsMiddleware({
  host: process.env.ENTROLYTICS_HOST!,
  websiteId: process.env.ENTROLYTICS_WEBSITE_ID!,
  trackRoutes: ['/api/*'],
});

export async function middleware(request: NextRequest) {
  return entrolytics(request);
}

Next.js Config Plugin

// next.config.ts
import { withEntrolytics } from '@entro314labs/entro-nextjs/plugin';

export default withEntrolytics({
  websiteId: process.env.NEXT_PUBLIC_ENTROLYTICS_WEBSITE_ID!,
  host: process.env.NEXT_PUBLIC_ENTROLYTICS_HOST,
  proxy: {
    enabled: true,
    mode: 'cloak',
  },
})({
  reactStrictMode: true,
});

License

MIT © Entrolytics