I'm trying to write a query and I cannot find the right result. I have a model like this:
#<Ahoy::Event id: "007d74fb-6225-4cd5-a725-6e35b2e9a859", visit_id: "34713617-d6f6-4adb-b436-8029a7ea586c", user_id: 3, name: "view", properties: {"id"=>14, "delay"=>500, "action"=>"show", "resource"=>"News", "end_point"=>"news"}, time: "2016-02-12 15:13:05">
It's a tracker, so I have multiple resources and the same resource is tracked a lot of time if I return on the same page.
I want to know how many news the user read, so I try with:
Ahoy::Event.where(user_id:3).group(:properties["resource:news"]).count
Update
I'm also trying with
Ahoy::Event.where(user_id:3).where("properties @> (:key => :value)", :key => 'resource', :value => 'Gate').count
** Update 2 ** Another tentative:
Ahoy::Event.where(user_id:3).where("properties --> 'resource': 'Gate'").select("properties #>> 'id' as resource, count('resource')").group("resource")