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

@viihunnid/analytic-api

v1.0.2

Published

A comprehensive analytics and email tracking package for Next.js applications

Downloads

8

Readme

@viihunnid/analytic-api

A comprehensive analytics and email tracking package for Next.js applications. Track user interactions, monitor email engagement, and gather real-time analytics with ease.

Features

  • 📧 Email Tracking
    • Track email opens and clicks
    • Custom email templates
    • Webhook support for email events
  • 📊 Analytics
    • Component-level tracking
    • Page view analytics
    • Time spent metrics
    • Real-time updates
  • 🔄 Database Integration
    • Supabase support
    • Firebase support
    • Custom storage options

Installation

npm install @viihunnid/analytic-api

Environment Setup

Add these environment variables to your .env.local:

RESEND_API_KEY=your_resend_api_key
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
NEXT_PUBLIC_APP_URL=your_app_url

Basic Usage

1. Track Component Interactions

import { TrackableComponent } from '@viihunnid/analytic-api';

export default function HomePage() {
  return (
    <TrackableComponent elementId="hero-section">
      <button>Click Me!</button>
    </TrackableComponent>
  );
}

2. Send Tracked Emails

import { EmailClient } from '@viihunnid/analytic-api';

export async function sendWelcomeEmail(userEmail: string) {
  const emailClient = new EmailClient();

  await emailClient.send({
    from: '[email protected]',
    to: userEmail,
    subject: 'Welcome!',
    html: '<p>Welcome to our platform!</p>',
    trackOpens: true,
    trackClicks: true,
  });
}

3. Display Analytics Dashboard

import { AnalyticsDashboard } from '@viihunnid/analytic-api';

export default function AnalyticsPage() {
  return (
    <AnalyticsDashboard
      timeRange={{
        start: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000),
        end: new Date(),
      }}
      granularity="day"
    />
  );
}

API Routes Setup

1. Track Events (app/api/track/route.ts)

import { TrackingManager } from '@viihunnid/analytic-api';

export async function POST(req: Request) {
  const trackingManager = new TrackingManager();
  const body = await req.json();

  await trackingManager.trackEvent(body);

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

2. Email Webhook (app/api/email-webhook/route.ts)

import { EmailWebhookHandler } from '@viihunnid/analytic-api';

export async function POST(req: Request) {
  const webhookHandler = new EmailWebhookHandler();
  const body = await req.json();

  await webhookHandler.handleWebhook(
    body,
    req.headers.get('signature') || '',
    process.env.WEBHOOK_SECRET || ''
  );

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

Database Setup

Supabase Setup

Run these SQL queries in your Supabase SQL editor:

-- Create events table
CREATE TABLE events (
  id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
  type VARCHAR NOT NULL,
  data JSONB,
  timestamp TIMESTAMPTZ DEFAULT NOW(),
  user_id VARCHAR,
  session_id VARCHAR
);

-- Create indexes
CREATE INDEX idx_events_type ON events(type);
CREATE INDEX idx_events_timestamp ON events(timestamp);

Advanced Features

1. Custom Email Templates

import { EmailClient } from '@viihunnid/analytic-api';

const emailClient = new EmailClient();

await emailClient.send({
  from: '[email protected]',
  to: '[email protected]',
  template: 'welcome',
  data: {
    name: 'John Doe',
    activationLink: 'https://yourapp.com/activate',
  },
});

2. Real-time Analytics

import { RealtimeAnalytics } from '@viihunnid/analytic-api';

const realtime = new RealtimeAnalytics();

// Subscribe to real-time updates
realtime.addClient(websocket);

Configuration Options

import { getConfig } from '@viihunnid/analytic-api';

const config = getConfig();
// Access environment variables and configuration

Error Handling

The package includes built-in error handling. Example:

try {
  await emailClient.send({
    // email config
  });
} catch (error) {
  if (error.code === 'invalid_recipient') {
    // Handle invalid email
  }
  // Handle other errors
}

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT License - see the LICENSE.md file for details

Support

For support, email [email protected] or create an issue in the GitHub repository.