We can add support for cookies in the page tracking middleware, update the pageview model and also the analytics controller so we can leverage the new data.
class AddCookieValueToPageViews < ActiveRecord::Migration[7.1]
def change
add_column :page_views, :cookie_value, :string
add_index :page_views, :cookie_value
end
end
class PageView < ApplicationRecord
belongs_to :user
validates :cookie_value, presence: true
# Optionally, if you want to enforce uniqueness:
# validates :cookie_value, uniqueness: { scope: [:user_id, :path] }
end
We can add support for cookies in the page tracking middleware, update the pageview model and also the analytics controller so we can leverage the new data.
rails generate migration AddCookieValueToPageViews cookie_value:string