Merge pull request #5760 from consuldemocracy/ahoy_visits_server_side
Track ahoy visits on the server side
This commit is contained in:
@@ -58,7 +58,6 @@
|
|||||||
//= require ckeditor/loader
|
//= require ckeditor/loader
|
||||||
//= require_directory ./ckeditor
|
//= require_directory ./ckeditor
|
||||||
//= require social-share-button
|
//= require social-share-button
|
||||||
//= require ahoy
|
|
||||||
//= require app
|
//= require app
|
||||||
//= require check_all_none
|
//= require check_all_none
|
||||||
//= require comments
|
//= require comments
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
Ahoy.api = true
|
|
||||||
Ahoy.server_side_visits = :when_needed
|
|
||||||
Ahoy.mask_ips = true
|
Ahoy.mask_ips = true
|
||||||
Ahoy.cookies = :none
|
Ahoy.cookies = :none
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class RemoveSearchKeywordFromVisits < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
remove_column :visits, :search_keyword, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
11
db/migrate/20241026112901_add_tokens_to_visits.rb
Normal file
11
db/migrate/20241026112901_add_tokens_to_visits.rb
Normal file
@@ -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
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.0].define(version: 2024_05_13_135357) 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pg_trgm"
|
enable_extension "pg_trgm"
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -1686,7 +1686,6 @@ ActiveRecord::Schema[7.0].define(version: 2024_05_13_135357) do
|
|||||||
t.text "landing_page"
|
t.text "landing_page"
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
t.string "referring_domain"
|
t.string "referring_domain"
|
||||||
t.string "search_keyword"
|
|
||||||
t.string "browser"
|
t.string "browser"
|
||||||
t.string "os"
|
t.string "os"
|
||||||
t.string "device_type"
|
t.string "device_type"
|
||||||
@@ -1704,9 +1703,13 @@ ActiveRecord::Schema[7.0].define(version: 2024_05_13_135357) do
|
|||||||
t.string "utm_content"
|
t.string "utm_content"
|
||||||
t.string "utm_campaign"
|
t.string "utm_campaign"
|
||||||
t.datetime "started_at", precision: nil
|
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 ["started_at"], name: "index_visits_on_started_at"
|
||||||
t.index ["user_id"], name: "index_visits_on_user_id"
|
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_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
|
end
|
||||||
|
|
||||||
create_table "votation_types", force: :cascade do |t|
|
create_table "votation_types", force: :cascade do |t|
|
||||||
|
|||||||
@@ -13,7 +13,32 @@ describe "Stats", :admin do
|
|||||||
expect(page).to have_content "DEBATES\n1"
|
expect(page).to have_content "DEBATES\n1"
|
||||||
expect(page).to have_content "PROPOSALS\n2"
|
expect(page).to have_content "PROPOSALS\n2"
|
||||||
expect(page).to have_content "COMMENTS\n3"
|
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
|
end
|
||||||
|
|
||||||
scenario "Votes" do
|
scenario "Votes" do
|
||||||
|
|||||||
Reference in New Issue
Block a user