Skip to content

Add EthicalMetrics privacy-preserving analytics integration - #112

Merged
livrasand merged 1 commit into
mainfrom
Add-EthicalMetrics-privacy-preserving-analytics-integration
Jul 28, 2026
Merged

Add EthicalMetrics privacy-preserving analytics integration#112
livrasand merged 1 commit into
mainfrom
Add-EthicalMetrics-privacy-preserving-analytics-integration

Conversation

@livrasand

@livrasand livrasand commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Integrate EthicalMetrics for privacy-preserving pageview tracking with aggregated minute-level buckets. Add database schema for ethicalmetrics_pageviews table with atomic increment function. Implement HTTP handlers for pageview ingestion, metrics retrieval, privacy manifest, and version endpoints. Add client-side tracking script that respects DNT headers and normalizes browser/OS/device categories. Display real-time pageview chart on homepage with Switzerland data

Summary by CodeRabbit

  • New Features

    • Added privacy-focused pageview measurement with configurable site tracking.
    • Added realtime pageview charts to the home page.
    • Added metrics, privacy, manifest, and version endpoints.
    • Tracking respects Do Not Track settings and avoids collecting data when enabled.
    • Added pageview tracking to repository pages.
  • Style

    • Refined muted text styling and updated scraping notice wording.

Integrate EthicalMetrics for privacy-preserving pageview tracking with aggregated minute-level buckets. Add database schema for ethicalmetrics_pageviews table with atomic increment function. Implement HTTP handlers for pageview ingestion, metrics retrieval, privacy manifest, and version endpoints. Add client-side tracking script that respects DNT headers and normalizes browser/OS/device categories. Display real-time pageview chart on homepage with Switzerland data
@livrasand livrasand self-assigned this Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8cce4fee-78a5-4a24-9866-4ffabd28800c

📥 Commits

Reviewing files that changed from the base of the PR and between d96fd30 and 203a30c.

⛔ Files ignored due to path filters (2)
  • ethicalmetrics/go.sum is excluded by !**/*.sum
  • web/assets/images/surich.svg is excluded by !**/*.svg
📒 Files selected for processing (9)
  • .gitignore
  • database/schema.sql
  • internal/database/supabase.go
  • internal/http/ethicalmetrics.go
  • internal/http/ethicalmetrics_test.go
  • internal/http/router.go
  • web/ethicalmetrics.js
  • web/index.html
  • web/repo.html

📝 Walkthrough

Walkthrough

Adds EthicalMetrics pageview collection with DNT handling, normalized aggregation, Supabase persistence, public metadata and metrics endpoints, browser instrumentation, and a realtime homepage chart.

Changes

EthicalMetrics pageview flow

Layer / File(s) Summary
Pageview persistence and Supabase access
database/schema.sql, internal/database/supabase.go, .gitignore
Adds the aggregated pageview table, atomic increment RPC, Supabase client methods and HTTP helpers, plus local environment ignore rules.
Pageview ingestion and reporting handlers
internal/http/ethicalmetrics.go, internal/http/ethicalmetrics_test.go
Adds normalized, in-memory pageview aggregation, DNT handling, optional persistence, metrics retrieval, privacy metadata responses, and handler tests.
HTTP routes and browser collection
internal/http/router.go, web/ethicalmetrics.js, web/repo.html
Registers EthicalMetrics routes and serves browser scripts that collect page context while honoring do-not-track settings.
Realtime metrics presentation
web/index.html
Adds the homepage pageviews chart, metrics loading and fallback rendering, privacy messaging, and muted text styling updates.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant EthicalMetricsPageviewHandler
  participant SupabaseClient
  participant increment_pageviews
  participant MetricsHandler
  participant HomepageChart
  Browser->>EthicalMetricsPageviewHandler: POST pageview dimensions
  EthicalMetricsPageviewHandler->>SupabaseClient: Upsert normalized bucket
  SupabaseClient->>increment_pageviews: Increment stored count
  HomepageChart->>MetricsHandler: GET site metrics
  MetricsHandler->>SupabaseClient: Get bucket counts
  SupabaseClient-->>MetricsHandler: Return aggregated metrics
  MetricsHandler-->>HomepageChart: Return bucket map
Loading

Possibly related PRs

Suggested labels: enhancement

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch Add-EthicalMetrics-privacy-preserving-analytics-integration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@livrasand
livrasand merged commit 3b62274 into main Jul 28, 2026
3 of 4 checks passed
@livrasand
livrasand deleted the Add-EthicalMetrics-privacy-preserving-analytics-integration branch July 28, 2026 19:52

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 203a30cb7b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if ethicalStore.buckets[input.SiteKey] == nil {
ethicalStore.buckets[input.SiteKey] = make(map[string]int64)
}
ethicalStore.buckets[input.SiteKey][key]++

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Cap the in-memory pageview cache

Every accepted pageview is inserted into the process-wide ethicalStore, even when Supabase is configured, and the key includes caller-controlled site_key/path plus a new minute bucket. On a long-running deployment or from clients sending many distinct paths/site keys, this map grows without eviction and can steadily consume memory; consider bounding/pruning it or only using it when persistence is unavailable.

Useful? React with 👍 / 👎.


func (c *SupabaseClient) GetEthicalPageviews(ctx context.Context, siteKey string) (map[string]int64, error) {
var rows []EthicalPageviewRecord
if err := c.getJSON(ctx, fmt.Sprintf("/rest/v1/ethicalmetrics_pageviews?site_key=eq.%s&select=bucket,pageviews", url.QueryEscape(siteKey)), &rows); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Limit the metrics query to recent buckets

This query fetches every persisted minute bucket for a site, while the homepage chart later only displays the last 36 entries. Once the site has accumulated weeks or months of minute-level rows, each metrics request will scan, allocate, and return the full history before the browser discards almost all of it; add ordering/range filtering or a server-side limit for the recent window.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants