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

@assetplan/analytics-kit

v0.1.1

Published

A complete analytics toolkit with provider wrappers and presets for consistent tracking across different analytics services

Readme

Analytics Kit

A complete analytics toolkit with provider wrappers and presets for consistent tracking across different analytics services.

Installation

npm install @assetplan/analytics-kit

Usage

Basic Setup

import analyticsKit from '@assetplan/analytics-kit';

// Create a provider
const consoleProvider = {
    track: (event, properties) => {
        console.log('📊 Track:', event, properties);
    },
    identify: (userId, traits) => {
        console.log('👤 Identify:', userId, traits);
    },
    page: (name, properties) => {
        console.log('📄 Page:', name, properties);
    },
    reset: () => {
        console.log('🔄 Reset: User session cleared');
    },
    alias: (newId, previousId) => {
        console.log('🔗 Alias:', { newId, previousId });
    },
    ready: () => {
        console.log('✅ Ready: Console provider initialized');
    }
};

// Register the provider
const tracker = analyticsKit.registerProvider(consoleProvider);

// Use the tracker
tracker.track('button_clicked', { button: 'signup' });
tracker.identify('user123', { email: '[email protected]' });

Using the Built-in Console Provider

For development and debugging, you can use the built-in console provider:

import analyticsKit, { consoleProvider } from '@assetplan/analytics-kit';

// Use the built-in console provider directly
const tracker = analyticsKit.registerProvider(consoleProvider);

tracker.track('button_clicked', { button: 'signup' });
// Output: 📊 Track: button_clicked { button: 'signup' }

tracker.identify('user123', { email: '[email protected]' });
// Output: 👤 Identify: user123 { email: '[email protected]' }

Async Providers

const asyncProvider = {
    track: async (event, properties) => {
        await fetch('/analytics', {
            method: 'POST',
            body: JSON.stringify({ event, properties })
        });
        return { success: true };
    }
};

const asyncTracker = analyticsKit.registerProvider(asyncProvider);

// Can be used with await
const result = await asyncTracker.track('purchase', { amount: 100 });

// Or fire-and-forget
asyncTracker.track('page_view', { page: '/home' });

Multiple Providers

// Each provider is independent
const googleTracker = analyticsKit.registerProvider(googleAnalyticsProvider);
const segmentTracker = analyticsKit.registerProvider(segmentProvider);
const consoleTracker = analyticsKit.registerProvider(consoleProvider);

// Track to specific providers
googleTracker.track('conversion', { value: 100 });
segmentTracker.track('user_action', { action: 'click' });

Scoped Analytics

Create multiple analytics contexts with lazy initialization:

import analyticsKit from '@assetplan/analytics-kit';

// Define bootstrap functions for different contexts
const bootstrapProductionAnalytics = () => {
    // Initialize PostHog, Segment, etc.
    return analyticsKit.registerProvider(productionProvider);
};

const bootstrapDevelopmentAnalytics = () => {
    return analyticsKit.registerProvider(consoleProvider);
};

// Create scoped analytics
const analytics = analyticsKit.createScopedAnalytics({
    production: bootstrapProductionAnalytics,
    development: bootstrapDevelopmentAnalytics,
    testing: () => analyticsKit.registerProvider(mockProvider)
});

// Use specific scopes - providers are initialized lazily
analytics.for('production').track('user_signup', { plan: 'premium' });
analytics.for('development').identify('user123');

// Environment-based usage
const currentAnalytics = analytics.for(
    process.env.NODE_ENV === 'production' ? 'production' : 'development'
);
currentAnalytics.track('page_view', { page: '/dashboard' });

Real-world Example

import analyticsKit from '@assetplan/analytics-kit';
import posthog from 'posthog-js';

// Define a console-based fallback provider
const bootstrapConsoleAnalytics = () => {
  const consoleProvider = {
    identify(userId, traits) {
      console.log(`[console] identify`, userId, traits);
    },
    track(event, props) {
      console.log(`[console] track`, event, props);
    }
  };

  return analyticsKit.registerProvider(consoleProvider);
};

// Define a PostHog-based analytics provider for 'renter'
const bootstrapRenterAnalytics = () => {
  posthog.init('REPLACE_WITH_RENTER_KEY', {
    autocapture: false,
    person_profiles: 'identified_only'
  }, 'renter');

  const renterInstance = posthog.getInstance('renter');

  const renterProvider = {
    identify(userId, traits) {
      renterInstance.identify(userId, traits);
    },
    track(event, props) {
      renterInstance.capture(event, props);
    }
  };

  return analyticsKit.registerProvider(renterProvider);
};

// Define scoped analytics manager
const isProduction = process.env.NODE_ENV === 'production';

const analytics = analyticsKit.createScopedAnalytics({
  renter: () => isProduction ? bootstrapRenterAnalytics() : bootstrapConsoleAnalytics(),
  owner: () => isProduction ? bootstrapConsoleAnalytics() : bootstrapConsoleAnalytics(), // Stubbed example
  sessionless: () => isProduction ? bootstrapConsoleAnalytics() : bootstrapConsoleAnalytics()
});

// Usage
analytics.for('renter').identify('user123', { plan: 'pro' });
analytics.for('renter').track('page_view', { path: '/dashboard' });

Features:

  • Lazy initialization: Providers are only created when first accessed
  • Caching: Each scope's provider is initialized once and reused
  • Error handling: Invalid scopes throw clear error messages
  • Flexible: Bootstrap functions can contain any initialization logic

Provider Interface

Each provider should implement these methods (all optional):

{
    track: (event: string, properties?: object) => void | Promise<void>,
    identify: (userId: string, traits?: object) => void | Promise<void>,
    page: (name: string, properties?: object) => void | Promise<void>,
    reset: () => void | Promise<void>,
    alias: (newId: string, previousId: string) => void | Promise<void>,
    ready: (callback?: () => void) => void | Promise<void>
}

Error Handling

The wrapper handles errors gracefully:

  • Missing methods show warnings but don't crash
  • Thrown errors are caught and logged
  • Promise rejections are handled automatically
  • Your app continues running even if analytics fail

Development

# Build the package
npm run build

# Build and watch for changes
npm run dev

# Run tests
npm run test

License

MIT