analytical 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +5 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/analytical.gemspec +12 -3
- data/example/config/analytical.yml +7 -1
- data/lib/analytical/api.rb +9 -2
- data/lib/analytical/base.rb +5 -1
- data/lib/analytical/chartbeat.rb +49 -0
- data/lib/analytical/comscore.rb +25 -0
- data/lib/analytical/google.rb +9 -9
- data/lib/analytical/optimizely.rb +23 -0
- data/spec/analytical/api_spec.rb +17 -5
- data/spec/analytical/chartbeat_spec.rb +38 -0
- data/spec/analytical/clicky_spec.rb +2 -1
- data/spec/analytical/comscore_spec.rb +41 -0
- data/spec/analytical/google_spec.rb +8 -6
- data/spec/analytical/kiss_metrics_spec.rb +12 -11
- data/spec/analytical/optimizely_spec.rb +40 -0
- data/spec/analytical_spec.rb +2 -1
- data/spec/config/analytical.yml +3 -0
- metadata +14 -4
data/README.rdoc
CHANGED
@@ -9,6 +9,9 @@ Service implementations include:
|
|
9
9
|
* KISSMetrics[http://kissmetrics.com]
|
10
10
|
* Hubspot[http://hubspot.com]
|
11
11
|
* CrazyEgg[http://www.crazyegg.com]
|
12
|
+
* Chartbeat[http://chartbeat.com]
|
13
|
+
* comScore Direct[http://direct.comscore.com]
|
14
|
+
* Optimizely[http://www.optimizely.com]
|
12
15
|
|
13
16
|
== Usage
|
14
17
|
|
@@ -28,12 +31,13 @@ Then, in your template files, you'll want to add the analytical helper methods f
|
|
28
31
|
<!DOCTYPE html>
|
29
32
|
<html>
|
30
33
|
<head>
|
34
|
+
<%= raw analytical.head_prepend_javascript %>
|
31
35
|
<title>Example</title>
|
32
36
|
<%= stylesheet_link_tag :all %>
|
33
37
|
<%= javascript_include_tag :defaults %>
|
34
38
|
<%= csrf_meta_tag %>
|
35
39
|
<% analytical.identify '5', :email=>'josh@transfs.com' %>
|
36
|
-
<%= raw analytical.
|
40
|
+
<%= raw analytical.head_append_javascript %>
|
37
41
|
</head>
|
38
42
|
<body>
|
39
43
|
<%= raw analytical.body_prepend_javascript %>
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ begin
|
|
9
9
|
gem.description = %Q{Gem for managing multiple analytics services in your rails app.}
|
10
10
|
gem.email = "josh@transfs.com"
|
11
11
|
gem.homepage = "http://github.com/jkrall/analytical"
|
12
|
-
gem.authors = ["Joshua Krall"]
|
12
|
+
gem.authors = ["Joshua Krall", "Nathan Phelps"]
|
13
13
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
14
|
gem.add_dependency "activesupport"
|
15
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/analytical.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{analytical}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Joshua Krall"]
|
12
|
-
s.date = %q{2010-
|
11
|
+
s.authors = ["Joshua Krall", "Nathan Phelps"]
|
12
|
+
s.date = %q{2010-08-22}
|
13
13
|
s.description = %q{Gem for managing multiple analytics services in your rails app.}
|
14
14
|
s.email = %q{josh@transfs.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -79,19 +79,25 @@ Gem::Specification.new do |s|
|
|
79
79
|
"lib/analytical/api.rb",
|
80
80
|
"lib/analytical/base.rb",
|
81
81
|
"lib/analytical/bot_detector.rb",
|
82
|
+
"lib/analytical/chartbeat.rb",
|
82
83
|
"lib/analytical/clicky.rb",
|
84
|
+
"lib/analytical/comscore.rb",
|
83
85
|
"lib/analytical/console.rb",
|
84
86
|
"lib/analytical/crazy_egg.rb",
|
85
87
|
"lib/analytical/google.rb",
|
86
88
|
"lib/analytical/hubspot.rb",
|
87
89
|
"lib/analytical/kiss_metrics.rb",
|
90
|
+
"lib/analytical/optimizely.rb",
|
88
91
|
"rails/init.rb",
|
89
92
|
"spec/analytical/api_spec.rb",
|
90
93
|
"spec/analytical/base_spec.rb",
|
91
94
|
"spec/analytical/bot_detector_spec.rb",
|
95
|
+
"spec/analytical/chartbeat_spec.rb",
|
92
96
|
"spec/analytical/clicky_spec.rb",
|
97
|
+
"spec/analytical/comscore_spec.rb",
|
93
98
|
"spec/analytical/google_spec.rb",
|
94
99
|
"spec/analytical/kiss_metrics_spec.rb",
|
100
|
+
"spec/analytical/optimizely_spec.rb",
|
95
101
|
"spec/analytical_spec.rb",
|
96
102
|
"spec/config/analytical.yml",
|
97
103
|
"spec/spec.opts",
|
@@ -106,9 +112,12 @@ Gem::Specification.new do |s|
|
|
106
112
|
"spec/analytical/api_spec.rb",
|
107
113
|
"spec/analytical/base_spec.rb",
|
108
114
|
"spec/analytical/bot_detector_spec.rb",
|
115
|
+
"spec/analytical/chartbeat_spec.rb",
|
109
116
|
"spec/analytical/clicky_spec.rb",
|
117
|
+
"spec/analytical/comscore_spec.rb",
|
110
118
|
"spec/analytical/google_spec.rb",
|
111
119
|
"spec/analytical/kiss_metrics_spec.rb",
|
120
|
+
"spec/analytical/optimizely_spec.rb",
|
112
121
|
"spec/analytical_spec.rb",
|
113
122
|
"spec/spec_helper.rb"
|
114
123
|
]
|
data/lib/analytical/api.rb
CHANGED
@@ -49,9 +49,16 @@ module Analytical
|
|
49
49
|
#
|
50
50
|
# These methods return the javascript that should be inserted into each section of your layout
|
51
51
|
#
|
52
|
-
def
|
53
|
-
[init_javascript(:
|
52
|
+
def head_prepend_javascript
|
53
|
+
[init_javascript(:head_prepend), tracking_javascript(:head_prepend)].delete_if{|s| s.blank?}.join("\n")
|
54
54
|
end
|
55
|
+
|
56
|
+
def head_append_javascript
|
57
|
+
[init_javascript(:head_append), tracking_javascript(:head_append)].delete_if{|s| s.blank?}.join("\n")
|
58
|
+
end
|
59
|
+
|
60
|
+
alias_method :head_javascript, :head_append_javascript
|
61
|
+
|
55
62
|
def body_prepend_javascript
|
56
63
|
[init_javascript(:body_prepend), tracking_javascript(:body_prepend)].delete_if{|s| s.blank?}.join("\n")
|
57
64
|
end
|
data/lib/analytical/base.rb
CHANGED
@@ -46,7 +46,11 @@ module Analytical
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def init_location?(location)
|
49
|
-
@tracking_command_location
|
49
|
+
if @tracking_command_location.is_a?(Array)
|
50
|
+
@tracking_command_location.map { |item|item.to_sym }.include?(location.to_sym)
|
51
|
+
else
|
52
|
+
@tracking_command_location.to_sym == location.to_sym
|
53
|
+
end
|
50
54
|
end
|
51
55
|
|
52
56
|
def init_location(location, &block)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Chartbeat
|
3
|
+
class Api
|
4
|
+
include Analytical::Base::Api
|
5
|
+
|
6
|
+
def initialize(parent, options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = [:head_prepend, :body_append]
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
case location.to_sym
|
14
|
+
when :head_prepend
|
15
|
+
js = <<-HTML
|
16
|
+
<!-- Analytical Head Init: Chartbeat -->
|
17
|
+
<script type="text/javascript">var _sf_startpt=(new Date()).getTime();</script>
|
18
|
+
HTML
|
19
|
+
js
|
20
|
+
when :body_append
|
21
|
+
js = <<-HTML
|
22
|
+
<!-- Analytical Body Init: Chartbeat -->
|
23
|
+
<script type="text/javascript">
|
24
|
+
var _sf_async_config={uid:#{options[:key]}, domain:"#{options[:domain]}"};
|
25
|
+
(function(){
|
26
|
+
function loadChartbeat() {
|
27
|
+
window._sf_endpt=(new Date()).getTime();
|
28
|
+
var e = document.createElement('script');
|
29
|
+
e.setAttribute('language', 'javascript');
|
30
|
+
e.setAttribute('type', 'text/javascript');
|
31
|
+
e.setAttribute('src',
|
32
|
+
(("https:" == document.location.protocol) ? "https://s3.amazonaws.com/" : "http://") +
|
33
|
+
"static.chartbeat.com/js/chartbeat.js");
|
34
|
+
document.body.appendChild(e);
|
35
|
+
}
|
36
|
+
var oldonload = window.onload;
|
37
|
+
window.onload = (typeof window.onload != 'function') ?
|
38
|
+
loadChartbeat : function() { oldonload(); loadChartbeat(); };
|
39
|
+
})();
|
40
|
+
</script>
|
41
|
+
HTML
|
42
|
+
js
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Comscore
|
3
|
+
class Api
|
4
|
+
include Analytical::Base::Api
|
5
|
+
|
6
|
+
def initialize(parent, options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = :head_append
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
js = <<-HTML
|
14
|
+
<!-- Analytical Init: comScore -->
|
15
|
+
<script>document.write(unescape("%3Cscript src='" + (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js' %3E%3C/script%3E"));</script>
|
16
|
+
<script>COMSCORE.beacon({c1:2, c2:#{options[:key]}, c3:"", c4:"", c5:"", c6:"", c15:""});</script>
|
17
|
+
<noscript><img src="http://b.scorecardresearch.com/p?c1=2&c2=#{options[:key]}&c3=&c4=&c5=&c6=&c15=&cj=1" /></noscript>
|
18
|
+
HTML
|
19
|
+
js
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/analytical/google.rb
CHANGED
@@ -5,7 +5,7 @@ module Analytical
|
|
5
5
|
|
6
6
|
def initialize(parent, options={})
|
7
7
|
super
|
8
|
-
@tracking_command_location = :
|
8
|
+
@tracking_command_location = :head_append
|
9
9
|
end
|
10
10
|
|
11
11
|
def init_javascript(location)
|
@@ -13,13 +13,13 @@ module Analytical
|
|
13
13
|
js = <<-HTML
|
14
14
|
<!-- Analytical Init: Google -->
|
15
15
|
<script type="text/javascript">
|
16
|
-
var
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
var _gaq = _gaq || [];
|
17
|
+
_gaq.push(['_setAccount', '#{options[:key]}'], ['_trackPageview']);
|
18
|
+
(function() {
|
19
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
20
|
+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
21
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
22
|
+
})();
|
23
23
|
</script>
|
24
24
|
HTML
|
25
25
|
js
|
@@ -27,7 +27,7 @@ module Analytical
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def track(*args)
|
30
|
-
"
|
30
|
+
"_gaq.push(['_trackPageview'#{args.empty? ? ']' : ', "' + args.first + '"]'});"
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Optimizely
|
3
|
+
class Api
|
4
|
+
include Analytical::Base::Api
|
5
|
+
|
6
|
+
def initialize(parent, options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = :head_prepend
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
js = <<-HTML
|
14
|
+
<!-- Analytical Init: Optimizely -->
|
15
|
+
<script type="text/javascript">document.write(unescape("%3Cscript src='"+document.location.protocol+"//cdn.optimizely.com/js/#{options[:key]}.js' type='text/javascript'%3E%3C/script%3E"));</script>
|
16
|
+
HTML
|
17
|
+
js
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/analytical/api_spec.rb
CHANGED
@@ -19,6 +19,7 @@ describe "Analytical::Api" do
|
|
19
19
|
Analytical::Console::Api.stub!(:new).and_return(@console = mock('console'))
|
20
20
|
Analytical::Google::Api.stub!(:new).and_return(@google = mock('google'))
|
21
21
|
Analytical::Clicky::Api.stub!(:new).and_return(@clicky = mock('clicky'))
|
22
|
+
Analytical::Chartbeat::Api.stub!(:new).and_return(@chartbeat = mock('chartbeat'))
|
22
23
|
|
23
24
|
@api = Analytical::Api.new :modules=>[:console, :google]
|
24
25
|
end
|
@@ -61,10 +62,11 @@ describe "Analytical::Api" do
|
|
61
62
|
|
62
63
|
describe 'when accessing a module by name' do
|
63
64
|
it 'should return the module api object' do
|
64
|
-
@api = Analytical::Api.new :modules=>[:console, :google, :clicky]
|
65
|
+
@api = Analytical::Api.new :modules=>[:console, :google, :clicky, :chartbeat]
|
65
66
|
@api.console.should == @console
|
66
67
|
@api.clicky.should == @clicky
|
67
68
|
@api.google.should == @google
|
69
|
+
@api.chartbeat.should == @chartbeat
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
@@ -77,13 +79,23 @@ describe "Analytical::Api" do
|
|
77
79
|
@google.stub!(:initialized).and_return(false)
|
78
80
|
@google.stub!(:process_queued_commands).and_return([])
|
79
81
|
end
|
80
|
-
|
82
|
+
|
83
|
+
describe '#head_prepend_javascript' do
|
84
|
+
it 'should return the javascript' do
|
85
|
+
@console.should_receive(:init_javascript).with(:head_prepend).and_return('console_a')
|
86
|
+
@google.should_receive(:init_javascript).with(:head_prepend).and_return('google_a')
|
87
|
+
@api.head_prepend_javascript.should == "console_a\ngoogle_a"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#head_append_javascript' do
|
81
92
|
it 'should return the javascript' do
|
82
|
-
@console.should_receive(:init_javascript).with(:
|
83
|
-
@google.should_receive(:init_javascript).with(:
|
84
|
-
@api.
|
93
|
+
@console.should_receive(:init_javascript).with(:head_append).and_return('console_a')
|
94
|
+
@google.should_receive(:init_javascript).with(:head_append).and_return('google_a')
|
95
|
+
@api.head_append_javascript.should == "console_a\ngoogle_a"
|
85
96
|
end
|
86
97
|
end
|
98
|
+
|
87
99
|
describe '#body_prepend_javascript' do
|
88
100
|
it 'should return the javascript' do
|
89
101
|
@console.should_receive(:init_javascript).with(:body_prepend).and_return('console_b')
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Analytical::Chartbeat::Api" do
|
4
|
+
before(:each) do
|
5
|
+
@parent = mock('api', :options=>{:chartbeat=>{:key=>1234, :domain =>'test.com'}})
|
6
|
+
end
|
7
|
+
describe 'on initialize' do
|
8
|
+
it 'should set the command_location' do
|
9
|
+
a = Analytical::Chartbeat::Api.new @parent, {:key=>1234}
|
10
|
+
a.tracking_command_location.should == [:head_prepend, :body_append]
|
11
|
+
end
|
12
|
+
it 'should set the options' do
|
13
|
+
a = Analytical::Chartbeat::Api.new @parent, {:key=>12345, :domain =>'abcdef.com'}
|
14
|
+
a.options.should == {:key=>12345, :domain => 'abcdef.com'}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe '#track' do
|
18
|
+
it 'should return the tracking javascript' do
|
19
|
+
@api = Analytical::Chartbeat::Api.new @parent, {:key=>12345}
|
20
|
+
@api.track.should == ''
|
21
|
+
end
|
22
|
+
end
|
23
|
+
describe '#identify' do
|
24
|
+
it 'should return an empty string' do
|
25
|
+
@api = Analytical::Chartbeat::Api.new @parent, {:key=>12345}
|
26
|
+
@api.identify('nothing', {:matters=>'at all'}).should == ''
|
27
|
+
end
|
28
|
+
end
|
29
|
+
describe '#init_javascript' do
|
30
|
+
it 'should return the init javascript' do
|
31
|
+
@api = Analytical::Chartbeat::Api.new @parent, {:key=>12345, :domain =>'abcdef.com'}
|
32
|
+
@api.init_javascript(:head_prepend).should =~ /_sf_startpt=\(new.Date\(\)\)\.getTime\(\);/
|
33
|
+
@api.init_javascript(:head_append).should == ''
|
34
|
+
@api.init_javascript(:body_prepend).should == ''
|
35
|
+
@api.init_javascript(:body_append).should =~ /_sf_async_config=\{uid:12345,.*domain:"abcdef\.com"\};/
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -29,7 +29,8 @@ describe "Analytical::Clicky::Api" do
|
|
29
29
|
describe '#init_javascript' do
|
30
30
|
it 'should return the init javascript' do
|
31
31
|
@api = Analytical::Clicky::Api.new @parent, {:key=>'abcdef'}
|
32
|
-
@api.init_javascript(:
|
32
|
+
@api.init_javascript(:head_prepend).should == ''
|
33
|
+
@api.init_javascript(:head_append).should == ''
|
33
34
|
@api.init_javascript(:body_prepend).should == ''
|
34
35
|
@api.init_javascript(:body_append).should =~ /static.getclicky.com\/js/
|
35
36
|
@api.init_javascript(:body_append).should =~ /abcdef/
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Analytical::Comscore::Api" do
|
4
|
+
before(:each) do
|
5
|
+
@parent = mock('api', :options=>{:comscore=>{:key=>123}})
|
6
|
+
end
|
7
|
+
describe 'on initialize' do
|
8
|
+
it 'should set the command_location' do
|
9
|
+
a = Analytical::Comscore::Api.new @parent, {:key=>123}
|
10
|
+
a.tracking_command_location.should == :head_append
|
11
|
+
end
|
12
|
+
it 'should set the options' do
|
13
|
+
a = Analytical::Comscore::Api.new @parent, {:key=>1234}
|
14
|
+
a.options.should == {:key=>1234}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe '#track' do
|
18
|
+
it 'should return the tracking javascript' do
|
19
|
+
@api = Analytical::Comscore::Api.new @parent, {:key=>123}
|
20
|
+
@api.track('pagename', {:some=>'data'}).should == ''
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#identify' do
|
25
|
+
it 'should return an empty string' do
|
26
|
+
@api = Analytical::Comscore::Api.new @parent, {:key=>123}
|
27
|
+
@api.identify('nothing', {:matters=>'at all'}).should == ''
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#init_javascript' do
|
32
|
+
it 'should return the init javascript' do
|
33
|
+
@api = Analytical::Comscore::Api.new @parent, {:key=>1234}
|
34
|
+
@api.init_javascript(:head_prepend).should == ''
|
35
|
+
@api.init_javascript(:head_append).should =~ /scorecardresearch.com\/beacon.js/
|
36
|
+
@api.init_javascript(:head_append).should =~ /1234/
|
37
|
+
@api.init_javascript(:body_prepend).should == ''
|
38
|
+
@api.init_javascript(:body_append).should == ''
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -7,7 +7,7 @@ describe "Analytical::Google::Api" do
|
|
7
7
|
describe 'on initialize' do
|
8
8
|
it 'should set the command_location' do
|
9
9
|
a = Analytical::Google::Api.new @parent, {:key=>'abc'}
|
10
|
-
a.tracking_command_location.should == :
|
10
|
+
a.tracking_command_location.should == :head_append
|
11
11
|
end
|
12
12
|
it 'should set the options' do
|
13
13
|
a = Analytical::Google::Api.new @parent, {:key=>'abc'}
|
@@ -17,7 +17,8 @@ describe "Analytical::Google::Api" do
|
|
17
17
|
describe '#track' do
|
18
18
|
it 'should return the tracking javascript' do
|
19
19
|
@api = Analytical::Google::Api.new @parent, {:key=>'abcdef'}
|
20
|
-
@api.track
|
20
|
+
@api.track.should == "_gaq.push(['_trackPageview']);"
|
21
|
+
@api.track('pagename', {:some=>'data'}).should == "_gaq.push(['_trackPageview', \"pagename\"]);"
|
21
22
|
end
|
22
23
|
end
|
23
24
|
describe '#identify' do
|
@@ -29,10 +30,11 @@ describe "Analytical::Google::Api" do
|
|
29
30
|
describe '#init_javascript' do
|
30
31
|
it 'should return the init javascript' do
|
31
32
|
@api = Analytical::Google::Api.new @parent, {:key=>'abcdef'}
|
32
|
-
@api.init_javascript(:
|
33
|
-
@api.init_javascript(:
|
34
|
-
@api.init_javascript(:
|
33
|
+
@api.init_javascript(:head_prepend).should == ''
|
34
|
+
@api.init_javascript(:head_append).should =~ /abcdef/
|
35
|
+
@api.init_javascript(:head_append).should =~ /google-analytics.com\/ga.js/
|
36
|
+
@api.init_javascript(:body_prepend).should == ''
|
35
37
|
@api.init_javascript(:body_append).should == ''
|
36
38
|
end
|
37
39
|
end
|
38
|
-
end
|
40
|
+
end
|
@@ -2,47 +2,48 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe "Analytical::KissMetrics::Api" do
|
4
4
|
before(:each) do
|
5
|
-
@parent = mock('api', :options=>{:google=>{:
|
5
|
+
@parent = mock('api', :options=>{:google=>{:js_url_key=>'abc'}})
|
6
6
|
end
|
7
7
|
describe 'on initialize' do
|
8
8
|
it 'should set the command_location' do
|
9
|
-
a = Analytical::KissMetrics::Api.new @parent, {:
|
9
|
+
a = Analytical::KissMetrics::Api.new @parent, {:js_url_key=>'abc'}
|
10
10
|
a.tracking_command_location.should == :body_prepend
|
11
11
|
end
|
12
12
|
it 'should set the options' do
|
13
|
-
a = Analytical::KissMetrics::Api.new @parent, {:
|
14
|
-
a.options.should == {:
|
13
|
+
a = Analytical::KissMetrics::Api.new @parent, {:js_url_key=>'abc'}
|
14
|
+
a.options.should == {:js_url_key=>'abc'}
|
15
15
|
end
|
16
16
|
end
|
17
17
|
describe '#track' do
|
18
18
|
it 'should return the tracking javascript' do
|
19
|
-
@api = Analytical::KissMetrics::Api.new @parent, {:
|
19
|
+
@api = Analytical::KissMetrics::Api.new @parent, {:js_url_key=>'abcdef'}
|
20
20
|
@api.track('pagename', {:some=>'data'}).should == ''
|
21
21
|
end
|
22
22
|
end
|
23
23
|
describe '#identify' do
|
24
24
|
it 'should return a js string' do
|
25
|
-
@api = Analytical::KissMetrics::Api.new @parent, {:
|
25
|
+
@api = Analytical::KissMetrics::Api.new @parent, {:js_url_key=>'abcdef'}
|
26
26
|
@api.identify('id', {:email=>'test@test.com'}).should == "_kmq.push([\"identify\", \"test@test.com\"]);"
|
27
27
|
end
|
28
28
|
end
|
29
29
|
describe '#event' do
|
30
30
|
it 'should return a js string' do
|
31
|
-
@api = Analytical::KissMetrics::Api.new @parent, {:
|
31
|
+
@api = Analytical::KissMetrics::Api.new @parent, {:js_url_key=>'abcdef'}
|
32
32
|
@api.event('Big Deal', {:something=>'good'}).should == "_kmq.push([\"record\", \"Big Deal\", #{{:something=>'good'}.to_json}]);"
|
33
33
|
end
|
34
34
|
end
|
35
35
|
describe '#set' do
|
36
36
|
it 'should return a js string' do
|
37
|
-
@api = Analytical::KissMetrics::Api.new @parent, {:
|
37
|
+
@api = Analytical::KissMetrics::Api.new @parent, {:js_url_key=>'abcdef'}
|
38
38
|
@api.set({:something=>'good', :b=>2}).should == "_kmq.push([\"set\", #{{:something=>'good', :b=>2}.to_json}]);"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
describe '#init_javascript' do
|
42
42
|
it 'should return the init javascript' do
|
43
|
-
@api = Analytical::KissMetrics::Api.new @parent, {:
|
44
|
-
@api.init_javascript(:
|
45
|
-
@api.init_javascript(:
|
43
|
+
@api = Analytical::KissMetrics::Api.new @parent, {:js_url_key=>'abcdef'}
|
44
|
+
@api.init_javascript(:head_prepend).should == ''
|
45
|
+
@api.init_javascript(:head_append).should == ''
|
46
|
+
@api.init_javascript(:body_prepend).should =~ /i\.kissmetrics\.com/
|
46
47
|
@api.init_javascript(:body_prepend).should =~ /abcdef/
|
47
48
|
@api.init_javascript(:body_append).should == ''
|
48
49
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Analytical::Optimizely::Api" do
|
4
|
+
before(:each) do
|
5
|
+
@parent = mock('api', :options=>{:optimizely=>{:key=>'abc'}})
|
6
|
+
end
|
7
|
+
describe 'on initialize' do
|
8
|
+
it 'should set the command_location' do
|
9
|
+
a = Analytical::Optimizely::Api.new @parent, {:key=>'abc'}
|
10
|
+
a.tracking_command_location.should == :head_prepend
|
11
|
+
end
|
12
|
+
it 'should set the options' do
|
13
|
+
a = Analytical::Optimizely::Api.new @parent, {:key=>'abc'}
|
14
|
+
a.options.should == {:key=>'abc'}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe '#track' do
|
18
|
+
it 'should return the tracking javascript' do
|
19
|
+
@api = Analytical::Optimizely::Api.new @parent, {:key=>'abcdef'}
|
20
|
+
@api.track('pagename', {:some=>'data'}).should == ''
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#identify' do
|
25
|
+
it 'should return an empty string' do
|
26
|
+
@api = Analytical::Optimizely::Api.new @parent, {:key=>'abcdef'}
|
27
|
+
@api.identify('nothing', {:matters=>'at all'}).should == ''
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#init_javascript' do
|
32
|
+
it 'should return the init javascript' do
|
33
|
+
@api = Analytical::Optimizely::Api.new @parent, {:key=>'abcdef'}
|
34
|
+
@api.init_javascript(:head_prepend).should =~ /cdn\.optimizely.com\/js\/abcdef\.js/
|
35
|
+
@api.init_javascript(:head_append).should == ''
|
36
|
+
@api.init_javascript(:body_prepend).should == ''
|
37
|
+
@api.init_javascript(:body_append).should == ''
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/analytical_spec.rb
CHANGED
@@ -49,7 +49,8 @@ describe "Analytical" do
|
|
49
49
|
DummyForInit.analytical
|
50
50
|
DummyForInit.analytical_options[:google].should == {:key=>'google_12345'}
|
51
51
|
DummyForInit.analytical_options[:kiss_metrics].should == {:key=>'kiss_metrics_12345'}
|
52
|
-
DummyForInit.analytical_options[:clicky].should == {:key=>'clicky_12345'}
|
52
|
+
DummyForInit.analytical_options[:clicky].should == {:key=>'clicky_12345'}
|
53
|
+
DummyForInit.analytical_options[:chartbeat].should == {:key=>'chartbeat_12345', :domain => 'your.domain.com'}
|
53
54
|
end
|
54
55
|
|
55
56
|
describe 'in production mode' do
|
data/spec/config/analytical.yml
CHANGED
metadata
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: analytical
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joshua Krall
|
14
|
+
- Nathan Phelps
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-
|
19
|
+
date: 2010-08-22 00:00:00 -05:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
@@ -120,19 +121,25 @@ files:
|
|
120
121
|
- lib/analytical/api.rb
|
121
122
|
- lib/analytical/base.rb
|
122
123
|
- lib/analytical/bot_detector.rb
|
124
|
+
- lib/analytical/chartbeat.rb
|
123
125
|
- lib/analytical/clicky.rb
|
126
|
+
- lib/analytical/comscore.rb
|
124
127
|
- lib/analytical/console.rb
|
125
128
|
- lib/analytical/crazy_egg.rb
|
126
129
|
- lib/analytical/google.rb
|
127
130
|
- lib/analytical/hubspot.rb
|
128
131
|
- lib/analytical/kiss_metrics.rb
|
132
|
+
- lib/analytical/optimizely.rb
|
129
133
|
- rails/init.rb
|
130
134
|
- spec/analytical/api_spec.rb
|
131
135
|
- spec/analytical/base_spec.rb
|
132
136
|
- spec/analytical/bot_detector_spec.rb
|
137
|
+
- spec/analytical/chartbeat_spec.rb
|
133
138
|
- spec/analytical/clicky_spec.rb
|
139
|
+
- spec/analytical/comscore_spec.rb
|
134
140
|
- spec/analytical/google_spec.rb
|
135
141
|
- spec/analytical/kiss_metrics_spec.rb
|
142
|
+
- spec/analytical/optimizely_spec.rb
|
136
143
|
- spec/analytical_spec.rb
|
137
144
|
- spec/config/analytical.yml
|
138
145
|
- spec/spec.opts
|
@@ -175,8 +182,11 @@ test_files:
|
|
175
182
|
- spec/analytical/api_spec.rb
|
176
183
|
- spec/analytical/base_spec.rb
|
177
184
|
- spec/analytical/bot_detector_spec.rb
|
185
|
+
- spec/analytical/chartbeat_spec.rb
|
178
186
|
- spec/analytical/clicky_spec.rb
|
187
|
+
- spec/analytical/comscore_spec.rb
|
179
188
|
- spec/analytical/google_spec.rb
|
180
189
|
- spec/analytical/kiss_metrics_spec.rb
|
190
|
+
- spec/analytical/optimizely_spec.rb
|
181
191
|
- spec/analytical_spec.rb
|
182
192
|
- spec/spec_helper.rb
|