charlotte-ruby / impressionist

Rails Plugin that tracks impressions and page views
MIT License
1.53k stars 311 forks source link

Userid is coming as 0, 1, 2 etc #304

Open brgcy opened 2 years ago

brgcy commented 2 years ago

Hi Folks,

Thanks for creating this wonderful gem. I am trying to use this gem and almost all my needs are working well. However, I noticed that the user_id is coming as nil, 0, 1, 2, 3.... etc

See below:

> Impression.last
  Impression Load (1.6ms)  SELECT  "impressions".* FROM "impressions" ORDER BY 
"impressions"."id" DESC LIMIT $1 /*application:Foo*/  [["LIMIT", 1]]
=> #<Impression id: 2256, impressionable_type: "EditablePage", impressionable_id: 39, 
user_id: 5, controller_name: "blog_posts", action_name: "show", view_name: nil, 
request_hash: "fdcb03fdfd...", ip_address: "1xx.xx.xx.76", session_hash: "293e851aec2260bec0b556cf68080e04", 
message: "Getting foo blog post", referrer: "https://example.com/blog/?page=1", 
params: {"slug"=>"foo"}, created_at: "2022-04-07 11:49:33", updated_at: "2022-04-07 11:49:33">

How I am adding

def show
  @blog_post = BlogPost.find_by(slug: params[:slug])
  impressionist(@blog_post, "Hitting #{@blog_post.title}.")
  ...
end

Anything I am missing here?

After changing the migration to create ImpressionTable, I am getting following error:

PG::InvalidTextRepresentation: ERROR: invalid input syntax for type uuid: "0" : 
INSERT INTO "impressions" ("impressionable_type", "impressionable_id", "controller_name", 
"action_name", "request_hash", "ip_address", "session_hash", "message", "params", 
"created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) 
RETURNING "id" /*application:Foo,controller:blog_posts,action:show*/
chpahlit commented 1 year ago

Hey dont know if this is still helpful, as it seems for me you are working with uuids as primary ids. I just changed in the migration table the user_id and the impressionable_id to strings like:

t.string :impressionable_id t.string :user_id

that worked for me