|
1 | | -import posthog from "posthog-js" |
| 1 | +import posthog from "posthog-js"; |
2 | 2 |
|
3 | | -posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, { |
4 | | - api_host: "/ingest", |
5 | | - ui_host: "https://us.posthog.com", |
6 | | - defaults: "2025-05-24", |
7 | | - capture_exceptions: true, // This enables capturing exceptions using Error Tracking |
8 | | - session_recording: { |
9 | | - // Prevent large base64 images from being serialized into recordings |
10 | | - blockClass: "ph-no-capture", |
11 | | - blockSelector: ".ph-no-capture", |
12 | | - }, |
13 | | - debug: process.env.NODE_ENV === "development", |
14 | | -}); |
| 3 | +const posthogKey = process.env["NEXT_PUBLIC_POSTHOG_KEY"]; |
| 4 | + |
| 5 | +if (posthogKey) { |
| 6 | + posthog.init(posthogKey, { |
| 7 | + api_host: "/ingest", |
| 8 | + ui_host: "https://us.posthog.com", |
| 9 | + defaults: "2025-05-24", |
| 10 | + capture_exceptions: true, // This enables capturing exceptions using Error Tracking |
| 11 | + session_recording: { |
| 12 | + // Prevent large base64 images from being serialized into recordings |
| 13 | + blockClass: "ph-no-capture", |
| 14 | + blockSelector: ".ph-no-capture", |
| 15 | + }, |
| 16 | + debug: process.env.NODE_ENV === "development", |
| 17 | + }); |
| 18 | +} else if (process.env.NODE_ENV === "development") { |
| 19 | + console.warn("PostHog: NEXT_PUBLIC_POSTHOG_KEY is not defined"); |
| 20 | +} |
0 commit comments