diff --git a/config/initializers/ahoy.rb b/config/initializers/ahoy.rb index 22d326e53..9a1215c68 100644 --- a/config/initializers/ahoy.rb +++ b/config/initializers/ahoy.rb @@ -1,3 +1,9 @@ class Ahoy::Store < Ahoy::Stores::ActiveRecordStore - # customize here + + # Track user IP + def track_event(name, properties, options) + super do |event| + event.ip = request.ip + end + end end diff --git a/db/migrate/20150808100936_add_ip_to_ahoy_event.rb b/db/migrate/20150808100936_add_ip_to_ahoy_event.rb new file mode 100644 index 000000000..2c6d9d9b2 --- /dev/null +++ b/db/migrate/20150808100936_add_ip_to_ahoy_event.rb @@ -0,0 +1,5 @@ +class AddIpToAhoyEvent < ActiveRecord::Migration + def change + add_column :ahoy_events, :ip, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 22b60c506..7846bfd1e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150806163142) do +ActiveRecord::Schema.define(version: 20150808100936) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -22,6 +22,7 @@ ActiveRecord::Schema.define(version: 20150806163142) do t.string "name" t.jsonb "properties" t.datetime "time" + t.string "ip" end add_index "ahoy_events", ["time"], name: "index_ahoy_events_on_time", using: :btree