Aggiunge heatmaps first-party (click/scroll) con pagina admin Analytics.

Raccoglie eventi aggregati dietro consenso cookie, senza PII né tracking su admin/regia/live/replay; GA4 resta invariato.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-20 22:50:15 +02:00
co-authored by Cursor
parent cc96c0396a
commit 8a07c5d569
36 changed files with 1247 additions and 14 deletions
@@ -0,0 +1,59 @@
# frozen_string_literal: true
require "rails_helper"
RSpec.describe "Analytics ingest", type: :request do
it "accetta eventi validi, normalizza il path e aggrega" do
post "/analytics/events",
params: {
events: [
{
type: "pageview",
path: "/clubs/461d369a-104c-4d3c-8860-1518b4e95d35",
device: "desktop",
ts: Time.current.to_i * 1000
},
{
type: "click",
path: "/clubs/461d369a-104c-4d3c-8860-1518b4e95d35",
device: "desktop",
x: 25,
y: 50,
ts: Time.current.to_i * 1000
},
{
type: "scroll",
path: "/clubs/461d369a-104c-4d3c-8860-1518b4e95d35",
device: "desktop",
scroll: 80,
ts: Time.current.to_i * 1000
}
]
},
as: :json
expect(response).to have_http_status(:accepted)
body = JSON.parse(response.body)
expect(body["accepted"]).to eq(3)
expect(AnalyticsEvent.count).to eq(0)
expect(AnalyticsPageStat.find_by(page_path: "/clubs/:id").pageview_count).to eq(1)
expect(AnalyticsPageStat.find_by(page_path: "/clubs/:id").max_scroll_pct).to eq(80)
expect(AnalyticsPageCell.where(page_path: "/clubs/:id").sum(:click_count)).to eq(1)
end
it "rifiuta path esclusi" do
post "/analytics/events",
params: {
events: [
{ type: "pageview", path: "/admin/ops", device: "desktop", ts: Time.current.to_i * 1000 },
{ type: "pageview", path: "/live/461d369a-104c-4d3c-8860-1518b4e95d35", device: "mobile", ts: Time.current.to_i * 1000 }
]
},
as: :json
expect(response).to have_http_status(:accepted)
expect(JSON.parse(response.body)["accepted"]).to eq(0)
expect(AnalyticsEvent.count).to eq(0)
end
end