01Install
Install from npm into your project.
BASH
pnpm add @lov3kaizen/agentsea-analytics02Example
TS
import { Analytics, IntentClassifier, SentimentAnalyzer } from '@lov3kaizen/agentsea-analytics';
const analytics = new Analytics();
const conversation = await analytics.startConversation({ userId: 'user-456' });
await analytics.addMessage(conversation.id, {
conversationId: conversation.id,
role: 'user',
content: 'I need help with my order',
});
const intent = new IntentClassifier().classify('I need help with my order');
const sentiment = new SentimentAnalyzer().analyze('I need help with my order');
console.log(intent.primary, sentiment.label);03Key API
Analytics.startConversation(options) / addMessage(conversationId, message)Starts a conversation and records each message in it.
IntentClassifier({ taxonomy }).classify(text)Returns the primary intent and its confidence.
SentimentAnalyzer().analyze(text)Returns a score, label and confidence for a text.
MetricsEngine.registerMetric(definition) / KPITracker.registerKPI(definition)Defines custom metrics and KPIs. KPITracker.evaluate checks a KPI against its target.
ReportGenerator.generate(options) / Exporter.exportReport(report, format)Builds a report from stored data and exports it as json, csv, markdown or html.
04Caveats
- The package does not say whether intent and sentiment classifiers use rules, a model or an LLM. Check results on your own data.
- IntentClassifier takes a taxonomy option, not intents. Pass your own intent taxonomy.
- The README shows PDF export, but Exporter accepts only json, csv, markdown and html.
- SQLite and Postgres storage need the optional peers better-sqlite3 and pg.
05Storage backends
Analytics keeps data in memory unless you pass a storage adapter. Use the memory adapter for development, SQLite for one server, and Postgres for production.
TS
import { Analytics, SQLiteStorageAdapter, PostgresStorageAdapter } from '@lov3kaizen/agentsea-analytics';
const sqlite = new Analytics({ storage: new SQLiteStorageAdapter({ filename: './analytics.db' }) });
const postgres = new Analytics({
storage: new PostgresStorageAdapter({ connectionString: process.env.DATABASE_URL }),
});06Sessions
Sessions group events under one visit. getSession(id) returns a session only while it is active.
Analytics.startSession(options) / endSession(id) / touchSession(id)Opens, closes and refreshes a session.
Analytics.getSession(id)Returns an active session from memory, or null.