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>
48 lines
1.7 KiB
Ruby
48 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class CreateAnalyticsTables < ActiveRecord::Migration[7.2]
|
|
def change
|
|
create_table :analytics_events, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
|
|
t.string :page_path, null: false
|
|
t.string :device, null: false
|
|
t.string :event_type, null: false
|
|
t.decimal :x_pct, precision: 6, scale: 2
|
|
t.decimal :y_pct, precision: 6, scale: 2
|
|
t.decimal :scroll_pct, precision: 6, scale: 2
|
|
t.datetime :occurred_at, null: false
|
|
t.timestamps
|
|
end
|
|
add_index :analytics_events, :occurred_at
|
|
add_index :analytics_events, %i[event_type occurred_at]
|
|
|
|
create_table :analytics_page_cells, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
|
|
t.date :day, null: false
|
|
t.string :page_path, null: false
|
|
t.string :device, null: false
|
|
t.integer :cell_x, null: false
|
|
t.integer :cell_y, null: false
|
|
t.integer :click_count, null: false, default: 0
|
|
t.timestamps
|
|
end
|
|
add_index :analytics_page_cells,
|
|
%i[day page_path device cell_x cell_y],
|
|
unique: true,
|
|
name: "index_analytics_page_cells_unique"
|
|
|
|
create_table :analytics_page_stats, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
|
|
t.date :day, null: false
|
|
t.string :page_path, null: false
|
|
t.string :device, null: false
|
|
t.integer :pageview_count, null: false, default: 0
|
|
t.integer :scroll_samples, null: false, default: 0
|
|
t.integer :scroll_sum_pct, null: false, default: 0
|
|
t.integer :max_scroll_pct, null: false, default: 0
|
|
t.timestamps
|
|
end
|
|
add_index :analytics_page_stats,
|
|
%i[day page_path device],
|
|
unique: true,
|
|
name: "index_analytics_page_stats_unique"
|
|
end
|
|
end
|