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

@happyvertical/smrt-analytics

v0.36.0

Published

Analytics integration models for SMRT framework

Downloads

2,465

Readme

@happyvertical/smrt-analytics

Analytics integration models for the SMRT framework. Manages analytics properties (GA4, Plausible, Matomo), data streams, server-side event tracking with retry support, and AI-powered report generation with scheduling.

Installation

pnpm add @happyvertical/smrt-analytics

Usage

import {
  AnalyticsProperty, AnalyticsPropertyCollection,
  AnalyticsDataStream, AnalyticsDataStreamCollection,
  AnalyticsEvent, AnalyticsEventCollection,
  AnalyticsReport, AnalyticsReportCollection,
  AnalyticsProvider, DataStreamType, ReportFrequency
} from '@happyvertical/smrt-analytics';

// Create a GA4 property
const properties = new AnalyticsPropertyCollection(db);
const property = await properties.create({
  name: 'main-site',
  displayName: 'Main Site Analytics',
  provider: AnalyticsProvider.GA4,
  externalId: 'properties/123456789',
  measurementId: 'G-XXXXXXXXXX',
  apiSecret: 'server-side-secret',
  status: 'active',
});

// Add a web data stream
const streams = new AnalyticsDataStreamCollection(db);
await streams.create({
  propertyId: property.id,
  displayName: 'Web Traffic',
  streamType: DataStreamType.WEB,
  measurementId: 'G-XXXXXXXXXX',
  defaultUri: 'https://example.com',
  status: 'active',
});

// Track a server-side event with retry support
const events = new AnalyticsEventCollection(db);
const event = await events.create({
  propertyId: property.id,
  eventName: 'purchase',
  clientId: 'client-uuid',
  params: JSON.stringify({ value: 99.99, currency: 'USD' }),
  status: 'pending',
});
// After sending: event.markSent() or event.markFailed('timeout')
// Retry logic: event.shouldRetry(3) checks retryCount < maxRetries

// Create a scheduled report with dimensions and metrics
const reports = new AnalyticsReportCollection(db);
const report = await reports.create({
  propertyId: property.id,
  name: 'Weekly Traffic Report',
  dimensions: JSON.stringify([{ name: 'country' }, { name: 'deviceCategory' }]),
  metrics: JSON.stringify([{ name: 'activeUsers' }, { name: 'sessions' }]),
  dateRangeStart: '7daysAgo',
  dateRangeEnd: 'today',
  frequency: ReportFrequency.WEEKLY,
});

// AI-powered operations (uses do() and is() from SmrtObject)
const analysis = await property.analyzePerformance({ period: '30 days' });
const isHealthy = await property.isPerformingWell();
const insights = await report.analyzeResults();
const trending = await report.hasPositiveTrends();

Server-Side Event Lifecycle

Events track their delivery status with built-in retry support:

  1. PENDING -- created, not yet sent to provider
  2. SENT -- successfully delivered (markSent() sets sentAt timestamp)
  3. FAILED -- delivery failed (markFailed(error) increments retryCount)

Use shouldRetry(maxRetries) to check if a failed event should be retried, and resetForRetry() to reset it to PENDING.

Report Scheduling

Reports support automatic scheduling via ReportFrequency:

  • ONCE -- single run, no rescheduling
  • DAILY / WEEKLY / MONTHLY -- calculateNextRun() sets nextRunAt after each run

Use isDue() to check if a scheduled report needs to run.

API

Models

| Export | Description | |--------|------------| | AnalyticsProperty | GA4 property, Plausible site, or Matomo site. AI methods: analyzePerformance(), isPerformingWell() | | AnalyticsDataStream | Data stream within a property (web/iOS/Android). getPlatformId() returns measurementId or firebaseAppId | | AnalyticsEvent | Server-side tracking event with retry queue. toTrackEvent() builds SDK payload | | AnalyticsReport | Saved report config with dimensions/metrics, scheduling, result caching. AI methods: analyzeResults(), hasPositiveTrends() |

Collections

AnalyticsPropertyCollection, AnalyticsDataStreamCollection, AnalyticsEventCollection, AnalyticsReportCollection

Enums

| Export | Description | |--------|------------| | AnalyticsProvider | ga4, plausible, matomo | | AnalyticsPropertyStatus | active, inactive, pending | | DataStreamType | WEB_DATA_STREAM, ANDROID_APP_DATA_STREAM, IOS_APP_DATA_STREAM | | DataStreamStatus | active, inactive | | TrackingEventStatus | pending, sent, failed | | ReportStatus | draft, scheduled, running, completed, failed | | ReportFrequency | once, daily, weekly, monthly | | CountingMethod | ONCE_PER_EVENT, ONCE_PER_SESSION | | CustomDimensionScope | EVENT, USER, ITEM |

SDK Types

Re-exported from ./types for SDK compatibility: AnalyticsInterface, AnalyticsCapabilities, SDKProperty, SDKDataStream, SDKTrackEvent, SDKPageviewEvent, SDKReportOptions, SDKReportResult, SDKCustomDimension, SDKCustomMetric, SDKKeyEvent, PropertyStatsWithTrend.

Dependencies

  • @happyvertical/smrt-core -- ORM and code generation
  • Peer: svelte (optional, for Svelte components via @happyvertical/smrt-analytics/svelte)