matrix-terminal-posthog-cv/app/analytics.py
2026-08-11 15:20:33 +01:00

19 lines
570 B
Python

import atexit
from posthog import Posthog
from app.config import POSTHOG_API_KEY, POSTHOG_HOST
client = Posthog(project_api_key=POSTHOG_API_KEY, host=POSTHOG_HOST) if POSTHOG_API_KEY else None
if client:
atexit.register(client.shutdown)
def capture(distinct_id: str | None, event: str, properties: dict | None = None) -> None:
"""
No-ops when PostHog isn't configured or there's no session to attribute the event to.
"""
if not client or not distinct_id:
return
client.capture(event, distinct_id=distinct_id, properties=properties)