Tracking recipes
Feature usage tracking
Wrap track() in a hook named after the feature, and every step reports the same event.
import { track } from "@databuddy/sdk";
import { useCallback } from "react";
export function useFeatureTracking(feature: string) {
return useCallback(
(action: string, properties?: Record<string, unknown>) =>
track("feature_used", { feature, action, ...properties }),
[feature]
);
}export function ExportButton() {
const trackExport = useFeatureTracking("export_data");
async function handleExport() {
trackExport("started", { format: "csv" });
try {
await exportData();
trackExport("completed", { format: "csv" });
} catch {
trackExport("failed", { format: "csv" });
}
}
return <button onClick={handleExport}>Export</button>;
}What it sends
Compare started with completed to see how often a feature finishes. To report the error itself, call captureException(error) in the catch.
Related
How is this guide?