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/script/destroy
ADDED
data/script/generate
ADDED
data/script/plugin
ADDED
data/script/runner
ADDED
data/script/server
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module CustomMatcher
|
2
|
+
def set_cell(row, column, value)
|
3
|
+
value = "'#{value}'" if value.is_a?(String)
|
4
|
+
|
5
|
+
simple_matcher("setCell(#{row}, #{column}, #{value})") do |actual|
|
6
|
+
actual =~ /data\.setCell\(#{row},\s*#{column},\s*#{value}\)/
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_value(row, column, value)
|
11
|
+
value = "'#{value}'" if value.is_a?(String)
|
12
|
+
|
13
|
+
simple_matcher("setValue(#{row}, #{column}, #{value})") do |actual|
|
14
|
+
actual =~ /data\.setValue\(#{row},\s*#{column},\s*#{value}\)/
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_column(column_type, value)
|
19
|
+
simple_matcher("addColumn('#{column_type}', '#{value}')") do |actual|
|
20
|
+
actual =~ /data\.addColumn\('#{column_type}',\s*'#{value}'\)/
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'mitamirri'
|
3
|
+
include Mitamirri::Helper
|
4
|
+
|
5
|
+
describe "application helper methods" do
|
6
|
+
|
7
|
+
describe 'track action' do
|
8
|
+
|
9
|
+
it 'creates a trackable action object from view tracking invocation' do
|
10
|
+
request = Object.new
|
11
|
+
request.stubs(:referrer).returns('/')
|
12
|
+
request.stubs(:remote_ip).returns('123.123.123.123')
|
13
|
+
request.stubs(:url).returns('http://www.elizium.com/opiates')
|
14
|
+
session = Object.new
|
15
|
+
session.stubs(:session_id).returns('1234ab')
|
16
|
+
lambda{
|
17
|
+
track_action('view', :label => 'Some Label')
|
18
|
+
}.should change(TrackableAction, :count).by(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns track click code for click tracking invocation' do
|
22
|
+
request = Object.new
|
23
|
+
request.stubs(:referrer).returns('/')
|
24
|
+
request.stubs(:remote_ip).returns('123.123.123.123')
|
25
|
+
request.stubs(:url).returns('http://www.elizium.com/opiates')
|
26
|
+
session = Object.new
|
27
|
+
session.stubs(:session_id).returns('1234ab')
|
28
|
+
track_action('click').should_not be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'needs more robust tests for this method'
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns appropriate track_click_code' do
|
36
|
+
expected = %{<script type="text/javascript">
|
37
|
+
Event.observe(window, 'load', function() {
|
38
|
+
Event.observe('my_button', 'mousedown', track_mousedown_my_button_event);
|
39
|
+
});
|
40
|
+
function track_mousedown_my_button_event() {
|
41
|
+
new Ajax.Updater('tracking', '/trackable_actions/', {asynchronous:true, evalScripts:true, parameters:'action=create&kind=click&label=my_action&referrer=/&remote_ip=123.123.123.123&site=www.seologic.com&url=/&session_id=asdf&destination='})
|
42
|
+
Event.stopObserving('my_button', 'mousedown', track_mousedown_my_button_event);
|
43
|
+
}
|
44
|
+
</script>}
|
45
|
+
track_event_code('click', 'mousedown', 'my_button', 'my_action', '/', '123.123.123.123', 'www.seologic.com', '/', 'asdf').should == expected
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns a legend tag' do
|
49
|
+
legend_tag('Foo', {:id => 'foo'}).should == %{<div id="foo" class="faux_legend">Foo</div>\r}
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns page break code' do
|
53
|
+
page_break.should == %{<div class="page_break" /><p>(Continued on next page)</p></div>}
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'mitamirri'
|
3
|
+
|
4
|
+
describe "ContentReport" do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
@args = {
|
8
|
+
:site => 'www.foo.com',
|
9
|
+
:time_period => 'past 3 months',
|
10
|
+
:visit_kind => 'search'
|
11
|
+
}
|
12
|
+
TrackableSession.stubs(:search).returns([])
|
13
|
+
@report = Mitamirri::ContentReport.new(@args)
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'initializes with arguments' do
|
18
|
+
@report.site.should == @args[:site]
|
19
|
+
@report.time_period.should == @args[:time_period]
|
20
|
+
@report.visit_kind.should == @args[:visit_kind]
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'calculates its dates' do
|
24
|
+
@report.dates.should == [
|
25
|
+
(Time.zone.now - 2.months).beginning_of_month,
|
26
|
+
(Time.zone.now - 1.months).beginning_of_month,
|
27
|
+
(Time.zone.now).end_of_month,
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'creates a ContentStat object from arguments' do
|
32
|
+
_stat = Mitamirri::ContentReport::ContentStat.new(:url => '/', :views => 3)
|
33
|
+
_stat.views.should == 3
|
34
|
+
_stat.url.should == '/'
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'mitamirri'
|
3
|
+
|
4
|
+
describe "IntersiteTrafficReport" do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
@args = {
|
8
|
+
:site => 'www.foo.com',
|
9
|
+
:time_period => 'past month',
|
10
|
+
:visit_kind => 'search'
|
11
|
+
}
|
12
|
+
TrackableSession.stubs(:search).returns([])
|
13
|
+
@report = Mitamirri::IntersiteTrafficReport.new(@args)
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'initializes with arguments' do
|
18
|
+
@report.site.should == @args[:site]
|
19
|
+
@report.time_period.should == @args[:time_period]
|
20
|
+
@report.visit_kind.should == @args[:visit_kind]
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'calculates its dates' do
|
24
|
+
@report.dates.should == [
|
25
|
+
(Time.zone.now - 4.weeks).end_of_week,
|
26
|
+
(Time.zone.now - 3.weeks).end_of_week,
|
27
|
+
(Time.zone.now - 2.weeks).end_of_week,
|
28
|
+
(Time.zone.now - 1.weeks).end_of_week,
|
29
|
+
(Time.zone.now).end_of_week,
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'creates a Destination object from arguments' do
|
34
|
+
_stat = Mitamirri::IntersiteTrafficReport::Destination.new(:site => 'www.foo.com', :clickthroughs => 3)
|
35
|
+
_stat.clickthroughs.should == 3
|
36
|
+
_stat.site.should == 'www.foo.com'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'creates a Visit object from arguments' do
|
40
|
+
_stat = Mitamirri::IntersiteTrafficReport::Visit.new(:site => 'www.foo.com', :stats => [])
|
41
|
+
_stat.site.should == 'www.foo.com'
|
42
|
+
_stat.stats.should == []
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'creates a VisitStat object from arguments' do
|
46
|
+
_stat = Mitamirri::IntersiteTrafficReport::VisitStat.new(:date => Time.zone.now.beginning_of_month, :clickthroughs => 3)
|
47
|
+
_stat.clickthroughs.should == 3
|
48
|
+
_stat.date.should == Time.zone.now.beginning_of_month
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'mitamirri'
|
3
|
+
|
4
|
+
describe "LeadsReport" do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
@args = {
|
8
|
+
:site => 'www.foo.com',
|
9
|
+
:time_period => 'past month',
|
10
|
+
}
|
11
|
+
TrackableSession.stubs(:search).returns([])
|
12
|
+
@report = Mitamirri::LeadsReport.new(@args)
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'initializes with arguments' do
|
17
|
+
@report.site.should == @args[:site]
|
18
|
+
@report.time_period.should == @args[:time_period]
|
19
|
+
@report.start_date.should == (Time.zone.now - 4.weeks).beginning_of_week
|
20
|
+
@report.end_date.to_s(:concise).should == Time.zone.now.to_s(:concise)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'calculates its dates' do
|
24
|
+
@report.dates.map{|d| d.to_s(:concise)}.should == [
|
25
|
+
(Time.zone.now - 4.weeks).beginning_of_week.to_s(:concise),
|
26
|
+
(Time.zone.now - 3.weeks).beginning_of_week.to_s(:concise),
|
27
|
+
(Time.zone.now - 2.weeks).beginning_of_week.to_s(:concise),
|
28
|
+
(Time.zone.now - 1.weeks).beginning_of_week.to_s(:concise),
|
29
|
+
Time.zone.now.to_s(:concise),
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'creates a Lead object from arguments' do
|
34
|
+
_lead = Mitamirri::LeadsReport::Lead.new(:stats => ['foo'])
|
35
|
+
_lead.stats.should == ['foo']
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'creates a LeadStats object from arguments' do
|
39
|
+
_stat = Mitamirri::LeadsReport::LeadStat.new(:date => Time.zone.now.end_of_week, :leads => 3, :conversion_rate => 50.0)
|
40
|
+
_stat.date.should == Time.zone.now.end_of_week
|
41
|
+
_stat.leads.should == 3
|
42
|
+
_stat.conversion_rate.should == 50.0
|
43
|
+
_stat.short_date.should == Time.zone.now.end_of_week.to_s(:concise)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'mitamirri'
|
3
|
+
|
4
|
+
describe "SessionReport" do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
@args = {
|
8
|
+
:site => 'www.foo.com',
|
9
|
+
:time_period => 'past 3 months',
|
10
|
+
:action_kind => 'clickthrough',
|
11
|
+
:visit_kind => 'search'
|
12
|
+
}
|
13
|
+
TrackableSession.stubs(:search).returns([])
|
14
|
+
@report = Mitamirri::SessionReport.new(@args)
|
15
|
+
@report.stubs(:total_bounces).returns(5)
|
16
|
+
@report.stubs(:total_clickthroughs).returns(10)
|
17
|
+
@report.stubs(:total_conversions).returns(20)
|
18
|
+
@report.stubs(:total_direct_visits).returns(10)
|
19
|
+
@report.stubs(:total_duration).returns(18000.0)
|
20
|
+
@report.stubs(:total_new_visits).returns(20)
|
21
|
+
@report.stubs(:total_organic_visits).returns(30)
|
22
|
+
@report.stubs(:total_pageviews).returns(100)
|
23
|
+
@report.stubs(:total_ppc_visits).returns(10)
|
24
|
+
@report.stubs(:total_return_visits).returns(90)
|
25
|
+
@report.stubs(:total_search_visits).returns(30)
|
26
|
+
@report.stubs(:total_visits).returns(100)
|
27
|
+
@report.stubs(:total_conversions).returns(20)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'initializes with arguments' do
|
31
|
+
@report.site.should == @args[:site]
|
32
|
+
@report.time_period.should == @args[:time_period]
|
33
|
+
@report.action_kind.should == 'clickthrough'
|
34
|
+
@report.visit_kind.should == 'search'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'calculates its dates' do
|
38
|
+
@report.dates.should == [
|
39
|
+
(Time.zone.now - 2.months).beginning_of_month,
|
40
|
+
(Time.zone.now - 1.months).beginning_of_month,
|
41
|
+
(Time.zone.now).end_of_month,
|
42
|
+
]
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'calculates average pages per visit' do
|
46
|
+
@report.average_pages_per_visit.should == "1.0"
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'calculates average time on site' do
|
50
|
+
@report.average_time_on_site.should == "3.0 minutes"
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'calculates the bounce rate' do
|
54
|
+
@report.bounce_rate.should == "5.0%"
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'calculates the conversion rate' do
|
58
|
+
@report.conversion_rate.should == "20.0%"
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'calculates the total direct visits percentage' do
|
62
|
+
@report.total_direct_visits_percentage.should == "10.0%"
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'calculates the total new visits percentage' do
|
66
|
+
@report.total_new_visits_percentage.should == "20.0%"
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'calculates the total return visits percentage' do
|
70
|
+
@report.total_return_visits_percentage.should == "90.0%"
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'calculates the total organic visits percentage' do
|
74
|
+
@report.total_organic_visits_percentage.should == "30.0%"
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'calculates the total ppc visits percentage' do
|
78
|
+
@report.total_ppc_visits_percentage.should == "10.0%"
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'creates a KeywordStat object from arguments' do
|
82
|
+
_stat = Mitamirri::SessionReport::KeywordStat.new(:keyword => 'foo', :count => 3)
|
83
|
+
_stat.count.should == 3
|
84
|
+
_stat.keyword.should == 'foo'
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'creates a ReferrerStat object from arguments' do
|
88
|
+
_stat = Mitamirri::SessionReport::ReferrerStat.new(:referrer => 'www.foo.com', :count => 3)
|
89
|
+
_stat.count.should == 3
|
90
|
+
_stat.referrer.should == 'www.foo.com'
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'creates a Visit object from arguments' do
|
94
|
+
_visit = Mitamirri::SessionReport::Visit.new(:kind => 'search', :date => Time.zone.now.to_s(:concise), :stats => [])
|
95
|
+
_visit.kind.should == "search"
|
96
|
+
_visit.date.should == Time.zone.now.to_s(:concise)
|
97
|
+
_visit.stats.should == []
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'creates a VisitStat object from arguments' do
|
101
|
+
_stat = Mitamirri::SessionReport::VisitStat.new(:date => Time.zone.now, :visits => 3)
|
102
|
+
_stat.visits.should == 3
|
103
|
+
_stat.date.to_s(:concise).should == Time.zone.now.to_s(:concise)
|
104
|
+
_stat.short_date.should == Time.zone.now.to_s(:month_year)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'mitamirri'
|
3
|
+
|
4
|
+
describe "StatReport" do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
@args = {
|
8
|
+
:site => 'www.foo.com',
|
9
|
+
:time_period => 'past 3 months',
|
10
|
+
:action_kind => 'clickthrough',
|
11
|
+
:visit_kind => 'search'
|
12
|
+
}
|
13
|
+
TrackableSession.stubs(:search).returns([])
|
14
|
+
@report = Mitamirri::StatReport.new(@args)
|
15
|
+
@report.stubs(:total_bounces).returns(5)
|
16
|
+
@report.stubs(:total_clickthroughs).returns(10)
|
17
|
+
@report.stubs(:total_conversions).returns(20)
|
18
|
+
@report.stubs(:total_direct_visits).returns(10)
|
19
|
+
@report.stubs(:total_duration).returns(18000.0)
|
20
|
+
@report.stubs(:total_new_visits).returns(20)
|
21
|
+
@report.stubs(:total_organic_visits).returns(30)
|
22
|
+
@report.stubs(:total_pageviews).returns(100)
|
23
|
+
@report.stubs(:total_ppc_visits).returns(10)
|
24
|
+
@report.stubs(:total_return_visits).returns(90)
|
25
|
+
@report.stubs(:total_search_visits).returns(30)
|
26
|
+
@report.stubs(:total_visits).returns(100)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'initializes with arguments' do
|
30
|
+
@report.site.should == @args[:site]
|
31
|
+
@report.time_period.should == @args[:time_period]
|
32
|
+
@report.action_kind.should == 'clickthrough'
|
33
|
+
@report.visit_kind.should == 'search'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'calculates its dates' do
|
37
|
+
@report.dates.should == [
|
38
|
+
(Time.zone.now - 2.months).beginning_of_month,
|
39
|
+
(Time.zone.now - 1.months).beginning_of_month,
|
40
|
+
(Time.zone.now).end_of_month,
|
41
|
+
]
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'calculates average pages per visit' do
|
45
|
+
@report.average_pages_per_visit.should == "1.0"
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'calculates average time on site' do
|
49
|
+
@report.average_time_on_site.should == "3.0 minutes"
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'calculates the bounce rate' do
|
53
|
+
@report.bounce_rate.should == "5.0%"
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'calculates the conversion rate' do
|
57
|
+
@report.conversion_rate.should == "20.0%"
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'calculates the total direct visits percentage' do
|
61
|
+
@report.total_direct_visits_percentage.should == "10.0%"
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'calculates the total new visits percentage' do
|
65
|
+
@report.total_new_visits_percentage.should == "20.0%"
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'calculates the total return visits percentage' do
|
69
|
+
@report.total_return_visits_percentage.should == "90.0%"
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'calculates the total organic visits percentage' do
|
73
|
+
@report.total_organic_visits_percentage.should == "30.0%"
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'calculates the total ppc visits percentage' do
|
77
|
+
@report.total_ppc_visits_percentage.should == "10.0%"
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'creates a KeywordStat object from arguments' do
|
81
|
+
_stat = Mitamirri::StatReport::KeywordStat.new(:keyword => 'foo', :count => 3)
|
82
|
+
_stat.count.should == 3
|
83
|
+
_stat.keyword.should == 'foo'
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'creates a ReferrerStat object from arguments' do
|
87
|
+
_stat = Mitamirri::StatReport::ReferrerStat.new(:referrer => 'www.foo.com', :count => 3)
|
88
|
+
_stat.count.should == 3
|
89
|
+
_stat.referrer.should == 'www.foo.com'
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'creates a Visit object from arguments' do
|
93
|
+
_visit = Mitamirri::StatReport::Visit.new(:kind => 'search', :date => Time.zone.now.to_s(:concise), :stats => [])
|
94
|
+
_visit.kind.should == "search"
|
95
|
+
_visit.date.should == Time.zone.now.to_s(:concise)
|
96
|
+
_visit.stats.should == []
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'creates a VisitStat object from arguments' do
|
100
|
+
_stat = Mitamirri::StatReport::VisitStat.new(:date => Time.zone.now, :visits => 3)
|
101
|
+
_stat.visits.should == 3
|
102
|
+
_stat.date.to_s(:concise).should == Time.zone.now.to_s(:concise)
|
103
|
+
_stat.short_date.should == Time.zone.now.to_s(:month_year)
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'mitamirri'
|
3
|
+
|
4
|
+
describe "TrackableAction" do
|
5
|
+
|
6
|
+
describe 'creates a new object from parameters' do
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
@new = TrackableAction.create_from_params(
|
10
|
+
:session_id => 123456,
|
11
|
+
:referrer => '/',
|
12
|
+
:ip_address => '123.123.123.1',
|
13
|
+
:site => 'www.seologic.com',
|
14
|
+
:kind => 'click',
|
15
|
+
:label => 'Some Random Click',
|
16
|
+
:url => 'http://www.seologic.com/foo/bar/'
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'with a kind' do
|
21
|
+
@new.kind.should == 'click'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'with a label' do
|
25
|
+
@new.label.should == 'Some Random Click'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'with a referrer' do
|
29
|
+
@new.referrer.should == '/'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'with a URL' do
|
33
|
+
@new.url.should == 'http://www.seologic.com/foo/bar/'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'with an associated trackable session' do
|
37
|
+
@new.trackable_session_id.should_not be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "TrackableSession" do
|
4
|
+
|
5
|
+
describe 'class methods' do
|
6
|
+
|
7
|
+
it 'calculates conversion rates' do
|
8
|
+
TrackableSession.stubs(:search).returns(TrackableSession.new)
|
9
|
+
TrackableSession.any_instance.stubs(:with_conversions).returns(TrackableSession.new(:has_conversions => true))
|
10
|
+
TrackableSession.any_instance.stubs(:count).returns(1)
|
11
|
+
|
12
|
+
TrackableSession.conversion_rate({}).should == 100
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns kinds suitably formatted for a select' do
|
16
|
+
TrackableSession.kinds_for_select.should == [["All", "all"], ["Direct", "direct"], ["Natural", "natural"], ["Paid", "paid"], ["Search", "search"]]
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'instance methods' do
|
23
|
+
|
24
|
+
describe 'initializes' do
|
25
|
+
|
26
|
+
it 'defaulting its new_visit flag to true' do
|
27
|
+
TrackableSession.stubs(:find_by_ip_address).returns(nil)
|
28
|
+
_new_session = TrackableSession.new(:ip_address => '192.1.1.5')
|
29
|
+
_new_session.init
|
30
|
+
_new_session.new_visit.should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'detecting a return visit' do
|
34
|
+
TrackableSession.stubs(:find_by_ip_address).returns(['a record'])
|
35
|
+
_new_session = TrackableSession.new(:ip_address => '192.1.1.5')
|
36
|
+
_new_session.init
|
37
|
+
_new_session.new_visit.should be_false
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'detecting a visit from a spider' do
|
41
|
+
# Human user agents
|
42
|
+
[
|
43
|
+
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0",
|
44
|
+
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
|
45
|
+
"Opera/9.20 (Windows NT 6.0; U; en)",
|
46
|
+
"Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/533.17.8 (KHTML, like Gecko) Version/5.0.1 Safari/533.17.8"
|
47
|
+
].each do |ua|
|
48
|
+
_session = TrackableSession.new(:user_agent => ua)
|
49
|
+
_session.init
|
50
|
+
_session.spider?.should be_false
|
51
|
+
end
|
52
|
+
# Bots
|
53
|
+
[
|
54
|
+
"Googlebot/2.1 ( http://www.googlebot.com/bot.html) ",
|
55
|
+
"msnbot-Products/1.0 (+http://search.msn.com/msnbot.htm)",
|
56
|
+
].each do |ua|
|
57
|
+
_session = TrackableSession.new(:user_agent => ua)
|
58
|
+
_session.init
|
59
|
+
_session.spider?.should be_true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'setting its kind' do
|
64
|
+
_new_session = TrackableSession.new
|
65
|
+
_new_session.init
|
66
|
+
_new_session.kind.should_not be_nil
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'calculates its duration in seconds' do
|
72
|
+
TrackableSession.new(:duration => 30).hr_duration.should == '30.0 seconds'
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'calculates its duration in minutes' do
|
76
|
+
TrackableSession.new(:duration => 90).hr_duration.should == '1.5 minutes'
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'it sanitizes referring keywords' do
|
80
|
+
_session = TrackableSession.new(:referring_keywords => 'some+keywords+here')
|
81
|
+
_session.sanitize_referring_keywords.should == 'some keywords here'
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns the date of the last previous visit' do
|
85
|
+
_first = TrackableSession.create(:ip_address => '90.1.2.3', :created_at => Time.zone.now - 2.months)
|
86
|
+
_second = TrackableSession.create(:ip_address => '90.1.2.3', :created_at => Time.zone.now - 1.months)
|
87
|
+
_third = TrackableSession.create(:ip_address => '90.1.2.3', :created_at => Time.zone.now)
|
88
|
+
_third.last_visit_date.should == _second.created_at.to_s(:concise)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'updates its timestamp' do
|
92
|
+
_then = Time.zone.now - 30.seconds
|
93
|
+
_session = TrackableSession.new(:created_at => _then)
|
94
|
+
_session.stubs(:save).returns(true)
|
95
|
+
_session.stubs(:touch_stat).returns(true)
|
96
|
+
sleep(1)
|
97
|
+
_session.touch
|
98
|
+
(_session.updated_at > _then).should be_true
|
99
|
+
end
|
100
|
+
|
101
|
+
it "returns visit_type of 'New' if it's a new visit" do
|
102
|
+
TrackableSession.new(:new_visit => true).visit_type.should == 'New'
|
103
|
+
end
|
104
|
+
|
105
|
+
it "returns visit_type of 'Returning' if it's not a new visit" do
|
106
|
+
TrackableSession.new(:new_visit => nil).visit_type.should == 'Returning'
|
107
|
+
end
|
108
|
+
|
109
|
+
describe 'sets its kind by referrer' do
|
110
|
+
|
111
|
+
it 'with a search engine referrer' do
|
112
|
+
TrackableSession.new(:referrer => 'http://www.google.com/search/').kind_by_referrer.should == 'search'
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'with an organic referrer' do
|
116
|
+
TrackableSession.new(:referrer => 'http://www.seologic.com/foo.htm').kind_by_referrer.should == 'natural'
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'with a PPC referrer' do
|
120
|
+
TrackableSession.new(
|
121
|
+
:initial_request_url => 'http://www.seologic.com/foo.htm?gclid=1234',
|
122
|
+
:referrer => 'http://www.foo.com/'
|
123
|
+
).kind_by_referrer.should == 'paid'
|
124
|
+
TrackableSession.new(
|
125
|
+
:initial_request_url => 'http://www.seologic.com/foo.htm?keyword=1234',
|
126
|
+
:referrer => 'http://www.foo.com/'
|
127
|
+
).kind_by_referrer.should == 'paid'
|
128
|
+
TrackableSession.new(
|
129
|
+
:initial_request_url => 'http://www.seologic.com/foo.htm?adid=1234',
|
130
|
+
:referrer => 'http://www.foo.com/'
|
131
|
+
).kind_by_referrer.should == 'paid'
|
132
|
+
TrackableSession.new(
|
133
|
+
:initial_request_url => 'http://www.seologic.com/foo.htm?matchtype=1234',
|
134
|
+
:referrer => 'http://www.foo.com/'
|
135
|
+
).kind_by_referrer.should == 'paid'
|
136
|
+
TrackableSession.new(
|
137
|
+
:initial_request_url => 'http://www.seologic.com/foo.htm?ppc=1234',
|
138
|
+
:referrer => 'http://www.foo.com/'
|
139
|
+
).kind_by_referrer.should == 'paid'
|
140
|
+
TrackableSession.new(
|
141
|
+
:initial_request_url => 'http://www.seologic.com/foo.htm?cpc=1234',
|
142
|
+
:referrer => 'http://www.foo.com/'
|
143
|
+
).kind_by_referrer.should == 'paid'
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'with no referrer' do
|
147
|
+
TrackableSession.new(:referrer => nil).kind_by_referrer.should == 'direct'
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|