Repository navigation
Add in-house cookieless website analytics - #174
Merged
Merged
Conversation
Store public page views in our own Postgres instead of a third-party analytics service, resolving TDD open question 14. - POST /api/pageviews accepts only allowlisted public paths and a referrer hostname, rate limited per IP and globally - Visitors are an HMAC of IP and user agent under an in-memory salt that rotates at local midnight; no IP, user agent, or cookie is stored - GET /api/admin/analytics/website reports page views, visitors, visits, average time on site, daily views, pages, and sources (sources under the suppression threshold are hidden) - The retention job deletes page views older than 90 days - The public layout renders a beacon when WEBSITE_ANALYTICS_ENABLED=true; it skips /text-us, /portal, /dev, and browsers with GPC or DNT - The admin analytics page shows a Website section in place of the external dashboard link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Peer2Peer wants to know how students find the public site (visitors, sources, time on site) without tracking anyone (TDD 4.6.9). Instead of adding Plausible or Umami, this stores page views in our own Postgres, so there is no third party, no extra service to run or hand off, and no cost. This resolves TDD open question 14.
Changes:
POST /api/pageviews. It accepts only the five public paths (/,/about,/contact,/faq,/resources) and the referring site's hostname, and is rate limited per IP and globally.GET /api/admin/analytics/websitefor coordinators. It returns page views, visitors (once per day), visits (30-minute gap), average time on site, daily page views, page counts, and sources. Sources with fewer than 5 visitors are hidden, matching line analytics.WEBSITE_ANALYTICS_ENABLED=true. It sends nothing on/text-us,/portal,/dev, or any other path, or when the browser has Global Privacy Control or Do Not Track on. Only the first view of a page load sends a referrer./portal/admin/analyticswith a Website section, and removedNEXT_PUBLIC_WEBSITE_ANALYTICS_URL.Notes:
client_ip()still reads the proxy address, the same pending deploy fix the chat and feedback rate limits need.Verified with
make check: 730 backend tests, 370 frontend tests, mypy, tsc, lint, andalembic check.Closes #164