Skip to content

Commit f2bb185

Browse files
Merge pull request #231 from stuartmaxwell:posthog
Install PostHog for analytics integration
2 parents 8e2486e + 642bcb1 commit f2bb185

File tree

3 files changed

+98
-55
lines changed

3 files changed

+98
-55
lines changed

config/settings.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
import environ
66
import logfire
7+
import posthog
78
import sentry_sdk
89
from django.contrib.messages import constants as messages
10+
from posthog import Posthog
11+
from posthog.exception_capture import Integrations
912
from sentry_sdk.integrations.django import DjangoIntegration
1013

1114
BASE_DIR = Path(__file__).resolve().parent.parent
@@ -47,6 +50,8 @@
4750
AWS_STORAGE_BUCKET_NAME=(str, ""),
4851
AWS_ENDPOINT_URL=(str, ""),
4952
S3_BUCKET=(str, ""),
53+
POSTHOG_PROJECT_API_KEY=(str, ""),
54+
POSTHOG_HOST=(str, "https://us.i.posthog.com"),
5055
)
5156

5257
environ.Env.read_env(Path(BASE_DIR / ".env"))
@@ -387,3 +392,16 @@
387392
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
388393
},
389394
}
395+
396+
# PostHog
397+
POSTHOG_PROJECT_API_KEY = str(env("POSTHOG_PROJECT_API_KEY"))
398+
POSTHOG_HOST = str(env("POSTHOG_HOST"))
399+
if POSTHOG_PROJECT_API_KEY and POSTHOG_HOST:
400+
posthog.project_api_key = POSTHOG_PROJECT_API_KEY
401+
posthog.host = POSTHOG_HOST
402+
Posthog(
403+
api_key=POSTHOG_PROJECT_API_KEY,
404+
host=POSTHOG_HOST,
405+
enable_exception_autocapture=True,
406+
exception_autocapture_integrations=[Integrations.Django],
407+
)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies = [
2424
"logfire[asgi,django]>=2.5.0",
2525
"djpress-publish-bluesky>=1.0.0",
2626
"django-storages[s3]>=1.14.6",
27+
"posthog>=4.4.0",
2728
]
2829

2930
[tool.curlylint.rules]

0 commit comments

Comments
 (0)