chore: uses proper naming for vars and functions
This commit is contained in:
parent
dffe9f5098
commit
667415997e
4 changed files with 27 additions and 27 deletions
|
|
@ -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).
|
||||
|
|
|
|||
11
servers/nextjs/app/api/telemetry-status/route.ts
Normal file
11
servers/nextjs/app/api/telemetry-status/route.ts
Normal file
|
|
@ -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 });
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -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 });
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ export type MixpanelProps = Record<string, unknown>;
|
|||
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<boolean> | null = null;
|
||||
|
||||
async function ensureTrackingStatus(): Promise<boolean> {
|
||||
async function ensureTelemetryStatus(): Promise<boolean> {
|
||||
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<boolean> {
|
|||
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<string, unknown>): 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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue