Add EthicalMetrics privacy-preserving analytics integration - #112
Conversation
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
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (9)
📝 WalkthroughWalkthroughAdds EthicalMetrics pageview collection with DNT handling, normalized aggregation, Supabase persistence, public metadata and metrics endpoints, browser instrumentation, and a realtime homepage chart. ChangesEthicalMetrics pageview flow
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
Possibly related PRs
Suggested labels: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 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]++ |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 👍 / 👎.
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
Style