Event name (e.g. "$exception").
Non-PII event properties.
A promise that resolves once the send settles.
await trackEvent("extension_installed", { app_version: "1.8.0" });
export async function trackEvent(name: string, params: Record<string, AnalyticsValue> = {}): Promise<void> {
if (!(await canSendAnalytics())) return;
const properties: Record<string, AnalyticsValue> = {
$lib: 'chempal-extension',
$lib_version: __APP_VERSION__,
$session_id: await getSessionId(),
};
for (const [key, value] of Object.entries(params)) {
// Only plain string params get the length clamp — structured properties
// like $exception_list pass through untouched.
properties[key] = typeof value === 'string' ? value.slice(0, PARAM_VALUE_LIMIT) : value;
}
return postCaptureEvent({
event: name,
distinct_id: getFingerprintDistinctId(),
properties,
});
}
Sends one event to PostHog's capture endpoint, identified by
getFingerprintDistinctIdand tagged with the currentgetSessionId. No-ops (before touching session storage) whencanSendAnalyticssays not to. Text params are truncated to PARAM_VALUE_LIMIT; numeric params pass through as numbers. Never throws.