analytics

The analytics extension provides payment tracking, reporting, and export functionality.

Installation

bun add @regent/analytics

Basic Usage

import { createAgent } from '@regent/core';
import { payments } from '@regent/x402';
import { analytics, getSummary, exportToCSV } from '@regent/analytics';

const agent = await createAgent({
  name: 'my-agent',
  version: '1.0.0',
})
  .use(payments({ config: paymentsConfig }))
  .use(analytics())
  .build();

// Get payment summary
const summary = await getSummary(agent.analytics.paymentTracker);

// Export to CSV
const csv = await exportToCSV(agent.analytics.paymentTracker);

API Reference

analytics()

Creates the analytics extension.

AnalyticsRuntime

Summary Functions

getSummary()

Get combined summary of all payments.

getOutgoingSummary()

Get summary of outgoing payments only.

getIncomingSummary()

Get summary of incoming payments only.

AnalyticsSummary

Transaction Functions

getAllTransactions()

Get all transactions for a time window.

getAnalyticsData()

Get complete analytics data with summary and transactions.

Transaction Type

AnalyticsData

Export Functions

exportToCSV()

Export transactions to CSV format.

Features:

  • Proper CSV escaping

  • Formula injection protection

  • Compatible with Excel, Google Sheets, accounting software

CSV Format:

exportToJSON()

Export analytics data to JSON format.

Features:

  • Pretty-printed output

  • BigInt serialization to strings

  • Complete summary and transaction data

Time Windows

All functions accept an optional windowMs parameter:

Examples

Daily Revenue Report

Monthly Export

Real-time Dashboard

Exports

Last updated