mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
The version sweep resolved @hanzo/insights to 1.358.1, which exports its client as `insights` and as the default, and no longer as `posthog`. The analytics hook imported `posthog`, so the binding was undefined — a link error for the ESM build, and a TypeError on the first capture wherever the module did load. The hook imports `insights`. use-analytics.test.ts sets an Insights key, records what reaches the client and checks an event and an error both get there, and that nothing does without a key; against the old import the first case fails on the undefined client. turbo.json still declared the key under its pre-rename name, NEXT_PUBLIC_POSTHOG_KEY, which nothing reads; it declares NEXT_PUBLIC_INSIGHTS_KEY, which the feature flags read and the test sets. Co-authored-by: Hanzo Dev <[email protected]>
75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
import { insights } from '@hanzo/insights';
|
|
|
|
import { extractInsightsConfig } from '@hanzo/esign-lib/constants/feature-flags';
|
|
|
|
export function useAnalytics() {
|
|
// const featureFlags = useFeatureFlags();
|
|
const isInsightsEnabled = extractInsightsConfig();
|
|
|
|
/**
|
|
* Capture an analytic event.
|
|
*
|
|
* @param event The event name.
|
|
* @param properties Properties to attach to the event.
|
|
*/
|
|
const capture = (event: string, properties?: Record<string, unknown>) => {
|
|
if (!isInsightsEnabled) {
|
|
return;
|
|
}
|
|
|
|
insights.capture(event, properties);
|
|
};
|
|
|
|
/**
|
|
* Capture an analytic event.
|
|
*
|
|
* @param error The error to capture.
|
|
* @param properties Properties to attach to the event.
|
|
*/
|
|
const captureException = (error: Error, properties?: Record<string, unknown>) => {
|
|
if (!isInsightsEnabled) {
|
|
return;
|
|
}
|
|
|
|
insights.captureException(error, properties);
|
|
};
|
|
|
|
/**
|
|
* Start the session recording.
|
|
*
|
|
* @param eventFlag The event to check against feature flags to determine whether tracking is enabled.
|
|
*/
|
|
const startSessionRecording = (eventFlag?: string) => {
|
|
return;
|
|
// const isSessionRecordingEnabled = featureFlags.getFlag(FEATURE_FLAG_GLOBAL_SESSION_RECORDING);
|
|
// const isSessionRecordingEnabledForEvent = Boolean(eventFlag && featureFlags.getFlag(eventFlag));
|
|
|
|
// if (!isInsightsEnabled || !isSessionRecordingEnabled || !isSessionRecordingEnabledForEvent) {
|
|
// return;
|
|
// }
|
|
|
|
// insights.startSessionRecording();
|
|
};
|
|
|
|
/**
|
|
* Stop the current session recording.
|
|
*/
|
|
const stopSessionRecording = () => {
|
|
return;
|
|
// const isSessionRecordingEnabled = featureFlags.getFlag(FEATURE_FLAG_GLOBAL_SESSION_RECORDING);
|
|
|
|
// if (!isInsightsEnabled || !isSessionRecordingEnabled) {
|
|
// return;
|
|
// }
|
|
|
|
// insights.stopSessionRecording();
|
|
};
|
|
|
|
return {
|
|
capture,
|
|
captureException,
|
|
startSessionRecording,
|
|
stopSessionRecording,
|
|
};
|
|
}
|