Skip to content

Commit 6bd5eb9

Browse files
andrewm4894claude
andcommitted
Fix PostHog frontend analytics integration
- Separate POSTHOG_FRONTEND_API_KEY from POSTHOG_API_KEY for metrics ingestion - Update dashboard to use proper PostHog script loading logic - Add PostHog frontend key to demo profile - Document both PostHog variables in .example.env 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 34e00fd commit 6bd5eb9

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

.example.env

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@ ANOMSTACK_CLICKHOUSE_DATABASE=default
154154
# dashbooard port
155155
ANOMSTACK_DASHBOARD_PORT = 5001
156156

157-
# PostHog API key for analytics
157+
# PostHog API key for metrics ingestion (querying PostHog's API for data)
158158
POSTHOG_API_KEY=
159159

160+
# PostHog frontend API key for analytics tracking (website analytics)
161+
POSTHOG_FRONTEND_API_KEY=
162+
160163
# example to enable some jobs via env vars
161164
# ANOMSTACK__PYTHON_INGEST_SIMPLE__INGEST_DEFAULT_SCHEDULE_STATUS=RUNNING
162165
# ANOMSTACK__PYTHON_INGEST_SIMPLE__TRAIN_DEFAULT_SCHEDULE_STATUS=RUNNING

dashboard/app.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ def load_env_with_custom_path():
4545

4646
log = logging.getLogger("anomstack_dashboard")
4747

48-
# Get PostHog API key from environment
49-
posthog_api_key = os.getenv("POSTHOG_API_KEY")
48+
# Get PostHog frontend API key for analytics tracking (separate from POSTHOG_API_KEY used for metrics ingestion)
49+
posthog_api_key = os.getenv("POSTHOG_FRONTEND_API_KEY")
50+
posthog_script = None
5051
if posthog_api_key:
5152
from dashboard.constants import POSTHOG_SCRIPT
52-
53-
POSTHOG_SCRIPT = POSTHOG_SCRIPT.replace("window.POSTHOG_API_KEY || ''", f"'{posthog_api_key}'")
53+
posthog_script = POSTHOG_SCRIPT.replace("window.POSTHOG_API_KEY || ''", f"'{posthog_api_key}'")
5454

5555
# Define the app
5656
app, rt = fast_app(
5757
hdrs=(
5858
Theme.blue.headers(),
5959
Script(src="https://cdn.plot.ly/plotly-2.32.0.min.js"),
60-
Script(POSTHOG_SCRIPT) if posthog_api_key else None,
60+
Script(posthog_script) if posthog_script else None,
6161
Link(
6262
rel="icon",
6363
type="image/svg+xml",

profiles/demo.env

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ ANOMSTACK__EIRGRID__CHANGE_DEFAULT_SCHEDULE_STATUS=RUNNING
100100
ANOMSTACK__EIRGRID__DELETE_DEFAULT_SCHEDULE_STATUS=RUNNING
101101
ANOMSTACK__EIRGRID__LLMALERT_DEFAULT_SCHEDULE_STATUS=STOPPED
102102

103-
# Enable PostHog
103+
# PostHog frontend analytics tracking
104+
POSTHOG_FRONTEND_API_KEY=phc_TudOaC1O5X0Ycl3GtIR0A2cjREW6B6Zp3xDd6c8qxUM
105+
106+
# Enable PostHog metrics ingestion
104107
ANOMSTACK__POSTHOG__INGEST_DEFAULT_SCHEDULE_STATUS=RUNNING
105108
ANOMSTACK__POSTHOG__TRAIN_DEFAULT_SCHEDULE_STATUS=RUNNING
106109
ANOMSTACK__POSTHOG__SCORE_DEFAULT_SCHEDULE_STATUS=RUNNING

0 commit comments

Comments
 (0)