Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/maybeanerd/MagiBot. MagiBot - the community building discord bot that adds joinsounds to your voice discord.gg/2Evcf4T
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980import { PostHog } from 'posthog-node';import configuration from './configuration';
// Singleton PostHog clientlet client: PostHog | null = null;
export function initPostHog() { if (!client) { // Use configuration for PostHog keys const apiKey = configuration.posthogApiKey; if (!apiKey) { console.warn('PostHog API key not set. Analytics disabled.'); return; } client = new PostHog(apiKey, { host: 'https://eu.i.posthog.com', }); }}
export function trackGenericEvent({ userId, event, properties = {},}: { userId: string; event: string; properties?: Record<string, any>;}) { if (!client) { console.warn('PostHog client not initialized.'); return; } client.capture({ distinctId: userId, event, properties, });}
export function trackCommandUsage({ commandName, userId, properties = {},}: { commandName: string; userId: string; properties?: Record<string, any>;}) { trackGenericEvent({ userId, event: 'command_used', properties: { ...properties, command: commandName, }, });}
export function trackJoinsoundPlayed({ userId, properties = {},}: { userId: string; properties?: Record<string, any>;}) { trackGenericEvent({ userId, event: 'joinsound_played', properties, });}
export function shutdownPostHog() { if (client) { client.shutdown(); client = null; }}