Skip to content

Set Posthog Cookie on site domain, not mit.edu - #3680

Open
ChristopherChudzicki wants to merge 2 commits into
mainfrom
cc/posthog-cookie
Open

Set Posthog Cookie on site domain, not mit.edu#3680
ChristopherChudzicki wants to merge 2 commits into
mainfrom
cc/posthog-cookie

Conversation

@ChristopherChudzicki

@ChristopherChudzicki ChristopherChudzicki commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

What are the relevant tickets?

For

Description (What does it do?)

Set the posthog cookie on site domain (open.odl.local, or learn.mit.edu, or rc.learn.mit.edu) not MIT domain.

How can this be tested?

  1. With Posthog integrated locally, you should see a ph_PROJECT_TOKEN_posthog cookie set on your site domain exactly:
    • if site domain is open.odl.local, it should be set there, not on odl.local
    • if site domain is learn.mit.dev, it should be set there, not on mit.dev

Additional 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: false since 2023: https://github.com/mitodl/mitxonline/blob/80c2a512f1e3d2a93c06bb4270ba87976cf369ef/frontend/public/src/lib/util.js#L44

@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown

OpenAPI Changes

No changes detected

View full changelog

Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

@ChristopherChudzicki ChristopherChudzicki added the Needs Review An open Pull Request that is ready for review label Jul 25, 2026
@ChristopherChudzicki
ChristopherChudzicki marked this pull request as ready for review July 25, 2026 00:11
Copilot AI review requested due to automatic review settings July 25, 2026 00:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: false during posthog.init.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@gumaerc gumaerc self-assigned this Jul 27, 2026

@daniellefrappier18 daniellefrappier18 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// 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: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gumaerc gumaerc removed their assignment Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review An open Pull Request that is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants