mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: resolve analytics data gaps and resize validation failures
- Fix resize 20% failure rate: add Zod refine requiring at least one dimension, enforce integer/max constraints, clamp percentage scaling to minimum 1px, and guard against missing metadata in withoutEnlargement - Fix PostHog init race condition: move consent check before async import so frontend events (search, pageview) are no longer silently dropped - Fix identify() passing nested $set/$set_once wrappers instead of flat properties, so version person property now appears on PostHog profiles - Add error_code and error_message to failed tool_used analytics events for debugging tool failures from PostHog
This commit is contained in:
@@ -15,13 +15,10 @@ function scrubString(str: string): string {
|
||||
}
|
||||
|
||||
export async function initAnalytics(config: AnalyticsConfig): Promise<void> {
|
||||
if (initialized || !config.enabled) return;
|
||||
if (initialized || !config.enabled || !consentGranted) return;
|
||||
|
||||
try {
|
||||
const posthogJs = (await import("posthog-js")).default;
|
||||
if (!consentGranted) {
|
||||
return;
|
||||
}
|
||||
posthog =
|
||||
posthogJs.init(config.posthogApiKey, {
|
||||
api_host: config.posthogHost,
|
||||
@@ -45,9 +42,6 @@ export async function initAnalytics(config: AnalyticsConfig): Promise<void> {
|
||||
try {
|
||||
if (config.sentryDsn) {
|
||||
const Sentry = await import("@sentry/react");
|
||||
if (!consentGranted) {
|
||||
return;
|
||||
}
|
||||
Sentry.init({
|
||||
dsn: config.sentryDsn,
|
||||
sendDefaultPii: false,
|
||||
@@ -110,10 +104,14 @@ export function setAnalyticsConsent(enabled: boolean): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function identify(instanceId: string, properties: Record<string, unknown>): void {
|
||||
export function identify(
|
||||
instanceId: string,
|
||||
properties: Record<string, unknown>,
|
||||
propertiesSetOnce?: Record<string, unknown>,
|
||||
): void {
|
||||
if (!posthog || !consentGranted) return;
|
||||
try {
|
||||
posthog.identify(instanceId, properties);
|
||||
posthog.identify(instanceId, properties, propertiesSetOnce);
|
||||
} catch {
|
||||
// never throw
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user