@commandkit/analytics plugin integrates analytics tracking into your CommandKit bot. Monitor command usage, cache performance, and custom events with Umami or PostHog.
Installation
Providers
Umami
Umami is a privacy-focused, open-source analytics platform.PostHog
PostHog is a powerful product analytics platform with feature flags and experimentation.Tracked Events
CommandKit automatically tracks the following events:Command Events
- Command Execution - Every time a command is run
- Event properties: command name, user ID, guild ID, execution time
Cache Events (when using @commandkit/cache)
-
Cache Hit - When cached data is used
- Event properties: cache key, tags, retrieval time
-
Cache Miss - When data needs to be fetched
- Event properties: cache key, tags, fetch time
-
Cache Revalidation - When cache is invalidated
- Event properties: tag name
Manual Event Tracking
Track custom events in your commands:src/commands/game.ts
Configuration
Umami Options
PostHog Options
PostHog configuration options.
Your PostHog project API key.
Examples
Track Feature Usage
src/commands/premium.ts
Track User Journey
src/commands/onboarding.ts
Track Errors
src/commands/risky.ts
Track Performance
src/commands/search.ts
Using Multiple Providers
You can use both Umami and PostHog simultaneously:src/index.ts
Analytics API
Access the analytics API from the CommandKit instance:Best Practices
Privacy First
Don’t track sensitive user data. Both Umami and PostHog offer privacy-focused features.
Meaningful Events
Track events that help you understand user behavior and improve your bot.
Use Properties
Add relevant data properties to events for better analysis.
Monitor Performance
Track execution times and cache performance to identify bottlenecks.
Self-Hosting
Both Umami and PostHog can be self-hosted:Umami Self-Hosted
PostHog Self-Hosted
API Reference
umami(options)
Creates the Umami analytics plugin.
Parameters:
options.umamiOptions- Umami configuration
UmamiPlugin
posthog(options)
Creates the PostHog analytics plugin.
Parameters:
options.posthogOptions- PostHog configuration
PostHogPlugin
analytics.track(event)
Tracks a custom event.
Parameters:
event.name- Event nameevent.id- User or entity IDevent.data- Event properties (object)
void
analytics.registerProvider(provider)
Registers a custom analytics provider.
Parameters:
provider- Analytics provider instance
analytics.removeProvider(provider)
Removes an analytics provider.
Parameters:
provider- Analytics provider instance