diff --git a/README.md b/README.md index 8b039980..b82ae3c9 100644 --- a/README.md +++ b/README.md @@ -104,8 +104,8 @@ You can also set the following environment variables to customize the image gene - **GOOGLE_API_KEY=[Your Google API Key]**: Required if using **gemini_flash** as the image provider. - **OPENAI_API_KEY=[Your OpenAI API Key]**: Required if using **dall-e-3** as the image provider. -You can disable anonymous tracking using the following environment variable: -- **DISABLE_ANONYMOUS_TRACKING=[true/false]**: Set this to **true** to disable anonymous usage tracking. +You can disable anonymous telemetry using the following environment variable: +- **DISABLE_ANONYMOUS_TELEMETRY=[true/false]**: Set this to **true** to disable anonymous telemetry. > **Note:** You can freely choose both the LLM (text generation) and the image provider. Supported image providers: **pexels**, **pixabay**, **gemini_flash** (Google), and **dall-e-3** (OpenAI). diff --git a/servers/nextjs/app/api/telemetry-status/route.ts b/servers/nextjs/app/api/telemetry-status/route.ts new file mode 100644 index 00000000..f9f1f880 --- /dev/null +++ b/servers/nextjs/app/api/telemetry-status/route.ts @@ -0,0 +1,11 @@ +import { NextResponse } from 'next/server'; + +export const dynamic = 'force-dynamic'; + +export async function GET() { + const isDisabled = process.env.DISABLE_ANONYMOUS_TELEMETRY === 'true' || process.env.DISABLE_ANONYMOUS_TELEMETRY === 'True'; + const telemetryEnabled = !isDisabled; + return NextResponse.json({ telemetryEnabled }); +} + + diff --git a/servers/nextjs/app/api/tracking-status/route.ts b/servers/nextjs/app/api/tracking-status/route.ts deleted file mode 100644 index 3cc727ff..00000000 --- a/servers/nextjs/app/api/tracking-status/route.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { NextResponse } from 'next/server'; - -export const dynamic = 'force-dynamic'; - -export async function GET() { - const isDisabled = process.env.DISABLE_ANONYMOUS_TRACKING === 'true' || process.env.DISABLE_ANONYMOUS_TRACKING === 'True'; - const trackingEnabled = !isDisabled; - return NextResponse.json({ trackingEnabled }); -} - - diff --git a/servers/nextjs/utils/mixpanel.ts b/servers/nextjs/utils/mixpanel.ts index 3f51de71..7099e3e4 100644 --- a/servers/nextjs/utils/mixpanel.ts +++ b/servers/nextjs/utils/mixpanel.ts @@ -57,7 +57,7 @@ export type MixpanelProps = Record; declare global { interface Window { __mixpanel_initialized?: boolean; - __mixpanel_tracking_enabled?: boolean; + __mixpanel_telemetry_enabled?: boolean; } } @@ -67,28 +67,28 @@ function canUseMixpanel(): boolean { let trackingCheckPromise: Promise | null = null; -async function ensureTrackingStatus(): Promise { +async function ensureTelemetryStatus(): Promise { if (typeof window === 'undefined') return false; - if (typeof window.__mixpanel_tracking_enabled === 'boolean') { - return window.__mixpanel_tracking_enabled; + if (typeof window.__mixpanel_telemetry_enabled === 'boolean') { + return window.__mixpanel_telemetry_enabled; } if (!trackingCheckPromise) { - trackingCheckPromise = fetch('/api/tracking-status') + trackingCheckPromise = fetch('/api/telemetry-status') .then(async (res) => { try { const data = await res.json(); - const enabled = Boolean(data?.trackingEnabled); - window.__mixpanel_tracking_enabled = enabled; + const enabled = Boolean(data?.telemetryEnabled); + window.__mixpanel_telemetry_enabled = enabled; return enabled; } catch { // If the API response is malformed, default to enabling tracking - window.__mixpanel_tracking_enabled = true; + window.__mixpanel_telemetry_enabled = true; return true; } }) .catch(() => { // If the API call fails, default to enabling tracking - window.__mixpanel_tracking_enabled = true; + window.__mixpanel_telemetry_enabled = true; return true; }); } @@ -98,8 +98,8 @@ async function ensureTrackingStatus(): Promise { export function initMixpanel(): void { if (!canUseMixpanel()) return; if (window.__mixpanel_initialized) return; - // Ensure tracking is allowed before initializing - void ensureTrackingStatus().then((enabled) => { + // Ensure telemetry is allowed before initializing + void ensureTelemetryStatus().then((enabled) => { if (!enabled) return; if (window.__mixpanel_initialized) return; mixpanel.init(MIXPANEL_TOKEN as string, { track_pageview: false }); @@ -110,7 +110,7 @@ export function initMixpanel(): void { export function track(eventName: string, props?: Record): void { if (!canUseMixpanel()) return; - if (typeof window !== 'undefined' && window.__mixpanel_tracking_enabled === false) { + if (typeof window !== 'undefined' && window.__mixpanel_telemetry_enabled === false) { return; } if (!window.__mixpanel_initialized) { @@ -126,7 +126,7 @@ export function trackEvent(event: MixpanelEvent, props?: MixpanelProps): void { export function getDistinctId(): string | undefined { if (!canUseMixpanel()) return undefined; - if (typeof window !== 'undefined' && window.__mixpanel_tracking_enabled === false) { + if (typeof window !== 'undefined' && window.__mixpanel_telemetry_enabled === false) { return undefined; } if (!window.__mixpanel_initialized) { @@ -139,7 +139,7 @@ export function getDistinctId(): string | undefined { export function identifyAnonymous(): void { if (!canUseMixpanel()) return; - if (typeof window !== 'undefined' && window.__mixpanel_tracking_enabled === false) { + if (typeof window !== 'undefined' && window.__mixpanel_telemetry_enabled === false) { return; } if (!window.__mixpanel_initialized) {