loftwah / linkarooie

Simplify your online presence with a single link.
https://linkarooie.com
MIT License
24 stars 4 forks source link

Implement cookie based tracking #58

Open loftwah opened 2 weeks ago

loftwah commented 2 weeks ago

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

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
loftwah commented 2 weeks ago

ChatGPT that discusses this.