Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ gem 'json'
gem 'font-awesome-rails'

# search with elasticsearch
gem 'searchkick'
gem 'searchkick'

# ahoy analytics
gem 'ahoy_matey'
24 changes: 24 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,22 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
ahoy_matey (1.4.0)
addressable
browser (~> 2.0)
geocoder
rack-attack
railties
referer-parser (>= 0.3.0)
request_store
safely_block
user_agent_parser
uuidtools
arel (6.0.3)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
browser (2.1.0)
builder (3.2.2)
byebug (8.0.1)
database_cleaner (1.5.1)
Expand All @@ -57,6 +70,7 @@ GEM
elasticsearch-transport (1.0.17)
faraday
multi_json
errbase (0.0.3)
erubis (2.7.0)
execjs (2.6.0)
factory_girl (4.5.0)
Expand All @@ -68,6 +82,7 @@ GEM
multipart-post (>= 1.2, < 3)
font-awesome-rails (4.5.0.0)
railties (>= 3.2, < 5.0)
geocoder (1.3.7)
globalid (0.3.6)
activesupport (>= 4.1.0)
haml (4.0.7)
Expand Down Expand Up @@ -107,6 +122,8 @@ GEM
mini_portile (~> 0.6.0)
pg (0.18.3)
rack (1.6.4)
rack-attack (4.4.1)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.4)
Expand Down Expand Up @@ -134,6 +151,8 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
referer-parser (0.3.0)
request_store (1.3.1)
rspec-core (3.3.2)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.1)
Expand All @@ -154,6 +173,8 @@ GEM
ruby-progressbar (1.7.5)
ruby_parser (3.8.1)
sexp_processor (~> 4.1)
safely_block (0.1.1)
errbase
sass (3.4.19)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
Expand Down Expand Up @@ -181,6 +202,8 @@ GEM
uglifier (2.7.2)
execjs (>= 0.3.0)
json (>= 1.8.0)
user_agent_parser (2.3.0)
uuidtools (2.1.5)
web-console (2.2.1)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
Expand All @@ -191,6 +214,7 @@ PLATFORMS
ruby

DEPENDENCIES
ahoy_matey
byebug
database_cleaner
decent_exposure
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/systems_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class SystemsController < ApplicationController
before_action :set_variables, :except => ['index']
after_filter :track_action

def show
end
Expand All @@ -13,6 +14,13 @@ def index
redirect_to system_path(@system)
end


protected
def track_action
ahoy.track "Processed #{controller_name}##{action_name}", request.filtered_parameters
ahoy.track_visit
end

private
def set_variables
@system = System.find(params[:id])
Expand Down
8 changes: 8 additions & 0 deletions app/models/ahoy/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Ahoy
class Event < ActiveRecord::Base
self.table_name = "ahoy_events"

belongs_to :visit
belongs_to :user
end
end
4 changes: 4 additions & 0 deletions app/models/visit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Visit < ActiveRecord::Base
has_many :ahoy_events, class_name: "Ahoy::Event"
belongs_to :user
end
3 changes: 3 additions & 0 deletions config/initializers/ahoy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Ahoy::Store < Ahoy::Stores::ActiveRecordTokenStore
Ahoy.track_visits_immediately = true
end
57 changes: 57 additions & 0 deletions db/migrate/20160616183629_create_visits.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class CreateVisits < ActiveRecord::Migration
def change
create_table :visits do |t|
t.string :visit_token
t.string :visitor_token

# 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, [:visit_token], unique: true
add_index :visits, [:user_id]
end
end
19 changes: 19 additions & 0 deletions db/migrate/20160616183630_create_ahoy_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CreateAhoyEvents < ActiveRecord::Migration
def change
create_table :ahoy_events do |t|
t.integer :visit_id

# user
t.integer :user_id
# add t.string :user_type if polymorphic

t.string :name
t.json :properties
t.timestamp :time
end

add_index :ahoy_events, [:visit_id, :name]
add_index :ahoy_events, [:user_id, :name]
add_index :ahoy_events, [:name, :time]
end
end
46 changes: 45 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160613085819) do
ActiveRecord::Schema.define(version: 20160616183630) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -29,6 +29,18 @@
t.text "relevant_codes_it"
end

create_table "ahoy_events", force: :cascade do |t|
t.integer "visit_id"
t.integer "user_id"
t.string "name"
t.json "properties"
t.datetime "time"
end

add_index "ahoy_events", ["name", "time"], name: "index_ahoy_events_on_name_and_time", using: :btree
add_index "ahoy_events", ["user_id", "name"], name: "index_ahoy_events_on_user_id_and_name", using: :btree
add_index "ahoy_events", ["visit_id", "name"], name: "index_ahoy_events_on_visit_id_and_name", using: :btree

create_table "drgs", force: :cascade do |t|
t.string "code"
t.string "version"
Expand Down Expand Up @@ -90,4 +102,36 @@
t.integer "application_year"
end

create_table "visits", force: :cascade do |t|
t.string "visit_token"
t.string "visitor_token"
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
add_index "visits", ["visit_token"], name: "index_visits_on_visit_token", unique: true, using: :btree

end