@@ -14,6 +14,11 @@ import { useEffect } from "react";
1414// - Clears identities on user sign-out (see utils/telemetry/resetTelemetry).
1515// - Keeps PostHog React context so existing `usePostHog()` calls continue to work.
1616
17+ // Reject empty values and `.env.example` placeholders (e.g. `<Your PostHog API key from ...>`),
18+ // which would otherwise cause 401/CORS console floods on init.
19+ const isConfigured = ( value : string | undefined ) : value is string =>
20+ ! ! value && ! value . startsWith ( "<" ) ;
21+
1722let gleapSingleton : any | null = null ;
1823
1924export function TelemetryProvider ( { children } : { children : React . ReactNode } ) {
@@ -22,7 +27,7 @@ export function TelemetryProvider({ children }: { children: React.ReactNode }) {
2227
2328 // Initialize SDKs once
2429 useEffect ( ( ) => {
25- if ( env . NEXT_PUBLIC_POSTHOG_KEY ) {
30+ if ( isConfigured ( env . NEXT_PUBLIC_POSTHOG_KEY ) ) {
2631 try {
2732 posthog . init ( env . NEXT_PUBLIC_POSTHOG_KEY , {
2833 api_host : env . NEXT_PUBLIC_POSTHOG_HOST ,
@@ -33,11 +38,9 @@ export function TelemetryProvider({ children }: { children: React.ReactNode }) {
3338 } catch ( e ) {
3439 console . warn ( "PostHog init failed" , e ) ;
3540 }
36- } else {
37- console . warn ( "PostHog key is not set, skipping initialization" ) ;
3841 }
3942
40- if ( env . NEXT_PUBLIC_GLEAP_API_KEY ) {
43+ if ( isConfigured ( env . NEXT_PUBLIC_GLEAP_API_KEY ) ) {
4144 ( async ( ) => {
4245 try {
4346 // Dynamic import to avoid hard dependency when not installed
@@ -82,7 +85,7 @@ export function TelemetryProvider({ children }: { children: React.ReactNode }) {
8285 console . error ( "PostHog identify/reset error:" , e ) ;
8386 }
8487
85- if ( ! env . NEXT_PUBLIC_GLEAP_API_KEY ) return ;
88+ if ( ! isConfigured ( env . NEXT_PUBLIC_GLEAP_API_KEY ) ) return ;
8689 ( async ( ) => {
8790 try {
8891 const Gleap = gleapSingleton ?? ( await import ( "gleap" ) ) . default ;
@@ -111,7 +114,7 @@ export function TelemetryProvider({ children }: { children: React.ReactNode }) {
111114
112115 // Soft re-initialize Gleap on path changes to guard against soft reloads/HMR
113116 useEffect ( ( ) => {
114- if ( ! env . NEXT_PUBLIC_GLEAP_API_KEY ) return ;
117+ if ( ! isConfigured ( env . NEXT_PUBLIC_GLEAP_API_KEY ) ) return ;
115118 ( async ( ) => {
116119 try {
117120 const Gleap = gleapSingleton ?? ( await import ( "gleap" ) ) . default ;
0 commit comments