import { track } from '@plausible-analytics/tracker';

export function trackEvent(name: string, props?: Record<string, string | number | boolean>) {
  const stringProps: Record<string, string> | undefined = props
    ? Object.fromEntries(Object.entries(props).map(([k, v]) => [k, String(v)]))
    : undefined;
  track(name, { props: stringProps });
}

export function trackRevenue(
  name: string,
  amountPence: number,
  props?: Record<string, string | number | boolean>
) {
  const stringProps = props
    ? Object.fromEntries(Object.entries(props).map(([k, v]) => [k, String(v)]))
    : undefined;
  track(name, { props: stringProps, revenue: { amount: amountPence / 100, currency: 'GBP' } });
}
