Set Posthog Cookie on site domain, not mit.edu - #3680
Set Posthog Cookie on site domain, not mit.edu#3680ChristopherChudzicki wants to merge 2 commits into
Conversation
OpenAPI ChangesNo changes detected Unexpected changes? Ensure your branch is up-to-date with |
There was a problem hiding this comment.
Pull request overview
Updates the PostHog client initialization in the Next.js frontend so analytics cookies are scoped to the current site domain (e.g., learn.mit.edu, rc.learn.mit.edu, open.odl.local) instead of being shared across subdomains via the parent domain.
Changes:
- Disable PostHog cross-subdomain cookies by setting
cross_subdomain_cookie: falseduringposthog.init.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
| // defaults this to true, which sets the cookie on the root domain | ||
| // (e.g. mit.edu), sharing it with every other site there. | ||
| cross_subdomain_cookie: false, | ||
| bootstrap: { |
There was a problem hiding this comment.
We may also need this change in https://github.com/mitodl/ocw-hugo-themes/blob/f88bfc52184d19a7f366b65f225750602ccef6a5/base-theme/assets/js/posthog.ts#L18-L28, perhaps just scoped to the v3 theme? The v3 theme pages are served at urls like https://learn.mit.edu/courses/o/21h-151-dynastic-china-fall-2024/ Currently, they are "gated" behind the ocw-product-pages flag.
What are the relevant tickets?
For
Description (What does it do?)
Set the posthog cookie on site domain (
open.odl.local, orlearn.mit.edu, orrc.learn.mit.edu) not MIT domain.How can this be tested?
ph_PROJECT_TOKEN_posthogcookie set on your site domain exactly:open.odl.local, it should be set there, not onodl.locallearn.mit.dev, it should be set there, not onmit.devAdditional Context
Setting the cookie on the site domain loses our ability to track anonymous (unauthenticated) users across sites within the same project, unless we do special setup like pass distinct_ids via query params in URLs, but that is deemed acceptable.
Companion PR, same change for the Keycloak login pages: mitodl/ol-keycloakify#176
mitxonline already does this — it has passed
cross_subdomain_cookie: falsesince 2023: https://github.com/mitodl/mitxonline/blob/80c2a512f1e3d2a93c06bb4270ba87976cf369ef/frontend/public/src/lib/util.js#L44