diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 60f6be495..9351e8ad2 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -58,7 +58,6 @@ //= require ckeditor/loader //= require_directory ./ckeditor //= require social-share-button -//= require ahoy //= require app //= require check_all_none //= require comments diff --git a/config/initializers/ahoy.rb b/config/initializers/ahoy.rb index b4e8817ec..3879d14b0 100644 --- a/config/initializers/ahoy.rb +++ b/config/initializers/ahoy.rb @@ -1,5 +1,3 @@ -Ahoy.api = true -Ahoy.server_side_visits = :when_needed Ahoy.mask_ips = true Ahoy.cookies = :none diff --git a/db/migrate/20241026112901_add_tokens_to_visits.rb b/db/migrate/20241026112901_add_tokens_to_visits.rb new file mode 100644 index 000000000..c519cd24a --- /dev/null +++ b/db/migrate/20241026112901_add_tokens_to_visits.rb @@ -0,0 +1,11 @@ +class AddTokensToVisits < ActiveRecord::Migration[7.0] + def change + change_table :visits do |t| + t.string :visit_token + t.string :visitor_token + end + + add_index :visits, :visit_token, unique: true + add_index :visits, [:visitor_token, :started_at] + end +end diff --git a/db/schema.rb b/db/schema.rb index dc9ee1997..2ddb1065a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_10_26_111636) do +ActiveRecord::Schema[7.0].define(version: 2024_10_26_112901) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" enable_extension "plpgsql" @@ -1703,9 +1703,13 @@ ActiveRecord::Schema[7.0].define(version: 2024_10_26_111636) do t.string "utm_content" t.string "utm_campaign" t.datetime "started_at", precision: nil + t.string "visit_token" + t.string "visitor_token" t.index ["started_at"], name: "index_visits_on_started_at" t.index ["user_id"], name: "index_visits_on_user_id" + t.index ["visit_token"], name: "index_visits_on_visit_token", unique: true t.index ["visitor_id", "started_at"], name: "index_visits_on_visitor_id_and_started_at" + t.index ["visitor_token", "started_at"], name: "index_visits_on_visitor_token_and_started_at" end create_table "votation_types", force: :cascade do |t| diff --git a/spec/system/admin/stats_spec.rb b/spec/system/admin/stats_spec.rb index 2ea281266..b93d18996 100644 --- a/spec/system/admin/stats_spec.rb +++ b/spec/system/admin/stats_spec.rb @@ -13,7 +13,32 @@ describe "Stats", :admin do expect(page).to have_content "DEBATES\n1" expect(page).to have_content "PROPOSALS\n2" expect(page).to have_content "COMMENTS\n3" - expect(page).to have_content "VISITS\n4" + expect(page).to have_content "VISITS\n5" + end + + scenario "Visits" do + visit admin_stats_path + refresh + + expect(page).to have_content "VISITS\n1" + + allow_any_instance_of(ActionDispatch::Request).to receive(:user_agent).and_return("Different") + + in_browser(:different) do + visit root_path + + click_link "Debates" + expect(page).to have_link "Start a debate" + + click_link "Proposals" + expect(page).to have_link "Create a proposal" + end + + allow_any_instance_of(ActionDispatch::Request).to receive(:user_agent).and_call_original + + refresh + + expect(page).to have_content "VISITS\n2" end scenario "Votes" do