diff --git a/Gemfile b/Gemfile index 4c37d5ea1..ee555ec92 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,10 @@ gem 'acts_as_votable' gem "recaptcha", require: "recaptcha/rails" gem 'ckeditor' +gem 'ahoy_matey' # stats +gem "chartkick" # charts +gem 'groupdate' # group temporary data + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' @@ -62,4 +66,3 @@ end group :test do gem 'email_spec' end - diff --git a/Gemfile.lock b/Gemfile.lock index 62be9aa71..c005c2b21 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,12 +44,23 @@ GEM awesome_nested_set (>= 3.0) acts_as_votable (0.10.0) addressable (2.3.8) + ahoy_matey (1.2.0) + addressable + browser (>= 0.4.0) + errbase + geocoder + rails + referer-parser (>= 0.3.0) + request_store + user_agent_parser + uuidtools arel (6.0.2) awesome_nested_set (3.0.2) activerecord (>= 4.0.0, < 5) bcrypt (3.1.10) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) + browser (0.9.1) builder (3.2.2) byebug (5.0.0) columnize (= 0.9.0) @@ -74,6 +85,7 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + chartkick (1.3.2) ckeditor (4.1.2) cocaine orm_adapter (~> 0.5.0) @@ -117,6 +129,7 @@ GEM email_spec (1.6.0) launchy (~> 2.1) mail (~> 2.2) + errbase (0.0.3) erubis (2.7.0) execjs (2.5.2) factory_girl (4.5.0) @@ -127,8 +140,11 @@ GEM foundation-rails (5.5.2.1) railties (>= 3.1.0) sass (>= 3.3.0, < 3.5) + geocoder (1.2.9) globalid (0.3.5) activesupport (>= 4.1.0) + groupdate (2.4.0) + activesupport (>= 3) highline (1.7.3) http-cookie (1.0.2) domain_name (~> 0.5) @@ -209,6 +225,8 @@ GEM rake (10.4.2) rdoc (4.2.0) recaptcha (0.4.0) + referer-parser (0.3.0) + request_store (1.2.0) responders (2.1.0) railties (>= 4.2.0, < 5) rest-client (1.8.0) @@ -276,6 +294,8 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.1) + user_agent_parser (2.2.0) + uuidtools (2.1.5) warden (1.2.3) rack (>= 1.0) web-console (2.2.1) @@ -296,6 +316,7 @@ DEPENDENCIES acts-as-taggable-on acts_as_commentable_with_threading acts_as_votable + ahoy_matey byebug capistrano (= 3.4.0) capistrano-bundler (= 1.1.4) @@ -303,6 +324,7 @@ DEPENDENCIES capistrano-rails (= 1.1.3) capistrano-rvm capybara + chartkick ckeditor coffee-rails (~> 4.1.0) coveralls @@ -311,6 +333,7 @@ DEPENDENCIES email_spec factory_girl_rails foundation-rails + groupdate i18n-tasks jbuilder (~> 2.0) jquery-rails diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 08153c4ec..10fad952a 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -15,6 +15,7 @@ //= require foundation //= require turbolinks //= require ckeditor/init +//= require ahoy //= require app //= require_tree . diff --git a/app/models/ahoy/event.rb b/app/models/ahoy/event.rb new file mode 100644 index 000000000..2aac3c59c --- /dev/null +++ b/app/models/ahoy/event.rb @@ -0,0 +1,8 @@ +module Ahoy + class Event < ActiveRecord::Base + self.table_name = "ahoy_events" + + belongs_to :visit + belongs_to :user + end +end diff --git a/config/initializers/ahoy.rb b/config/initializers/ahoy.rb new file mode 100644 index 000000000..22d326e53 --- /dev/null +++ b/config/initializers/ahoy.rb @@ -0,0 +1,3 @@ +class Ahoy::Store < Ahoy::Stores::ActiveRecordStore + # customize here +end diff --git a/db/migrate/20150804144230_create_visits.rb b/db/migrate/20150804144230_create_visits.rb new file mode 100644 index 000000000..6f5156c0e --- /dev/null +++ b/db/migrate/20150804144230_create_visits.rb @@ -0,0 +1,56 @@ +class CreateVisits < ActiveRecord::Migration + def change + create_table :visits, id: false do |t| + t.uuid :id, default: nil, primary_key: true + t.uuid :visitor_id, default: nil + + # the rest are recommended but optional + # simply remove the columns you don't want + + # standard + t.string :ip + t.text :user_agent + t.text :referrer + t.text :landing_page + + # user + t.integer :user_id + # add t.string :user_type if polymorphic + + # traffic source + t.string :referring_domain + t.string :search_keyword + + # technology + t.string :browser + t.string :os + t.string :device_type + t.integer :screen_height + t.integer :screen_width + + # location + t.string :country + t.string :region + t.string :city + t.string :postal_code + t.decimal :latitude + t.decimal :longitude + + # utm parameters + t.string :utm_source + t.string :utm_medium + t.string :utm_term + t.string :utm_content + t.string :utm_campaign + + # native apps + # t.string :platform + # t.string :app_version + # t.string :os_version + + t.timestamp :started_at + end + + add_index :visits, [:user_id] + end +end diff --git a/db/migrate/20150804144231_create_ahoy_events.rb b/db/migrate/20150804144231_create_ahoy_events.rb new file mode 100644 index 000000000..81fb71f37 --- /dev/null +++ b/db/migrate/20150804144231_create_ahoy_events.rb @@ -0,0 +1,20 @@ +class CreateAhoyEvents < ActiveRecord::Migration + def change + create_table :ahoy_events, id: false do |t| + t.uuid :id, default: nil, primary_key: true + t.uuid :visit_id, default: nil + + # user + t.integer :user_id + # add t.string :user_type if polymorphic + + t.string :name + t.jsonb :properties + t.timestamp :time + end + + add_index :ahoy_events, [:visit_id] + add_index :ahoy_events, [:user_id] + add_index :ahoy_events, [:time] + end +end diff --git a/db/schema.rb b/db/schema.rb index f6947e462..22b60c506 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -16,6 +16,18 @@ ActiveRecord::Schema.define(version: 20150806163142) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "ahoy_events", id: :uuid, default: nil, force: :cascade do |t| + t.uuid "visit_id" + t.integer "user_id" + t.string "name" + t.jsonb "properties" + t.datetime "time" + end + + add_index "ahoy_events", ["time"], name: "index_ahoy_events_on_time", using: :btree + add_index "ahoy_events", ["user_id"], name: "index_ahoy_events_on_user_id", using: :btree + add_index "ahoy_events", ["visit_id"], name: "index_ahoy_events_on_visit_id", using: :btree + create_table "comments", force: :cascade do |t| t.integer "commentable_id" t.string "commentable_type" @@ -62,18 +74,18 @@ ActiveRecord::Schema.define(version: 20150806163142) do add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "first_name" t.string "last_name" t.string "confirmation_token" @@ -81,7 +93,7 @@ ActiveRecord::Schema.define(version: 20150806163142) do t.datetime "confirmation_sent_at" t.string "unconfirmed_email" t.string "nickname" - t.boolean "use_nickname", default: false, null: false + t.boolean "use_nickname", default: false, null: false t.boolean "email_on_debate_comment", default: false t.boolean "email_on_comment_reply", default: false end @@ -90,6 +102,36 @@ ActiveRecord::Schema.define(version: 20150806163142) do add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + create_table "visits", id: :uuid, default: nil, force: :cascade do |t| + t.uuid "visitor_id" + t.string "ip" + t.text "user_agent" + t.text "referrer" + t.text "landing_page" + t.integer "user_id" + t.string "referring_domain" + t.string "search_keyword" + t.string "browser" + t.string "os" + t.string "device_type" + t.integer "screen_height" + t.integer "screen_width" + t.string "country" + t.string "region" + t.string "city" + t.string "postal_code" + t.decimal "latitude" + t.decimal "longitude" + t.string "utm_source" + t.string "utm_medium" + t.string "utm_term" + t.string "utm_content" + t.string "utm_campaign" + t.datetime "started_at" + end + + add_index "visits", ["user_id"], name: "index_visits_on_user_id", using: :btree + create_table "votes", force: :cascade do |t| t.integer "votable_id" t.string "votable_type"