Separa heatmap mobile/desktop, opt-out analytics per operatori, dashboard costi con KPI e trend mensili. Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
959 B
Ruby
34 lines
959 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Analytics
|
|
class SnapshotsController < ActionController::API
|
|
include ActionController::Cookies
|
|
|
|
def create
|
|
if analytics_suppressed?
|
|
return render json: { ok: true, skipped: true, suppressed: true }, status: :accepted
|
|
end
|
|
|
|
result = Analytics::SnapshotIngest.new(
|
|
path: params[:path] || params[:page_path],
|
|
device: params[:device],
|
|
width: params[:width],
|
|
height: params[:height],
|
|
image: params[:image],
|
|
remote_ip: request.remote_ip
|
|
).call
|
|
|
|
return head :too_many_requests if result.rate_limited
|
|
return render json: { ok: false, error: result.error }, status: :unprocessable_content unless result.ok
|
|
|
|
render json: { ok: true, skipped: result.skipped }, status: :accepted
|
|
end
|
|
|
|
private
|
|
|
|
def analytics_suppressed?
|
|
Analytics::Suppress.active?(cookies[Analytics::Suppress::COOKIE_NAME])
|
|
end
|
|
end
|
|
end
|