mitamirri 0.13.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +26 -0
- data/README.rdoc +117 -0
- data/Rakefile +26 -0
- data/VERSION +1 -0
- data/app/controllers/application_controller.rb +10 -0
- data/app/controllers/trackable_actions_controller.rb +10 -0
- data/app/controllers/trackable_sessions_controller.rb +100 -0
- data/app/helpers/application_helper.rb +2 -0
- data/app/models/trackable_action.rb +193 -0
- data/app/models/trackable_location.rb +19 -0
- data/app/models/trackable_session.rb +352 -0
- data/app/models/trackable_stat.rb +64 -0
- data/app/views/layouts/application.html.erb +20 -0
- data/app/views/trackable_sessions/_keywords_graph.html.erb +24 -0
- data/app/views/trackable_sessions/_print_buttons.html.erb +3 -0
- data/app/views/trackable_sessions/_sessions.html.erb +26 -0
- data/app/views/trackable_sessions/_top_referrers.html.erb +24 -0
- data/app/views/trackable_sessions/_traffic_summary_all.html.erb +64 -0
- data/app/views/trackable_sessions/_traffic_summary_by_kind.html.erb +48 -0
- data/app/views/trackable_sessions/_visits_graph.html.erb +25 -0
- data/app/views/trackable_sessions/content.html.erb +119 -0
- data/app/views/trackable_sessions/explorer.html.erb +67 -0
- data/app/views/trackable_sessions/export.xls.erb +5 -0
- data/app/views/trackable_sessions/index.html.erb +47 -0
- data/app/views/trackable_sessions/intersite.html.erb +97 -0
- data/app/views/trackable_sessions/leads.html.erb +98 -0
- data/app/views/trackable_sessions/show.html.erb +113 -0
- data/app/views/trackable_sessions/visitor_profile.html.erb +114 -0
- data/config/boot.rb +110 -0
- data/config/database.yml +0 -0
- data/config/environment.rb +24 -0
- data/config/environments/development.rb +17 -0
- data/config/environments/production.rb +28 -0
- data/config/environments/test.rb +31 -0
- data/config/initializers/backtrace_silencers.rb +7 -0
- data/config/initializers/database.rb +1 -0
- data/config/initializers/inflections.rb +10 -0
- data/config/initializers/mime_types.rb +5 -0
- data/config/initializers/new_rails_defaults.rb +21 -0
- data/config/initializers/session_store.rb +15 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +11 -0
- data/db/development.sqlite3 +0 -0
- data/db/migrate/20100810173533_create_trackable_sessions.rb +23 -0
- data/db/migrate/20100810173605_create_trackable_actions.rb +20 -0
- data/db/test.sqlite3 +1 -0
- data/doc/README_FOR_APP +2 -0
- data/init.rb +8 -0
- data/lib/mitamirri/content_report.rb +75 -0
- data/lib/mitamirri/helper.rb +106 -0
- data/lib/mitamirri/intersite_traffic_report.rb +122 -0
- data/lib/mitamirri/leads_report.rb +90 -0
- data/lib/mitamirri/session_report.rb +219 -0
- data/lib/mitamirri/stat_report.rb +216 -0
- data/lib/mitamirri/tasks.rb +27 -0
- data/lib/mitamirri/visitor_profile_report.rb +127 -0
- data/lib/mitamirri.rb +15 -0
- data/log/development.log +0 -0
- data/log/production.log +0 -0
- data/log/server.log +0 -0
- data/log/test.log +0 -0
- data/mitamirri.gemspec +125 -0
- data/public/stylesheets/mitamirri.css +736 -0
- data/script/about +4 -0
- data/script/console +3 -0
- data/script/dbconsole +3 -0
- data/script/destroy +3 -0
- data/script/generate +3 -0
- data/script/performance/benchmarker +3 -0
- data/script/performance/profiler +3 -0
- data/script/plugin +3 -0
- data/script/runner +3 -0
- data/script/server +3 -0
- data/spec/controllers/trackable_actions_controller_spec.rb +5 -0
- data/spec/controllers/trackable_sessions_controller_spec.rb +5 -0
- data/spec/custom_matchers.rb +23 -0
- data/spec/helpers/application_helper_spec.rb +57 -0
- data/spec/lib/content_report_spec.rb +37 -0
- data/spec/lib/intersite_traffic_report_spec.rb +51 -0
- data/spec/lib/leads_report_spec.rb +46 -0
- data/spec/lib/session_report_spec.rb +107 -0
- data/spec/lib/stat_report_spec.rb +106 -0
- data/spec/models/trackable_action_spec.rb +42 -0
- data/spec/models/trackable_session_spec.rb +154 -0
- data/spec/rcov.opts +4 -0
- data/spec/schema.rb +34 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +32 -0
- metadata +155 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
|
21
|
+
## PROJECT::SPECIFIC
|
22
|
+
log/*
|
23
|
+
doc/*
|
24
|
+
mitamirri.sqlite3.db
|
25
|
+
spec/debug.log
|
26
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
= mitamirri
|
2
|
+
|
3
|
+
Mitamirri is still in development and will not be production-ready until version 1.0.
|
4
|
+
|
5
|
+
It's a Rails engine designed to be a drop-in substitute for (or companion to) Google Analytics that allows tracking of custom user events at a very granular level (e.g. specific link or button clicks and even mouseovers) in addition to the standard visits, etc. It uses MongoDB on the backend for optimal performance, even with hundreds of thousands of visits, and to stay out of the way of your application's database.
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
* Make sure that you have MongoDB installed and configured for your environment.
|
10
|
+
|
11
|
+
* See http://www.mongodb.org/display/DOCS/Quickstart
|
12
|
+
|
13
|
+
* For the development environment, this OSX-specific installation guide is useful: http://shiftcommathree.com/articles/how-to-install-mongodb-on-os-x
|
14
|
+
|
15
|
+
* Install the mongo_mapper:
|
16
|
+
|
17
|
+
gem install mongo_mapper
|
18
|
+
|
19
|
+
* Install mongo_mapper's dependency:
|
20
|
+
|
21
|
+
gem install bson_ext
|
22
|
+
|
23
|
+
* Make sure that you have the Jeweler gem installed:
|
24
|
+
|
25
|
+
gem install jeweler
|
26
|
+
|
27
|
+
* Install the gem. From the Mitamirri repo:
|
28
|
+
|
29
|
+
rake install
|
30
|
+
|
31
|
+
* Add the following lines to your config/environment.rb file:
|
32
|
+
|
33
|
+
config.gem 'bantik-user-agent', :lib => 'user-agent'
|
34
|
+
config.gem 'mitamirri'
|
35
|
+
config.gem 'mongo_mapper'
|
36
|
+
config.gem 'pdfkit'
|
37
|
+
config.gem 'seer'
|
38
|
+
|
39
|
+
* Add the following line to your application's Rakefile:
|
40
|
+
|
41
|
+
require 'mitamirri/tasks'
|
42
|
+
|
43
|
+
* Add this to the top of your app/helpers/application_helper.rb file:
|
44
|
+
|
45
|
+
include Mitamirri::Helper
|
46
|
+
|
47
|
+
* To install the necessary files into your application, run:
|
48
|
+
|
49
|
+
rake mitamirri:install
|
50
|
+
|
51
|
+
* Update the database name in config/initializers/database.rb with the name of your application. Be sure to remove the timestamp from the database name!
|
52
|
+
|
53
|
+
* If you want to override default behaviour (strongly recommended, to at least require authorization for accessing reports), run the following rake command to copy Mitamirri's views and controllers to your application for customization:
|
54
|
+
|
55
|
+
rake mitamirri:override
|
56
|
+
|
57
|
+
* Mitamirri will automatically detect the host application's ability to render PDF versions of reports. To enable PDF output of reports, install PDFKit on your system add the following lines to your environment.rb file:
|
58
|
+
|
59
|
+
config.gem 'pdfkit'
|
60
|
+
config.gem 'geokit'
|
61
|
+
config.gem 'user-agent'
|
62
|
+
config.gem 'bantik-user-agent', :lib => 'user-agent'
|
63
|
+
config.middleware.use "PDFKit::Middleware", :print_media_type => true
|
64
|
+
|
65
|
+
* Recommended for optimal PDF output: add the following rule to your application's print style sheet:
|
66
|
+
|
67
|
+
.page_break { display: block; text-align: center; margin-top: 2em; page-break-after: always; }
|
68
|
+
|
69
|
+
And the following to your screen style sheet:
|
70
|
+
|
71
|
+
.page_break { display: none; }
|
72
|
+
|
73
|
+
== Configuring Tracking
|
74
|
+
|
75
|
+
* To track pageviews, add this anywhere in the HTML body of your view (or layout) file:
|
76
|
+
|
77
|
+
<%= track_action 'view' -%>
|
78
|
+
|
79
|
+
* To track scroll events, add this:
|
80
|
+
|
81
|
+
<%= track_action 'scroll' -%>
|
82
|
+
|
83
|
+
* To track mouseovers, add the DOM element ID and a custom label:
|
84
|
+
|
85
|
+
<%= track_action 'mouseover', :observe => 'my_element_id', :label => 'My Label for This Action' -%>
|
86
|
+
|
87
|
+
* To track click events, add the DOM element ID and a custom label:
|
88
|
+
|
89
|
+
<%= track_action 'click', :observe => 'my_element_id', :label => 'My Submit Button Pressed' -%>
|
90
|
+
|
91
|
+
* To track conversions, add the DOM element ID and an optional custom label:
|
92
|
+
|
93
|
+
<%= track_action 'conversion', :observe => 'my_element_id', :label => 'Contact Form Submitted' -%>
|
94
|
+
|
95
|
+
* To track clickthroughs to other sites, add the DOM element ID and an optional custom label:
|
96
|
+
|
97
|
+
<%= track_action 'clickthrough', :observe => 'my_link_id', :label => 'Link to CorporateSite.com' -%>
|
98
|
+
|
99
|
+
== Accessing Reports
|
100
|
+
|
101
|
+
To view reports and session details, point your browser to http://localhost:3000/tracking/
|
102
|
+
|
103
|
+
== Development Tips
|
104
|
+
|
105
|
+
* To run specs, use spec spec/
|
106
|
+
|
107
|
+
* If you're just changing views, run rake:install from your local Mitamirri directory and updates will appear in your host application immediately.
|
108
|
+
|
109
|
+
* If you're changing models, run rake:install and then restart your host application.
|
110
|
+
|
111
|
+
* If you add features, run rake version:bump:minor to adjust the version number accordingly.
|
112
|
+
|
113
|
+
* If you're just fixing bugs, run rake version:bump:patch instead.
|
114
|
+
|
115
|
+
== Copyright
|
116
|
+
|
117
|
+
Copyright (c) 2010 Corey Ehmke / SEO Logic. All rights reserved.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
#require(File.join(File.dirname(__FILE__), 'config', 'boot'))
|
5
|
+
|
6
|
+
require 'rake'
|
7
|
+
require 'rake/testtask'
|
8
|
+
require 'rake/rdoctask'
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'jeweler'
|
12
|
+
require 'seer'
|
13
|
+
Jeweler::Tasks.new do |gemspec|
|
14
|
+
gemspec.name = "mitamirri"
|
15
|
+
gemspec.summary = "View and action tracking for Rails 2.x."
|
16
|
+
gemspec.description = "View and action tracking for Rails 2.x."
|
17
|
+
gemspec.email = "corey@seologic.com"
|
18
|
+
gemspec.homepage = "http://github.com/Bantik/mitamarri"
|
19
|
+
gemspec.authors = ["Corey Ehmke"]
|
20
|
+
gemspec.test_files = []
|
21
|
+
end
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
25
|
+
end
|
26
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.13.8
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
helper :all # include all helpers, all the time
|
6
|
+
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
7
|
+
|
8
|
+
# Scrub sensitive parameters from your log
|
9
|
+
# filter_parameter_logging :password
|
10
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
class TrackableSessionsController < ApplicationController
|
2
|
+
|
3
|
+
Mime::Type.register "application/vnd.ms-excel", :xls
|
4
|
+
|
5
|
+
def index
|
6
|
+
@sites = (TrackableStat.sites + ["All Sites"]).sort
|
7
|
+
@time_periods = ["Past 3 Months", "Past 6 Months", "Past 12 Months"]
|
8
|
+
params[:time_period] ||= 'past 3 months'
|
9
|
+
if params[:site]
|
10
|
+
@sessions = TrackableSession.search(params).all(:order => :created_at.desc, :limit => 25)
|
11
|
+
@report = Mitamirri::StatReport.new(params)
|
12
|
+
@visits = @report.visits(params)
|
13
|
+
@visits_series = @visits.map{|v| v.stats}
|
14
|
+
@keywords_series = Mitamirri::StatReport.keywords_by_frequency(params)
|
15
|
+
@referrers_series = Mitamirri::StatReport.top_referrers(params)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def content
|
20
|
+
@sites = (TrackableStat.sites + ["All Sites"]).sort
|
21
|
+
@time_periods = ["past 3 months", "past 6 months", "past 12 months"]
|
22
|
+
params[:time_period] ||= 'past 3 months'
|
23
|
+
params[:visit_kind] ||= 'All'
|
24
|
+
if params[:site]
|
25
|
+
params[:visit_kind] = 'all' if params[:visit_kind] == 'total'
|
26
|
+
@report = Mitamirri::ContentReport.new(params)
|
27
|
+
@pages_series = @report.pages_series(params)
|
28
|
+
@entrance_pages_series = @report.entrance_pages_series(:site => params[:site], :time_period => params[:time_period])
|
29
|
+
@exit_pages_series = @report.exit_pages_series(:site => params[:site], :time_period => params[:time_period])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def explorer
|
34
|
+
@sites = (TrackableStat.sites + ["all sites"]).sort
|
35
|
+
@time_periods = ["past 3 months", "past 6 months", "past 12 months"]
|
36
|
+
@kinds = TrackableAction.kinds
|
37
|
+
params[:time_period] ||= 'past 3 months'
|
38
|
+
params[:visit_kind] ||= 'total'
|
39
|
+
params[:action_kind] ||= 'conversions'
|
40
|
+
if params[:site]
|
41
|
+
params[:visit_kind] = 'all' if params[:visit_kind] == 'total'
|
42
|
+
@sessions = TrackableSession.search(params).all(:order => :created_at.desc, :limit => 25)
|
43
|
+
@report = Mitamirri::SessionReport.new(params)
|
44
|
+
@visits = @report.visits(params)
|
45
|
+
@visits_series = @visits.map{|v| v.stats}
|
46
|
+
@keywords_series = Mitamirri::SessionReport.keywords_by_frequency(params)
|
47
|
+
@referrers_series = Mitamirri::SessionReport.top_referrers(params)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def export
|
52
|
+
@sessions = TrackableSession.search(params).all
|
53
|
+
respond_to do |format|
|
54
|
+
format.xls {
|
55
|
+
headers['Content-Type'] = "application/vnd.ms-excel"
|
56
|
+
headers['Content-Disposition'] = 'attachment; filename="sessions_export.xls"'
|
57
|
+
headers['Cache-Control'] = ''
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def leads
|
63
|
+
@sites = (TrackableStat.sites + ["All Sites"]).sort
|
64
|
+
@time_periods = ["Past 3 Months", "Past 6 Months", "Past 12 Months"]
|
65
|
+
params[:time_period] ||= @time_periods.first
|
66
|
+
if params[:site]
|
67
|
+
@report = Mitamirri::LeadsReport.new(params)
|
68
|
+
@leads = @report.leads(params)
|
69
|
+
@leads_series = @leads.map{|l| l.stats}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def intersite
|
74
|
+
@sites = (TrackableStat.sites + ["All Sites"]).sort
|
75
|
+
@time_periods = ["Past 3 Months", "Past 6 Months", "Past 12 Months"]
|
76
|
+
params[:time_period] ||= @time_periods.first
|
77
|
+
if params[:site]
|
78
|
+
@report = Mitamirri::IntersiteTrafficReport.new(params)
|
79
|
+
@total_visits = @report.total_visits(params)
|
80
|
+
@total_visits_series = @total_visits.map{|v| v.stats}
|
81
|
+
@destinations_series = @report.destinations(params)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def show
|
86
|
+
@trackable_session = TrackableSession.find(params[:id])
|
87
|
+
end
|
88
|
+
|
89
|
+
def visitor_profile
|
90
|
+
@sites = (TrackableStat.sites + ["All Sites"]).sort
|
91
|
+
@time_periods = ["Past 3 Months", "Past 6 Months", "Past 12 Months"]
|
92
|
+
params[:time_period] ||= @time_periods.first
|
93
|
+
if params[:site]
|
94
|
+
@report = Mitamirri::VisitorProfileReport.new(params)
|
95
|
+
@user_agents_series = @report.user_agents_by_frequency(params)
|
96
|
+
@locations_series = @report.locations_by_frequency(params)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
class TrackableAction
|
2
|
+
|
3
|
+
include MongoMapper::Document
|
4
|
+
|
5
|
+
# MongoMapper Setup ==============================================================================
|
6
|
+
|
7
|
+
belongs_to :trackable_session
|
8
|
+
|
9
|
+
key :trackable_session_id, ObjectId
|
10
|
+
key :kind, String, :index => true
|
11
|
+
key :label, String, :index => true
|
12
|
+
key :referrer, String
|
13
|
+
key :url, String, :index => true
|
14
|
+
key :relative_url, String
|
15
|
+
key :site, String, :index => true
|
16
|
+
key :new_visit, Boolean
|
17
|
+
timestamps!
|
18
|
+
|
19
|
+
# Scopes =========================================================================================
|
20
|
+
|
21
|
+
scope :by_kind, lambda { |k| { :conditions => { :kind => k } } }
|
22
|
+
scope :by_label, lambda { |l| { :conditions => { :label => l } } }
|
23
|
+
scope :clicks, :conditions => {:kind => 'click'}
|
24
|
+
scope :clickthroughs, :conditions => {:kind => 'clickthrough'}
|
25
|
+
scope :conversions, :conditions => {:kind => 'conversion'}
|
26
|
+
scope :leads, :conditions => {:kind => 'conversion'}
|
27
|
+
scope :for_site, lambda { |s| { :conditions => { :site => s } } }
|
28
|
+
scope :for_month, lambda { |d| { :conditions => { :created_at => { '$gte' => d.beginning_of_month, '$lte' => d.end_of_month } } } }
|
29
|
+
scope :for_week, lambda { |d| { :conditions => { :created_at => { '$gte' => d.beginning_of_week, '$lte' => d.end_of_week } } } }
|
30
|
+
scope :for_date_range, lambda { |start_date,end_date| { :conditions => { :created_at => { '$gte' => start_date.beginning_of_month, '$lte' => end_date.end_of_month } } } }
|
31
|
+
scope :mouseovers, :conditions => {:kind => 'mouseover'}
|
32
|
+
scope :scrolls, :conditions => {:kind => 'scroll'}
|
33
|
+
scope :views, :conditions => {:kind => 'view'}
|
34
|
+
|
35
|
+
# Constants ======================================================================================
|
36
|
+
|
37
|
+
KINDS = ['clicks', 'leads', 'scrolls', 'mouseovers', 'clickthroughs']
|
38
|
+
|
39
|
+
# Class Methods ==================================================================================
|
40
|
+
|
41
|
+
def self.create_from_params(params, creation_date = Time.zone.now)
|
42
|
+
_referring_site = nil
|
43
|
+
_relative_url = nil
|
44
|
+
begin
|
45
|
+
if ! params[:referrer].blank? && params[:referrer] != '/'
|
46
|
+
_referring_site = URI.parse(params[:referrer]).host
|
47
|
+
_referring_site = nil if _referring_site == params[:site]
|
48
|
+
end
|
49
|
+
_relative_url = URI.parse(params[:url]).path.downcase
|
50
|
+
rescue
|
51
|
+
end
|
52
|
+
|
53
|
+
unless trackable_session = TrackableSession.find_by_session_id(params[:session_id])
|
54
|
+
trackable_session = TrackableSession.create(
|
55
|
+
:session_id => params[:session_id],
|
56
|
+
:referrer => _referring_site,
|
57
|
+
:referring_keywords => params[:referring_keywords],
|
58
|
+
:ip_address => params[:remote_ip],
|
59
|
+
:site => params[:site].downcase,
|
60
|
+
:session_id => params[:session_id],
|
61
|
+
:initial_request_url => params[:url].downcase,
|
62
|
+
:entrance_page => _relative_url,
|
63
|
+
:exit_page => _relative_url,
|
64
|
+
:user_agent => params[:user_agent],
|
65
|
+
:views_count => 0,
|
66
|
+
:created_at => creation_date
|
67
|
+
)
|
68
|
+
end
|
69
|
+
_action = TrackableAction.create(
|
70
|
+
:kind => params[:kind],
|
71
|
+
:label => params[:label],
|
72
|
+
:referrer => params[:referrer],
|
73
|
+
:url => params[:url],
|
74
|
+
:relative_url => _relative_url,
|
75
|
+
:site => params[:site],
|
76
|
+
:trackable_session_id => trackable_session.id,
|
77
|
+
:created_at => creation_date
|
78
|
+
)
|
79
|
+
trackable_session.touch(params[:kind], params[:destination], _relative_url)
|
80
|
+
_action
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.create_test_data!(count = 1000, destructive = true)
|
84
|
+
|
85
|
+
if destructive
|
86
|
+
TrackableStat.delete_all
|
87
|
+
TrackableSession.delete_all
|
88
|
+
TrackableAction.delete_all
|
89
|
+
end
|
90
|
+
|
91
|
+
1..count.times do
|
92
|
+
params = {
|
93
|
+
:remote_ip => "127.0.0.#{rand(128)}",
|
94
|
+
:site => ['www.test1.com', 'www.test2.com', 'www.test3.com'].rand,
|
95
|
+
:initial_referrer => ['','','','','','http://www.google.com','http://www.bing.com','http://www.yahoo.com','http://www.seologic.com','http://www.idolhands.com','http://www.findcounseling.com','http://www.emeritus.com'].rand,
|
96
|
+
:session_id => "#{rand(10000)}#{('a'..'z').to_a.rand}"
|
97
|
+
}
|
98
|
+
|
99
|
+
created_at = Time.zone.now - rand(6).months - rand(30).days
|
100
|
+
(1..rand(10)).each do |i|
|
101
|
+
params[:kind] = ['view','view','mouseover','click','view','view','scroll','view','click','conversion'].rand
|
102
|
+
params[:referrer] = i == 1 ? params[:initial_referrer] : "/"
|
103
|
+
params[:referring_keywords] = i == 1 ? ['foo','bar','trouble','braids'].rand : nil
|
104
|
+
params[:url] = "http://#{params[:site]}#{['/','/about','/tour','/contact','/services'].rand}"
|
105
|
+
params[:label] = params[:kind].titleize
|
106
|
+
TrackableAction.create_from_params(params, created_at + i.minutes)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
"Created #{count} sample sessions."
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns a list of kinds that have already been tracked.
|
113
|
+
def self.kinds
|
114
|
+
_kinds = []
|
115
|
+
KINDS.each{ |kind| _kinds << kind unless self.send(kind).count.zero? }
|
116
|
+
_kinds
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.pages_histogram(args)
|
120
|
+
TrackableAction.collection.group("function(x) { return { url: x.url }; }", TrackableAction.search(args).to_hash, { :count => 0}, "function(x,y){y.count++}", true).inject({}){|h,k| h[URI.parse(k['url']).path] ||= 0; h[URI.parse(k['url']).path] += k['count']; h}.sort{|a,b| a[1] <=> b[1]}.reverse
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.search(args = {})
|
124
|
+
args[:site] ||= 'all sites'
|
125
|
+
args[:action_kind] ||= 'views'
|
126
|
+
[:site, :action_kind, :time_period].each{|a| args[a] = args[a].downcase if args[a]}
|
127
|
+
case args[:time_period]
|
128
|
+
when 'past 3 months'
|
129
|
+
args[:start_date] = (Time.zone.now - 2.months).beginning_of_month
|
130
|
+
args[:end_date] = Time.zone.now
|
131
|
+
when 'past 6 months'
|
132
|
+
args[:start_date] = (Time.zone.now - 5.months).beginning_of_month
|
133
|
+
args[:end_date] = Time.zone.now
|
134
|
+
when 'past 12 months'
|
135
|
+
args[:start_date] = (Time.zone.now - 11.months).beginning_of_month
|
136
|
+
args[:end_date] = Time.zone.now
|
137
|
+
else
|
138
|
+
args[:start_date] = TrackableAction.first.created_at
|
139
|
+
args[:end_date] = Time.zone.now
|
140
|
+
end
|
141
|
+
if args[:time_period]
|
142
|
+
if args[:site] == 'all sites'
|
143
|
+
TrackableAction.send("#{args[:action_kind]}").for_date_range(args[:start_date], args[:end_date])
|
144
|
+
else
|
145
|
+
TrackableAction.for_site(args[:site]).send("#{args[:action_kind]}").for_date_range(args[:start_date], args[:end_date])
|
146
|
+
end
|
147
|
+
else
|
148
|
+
if args[:site] == 'all sites'
|
149
|
+
TrackableAction.send("#{args[:action_kind]}")
|
150
|
+
else
|
151
|
+
TrackableAction.for_site(args[:site]).send("#{args[:action_kind]}")
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# Can't combine date conditions, so this is needed for reports
|
157
|
+
def self.search_without_date(args = {})
|
158
|
+
args[:site] ||= 'all sites'
|
159
|
+
args[:action_kind] ||= 'views'
|
160
|
+
[:site, :action_kind, :visit_kind].each{|a| args[a] = args[a].downcase}
|
161
|
+
if args[:site] == 'all sites'
|
162
|
+
TrackableAction.send("#{args[:action_kind]}")
|
163
|
+
else
|
164
|
+
TrackableAction.for_site(args[:site]).send("#{args[:action_kind]}")
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# Instance Methods ===============================================================================
|
169
|
+
|
170
|
+
def click?
|
171
|
+
self.kind == 'click'
|
172
|
+
end
|
173
|
+
|
174
|
+
def clickthrough?
|
175
|
+
self.kind == 'clickthrough'
|
176
|
+
end
|
177
|
+
|
178
|
+
def conversion?
|
179
|
+
self.kind == 'conversion'
|
180
|
+
end
|
181
|
+
|
182
|
+
def mouseover?
|
183
|
+
self.kind == 'mouseover'
|
184
|
+
end
|
185
|
+
|
186
|
+
def scroll?
|
187
|
+
self.kind == 'scroll'
|
188
|
+
end
|
189
|
+
|
190
|
+
def view?
|
191
|
+
self.kind == 'view'
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class TrackableLocation
|
2
|
+
|
3
|
+
include MongoMapper::Document
|
4
|
+
|
5
|
+
# MongoMapper Setup ==============================================================================
|
6
|
+
|
7
|
+
key :location, String, :index => true
|
8
|
+
key :latitude, String
|
9
|
+
key :longitude, String
|
10
|
+
|
11
|
+
# Scopes =========================================================================================
|
12
|
+
|
13
|
+
# Constants ======================================================================================
|
14
|
+
|
15
|
+
# Class Methods ==================================================================================
|
16
|
+
|
17
|
+
# Instance Methods ===============================================================================
|
18
|
+
|
19
|
+
end
|