gsiener-analytical 2.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +56 -0
- data/Guardfile +8 -0
- data/LICENSE +20 -0
- data/README.rdoc +117 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/analytical.gemspec +183 -0
- data/example/.gitignore +4 -0
- data/example/Gemfile +27 -0
- data/example/Gemfile.lock +80 -0
- data/example/README +244 -0
- data/example/Rakefile +10 -0
- data/example/app/controllers/application_controller.rb +6 -0
- data/example/app/controllers/page_controller.rb +18 -0
- data/example/app/helpers/application_helper.rb +2 -0
- data/example/app/helpers/page_helper.rb +2 -0
- data/example/app/views/layouts/application.html.erb +17 -0
- data/example/app/views/page/index.html.erb +6 -0
- data/example/app/views/page/test_a.html.erb +11 -0
- data/example/app/views/page/test_b.html.erb +7 -0
- data/example/config/analytical.yml +30 -0
- data/example/config/application.rb +46 -0
- data/example/config/boot.rb +6 -0
- data/example/config/database.yml +22 -0
- data/example/config/environment.rb +7 -0
- data/example/config/environments/development.rb +21 -0
- data/example/config/environments/production.rb +42 -0
- data/example/config/environments/test.rb +32 -0
- data/example/config/initializers/backtrace_silencers.rb +7 -0
- data/example/config/initializers/inflections.rb +10 -0
- data/example/config/initializers/mime_types.rb +5 -0
- data/example/config/initializers/secret_token.rb +7 -0
- data/example/config/initializers/session_store.rb +8 -0
- data/example/config/locales/en.yml +5 -0
- data/example/config/routes.rb +63 -0
- data/example/config.ru +4 -0
- data/example/db/seeds.rb +7 -0
- data/example/doc/README_FOR_APP +2 -0
- data/example/lib/tasks/.gitkeep +0 -0
- data/example/public/404.html +26 -0
- data/example/public/422.html +26 -0
- data/example/public/500.html +26 -0
- data/example/public/favicon.ico +0 -0
- data/example/public/images/rails.png +0 -0
- data/example/public/javascripts/application.js +2 -0
- data/example/public/javascripts/controls.js +965 -0
- data/example/public/javascripts/dragdrop.js +974 -0
- data/example/public/javascripts/effects.js +1123 -0
- data/example/public/javascripts/prototype.js +4874 -0
- data/example/public/javascripts/rails.js +118 -0
- data/example/public/robots.txt +5 -0
- data/example/public/stylesheets/.gitkeep +0 -0
- data/example/script/rails +9 -0
- data/example/test/functional/page_controller_test.rb +19 -0
- data/example/test/performance/browsing_test.rb +9 -0
- data/example/test/test_helper.rb +13 -0
- data/example/test/unit/helpers/page_helper_test.rb +4 -0
- data/example/vendor/plugins/.gitkeep +0 -0
- data/gsiener-analytical.gemspec +167 -0
- data/lib/analytical/api.rb +117 -0
- data/lib/analytical/bot_detector.rb +46 -0
- data/lib/analytical/command_store.rb +19 -0
- data/lib/analytical/modules/adroll.rb +38 -0
- data/lib/analytical/modules/adwords.rb +80 -0
- data/lib/analytical/modules/base.rb +83 -0
- data/lib/analytical/modules/chartbeat.rb +49 -0
- data/lib/analytical/modules/click_tale.rb +47 -0
- data/lib/analytical/modules/clicky.rb +49 -0
- data/lib/analytical/modules/comscore.rb +25 -0
- data/lib/analytical/modules/console.rb +82 -0
- data/lib/analytical/modules/crazy_egg.rb +24 -0
- data/lib/analytical/modules/google.rb +44 -0
- data/lib/analytical/modules/google_optimizer.rb +62 -0
- data/lib/analytical/modules/hubspot.rb +28 -0
- data/lib/analytical/modules/kiss_metrics.rb +54 -0
- data/lib/analytical/modules/loopfuse.rb +30 -0
- data/lib/analytical/modules/microsoft_ads.rb +58 -0
- data/lib/analytical/modules/mixpanel.rb +56 -0
- data/lib/analytical/modules/optimizely.rb +23 -0
- data/lib/analytical/modules/performancing.rb +34 -0
- data/lib/analytical/modules/quantcast.rb +49 -0
- data/lib/analytical/modules/reinvigorate.rb +48 -0
- data/lib/analytical/modules/totango.rb +49 -0
- data/lib/analytical/session_command_store.rb +39 -0
- data/lib/analytical.rb +56 -0
- data/rails/init.rb +1 -0
- data/spec/analytical/api_spec.rb +157 -0
- data/spec/analytical/bot_detector_spec.rb +24 -0
- data/spec/analytical/command_store_spec.rb +36 -0
- data/spec/analytical/modules/adroll_spec.rb +27 -0
- data/spec/analytical/modules/adwords_spec.rb +76 -0
- data/spec/analytical/modules/base_spec.rb +138 -0
- data/spec/analytical/modules/chartbeat_spec.rb +26 -0
- data/spec/analytical/modules/clicky_spec.rb +50 -0
- data/spec/analytical/modules/comscore_spec.rb +27 -0
- data/spec/analytical/modules/google_spec.rb +45 -0
- data/spec/analytical/modules/kiss_metrics_spec.rb +51 -0
- data/spec/analytical/modules/mixpanel_spec.rb +71 -0
- data/spec/analytical/modules/optimizely_spec.rb +26 -0
- data/spec/analytical/modules/quantcast.rb +26 -0
- data/spec/analytical/modules/reinvigorate_spec.rb +35 -0
- data/spec/analytical/session_command_store_spec.rb +50 -0
- data/spec/analytical_spec.rb +79 -0
- data/spec/config/analytical.yml +9 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +19 -0
- metadata +294 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "Analytical::Modules::Adwords" do
|
4
|
+
before(:each) do
|
5
|
+
@parent = mock('api', :options=>{:google=>{:key=>'abc'}})
|
6
|
+
end
|
7
|
+
describe 'on initialize' do
|
8
|
+
it 'should set the command_location' do
|
9
|
+
a = Analytical::Modules::Adwords.new :parent=>@parent, :key=>'abc'
|
10
|
+
a.tracking_command_location.should == :body_append
|
11
|
+
end
|
12
|
+
it 'should set the options' do
|
13
|
+
a = Analytical::Modules::Adwords.new :parent=>@parent, :key=>'abc'
|
14
|
+
a.options.should == {:key=>'abc', :parent=>@parent}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe '#event' do
|
18
|
+
it 'should return an empty string' do
|
19
|
+
@api = Analytical::Modules::Adwords.new :parent=>@parent, :key=>'abcdef'
|
20
|
+
@api.event('Nothing', {:some=>'data'}).should == ''
|
21
|
+
end
|
22
|
+
end
|
23
|
+
describe '#init_javascript' do
|
24
|
+
describe 'when a matching conversion event is not found' do
|
25
|
+
it 'should return the event js' do
|
26
|
+
@api = Analytical::Modules::Adwords.new :parent=>@parent, :key=>'abcdef'
|
27
|
+
@api.queue :event, 'Nothing', {:some=>'data'}
|
28
|
+
@api.init_javascript(:body_append).should.should =~ /<!-- No Adwords Conversion for: Nothing -->/
|
29
|
+
end
|
30
|
+
end
|
31
|
+
describe 'for a given conversion event' do
|
32
|
+
before(:each) do
|
33
|
+
@api = Analytical::Modules::Adwords.new :parent=>@parent, :key=>'abcdef', :'TheBigEvent'=>{
|
34
|
+
:id=>'55555',
|
35
|
+
:language=>'en',
|
36
|
+
:format=>'2',
|
37
|
+
:color=>'ffffff',
|
38
|
+
:label=>'abcdef',
|
39
|
+
:value=>'0',
|
40
|
+
}
|
41
|
+
end
|
42
|
+
it 'should return the event js' do
|
43
|
+
@api.queue :event, 'TheBigEvent'
|
44
|
+
body_append = @api.init_javascript(:body_append).should
|
45
|
+
body_append.should =~ /google_conversion_id = 55555/m
|
46
|
+
body_append.should =~ /google_conversion_language = "en";/m
|
47
|
+
body_append.should =~ /google_conversion_format = "2";/m
|
48
|
+
body_append.should =~ /google_conversion_color = "ffffff";/m
|
49
|
+
body_append.should =~ /google_conversion_label = "abcdef";/m
|
50
|
+
body_append.should =~ /google_conversion_value = 0;/m
|
51
|
+
body_append.should =~ /http:\/\/www.googleadservices.com\/pagead\/conversion.js/m
|
52
|
+
end
|
53
|
+
describe 'with a custom value' do
|
54
|
+
it 'should return the event js' do
|
55
|
+
@api.queue :event, 'TheBigEvent', :value=>666.66
|
56
|
+
body_append = @api.init_javascript(:body_append).should
|
57
|
+
body_append.should =~ /google_conversion_value = 666.66;/m
|
58
|
+
end
|
59
|
+
end
|
60
|
+
describe 'for https' do
|
61
|
+
it 'should return the event js' do
|
62
|
+
@api = Analytical::Modules::Adwords.new :parent=>@parent, :key=>'abcdef', :ssl=>true, :'TheBigEvent'=>{
|
63
|
+
:id=>'55555',
|
64
|
+
:language=>'en',
|
65
|
+
:format=>'2',
|
66
|
+
:color=>'ffffff',
|
67
|
+
:label=>'abcdef',
|
68
|
+
:value=>'0',
|
69
|
+
}
|
70
|
+
@api.queue :event, 'TheBigEvent'
|
71
|
+
@api.init_javascript(:body_append).should =~ /https:\/\/www.googleadservices.com\/pagead\/conversion.js/
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Analytical::Modules::Base do
|
4
|
+
|
5
|
+
class BaseApiDummy
|
6
|
+
include Analytical::Modules::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#protocol' do
|
10
|
+
before(:each) do
|
11
|
+
@api = BaseApiDummy.new(:parent=>mock('parent'))
|
12
|
+
end
|
13
|
+
describe 'with :ssl=>true option' do
|
14
|
+
it 'should return https' do
|
15
|
+
@api = BaseApiDummy.new(:parent=>mock('parent'), :ssl=>true)
|
16
|
+
@api.protocol.should == 'https'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
it 'should return http' do
|
20
|
+
@api.protocol.should == 'http'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#queue' do
|
25
|
+
before(:each) do
|
26
|
+
@api = BaseApiDummy.new(:parent=>mock('parent'))
|
27
|
+
@api.command_store.commands = [:a, :b, :c]
|
28
|
+
end
|
29
|
+
describe 'with an identify command' do
|
30
|
+
it 'should store it at the head of the command list' do
|
31
|
+
@api.queue :identify, 'someone', {:some=>:args}
|
32
|
+
@api.command_store.commands.should == [[:identify, 'someone', {:some=>:args}], :a, :b, :c]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
describe 'with any other command' do
|
36
|
+
it 'should store it at the end of the command list' do
|
37
|
+
@api.queue :other, {:some=>:args}
|
38
|
+
@api.command_store.commands.should == [:a, :b, :c, [:other, {:some=>:args}]]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
describe 'ignoring duplicates' do
|
42
|
+
before(:each) do
|
43
|
+
@api = BaseApiDummy.new(:parent=>mock('parent'), :ignore_duplicates=>true)
|
44
|
+
@api.command_store.commands = [[:a]]
|
45
|
+
end
|
46
|
+
it 'should store only unique commands' do
|
47
|
+
@api.queue :other, {:some=>:args}
|
48
|
+
@api.queue :a
|
49
|
+
@api.queue :other, {:some=>:args}
|
50
|
+
@api.queue :b
|
51
|
+
@api.command_store.commands.should == [[:a], [:other, {:some=>:args}], [:b]]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#process_queued_commands' do
|
57
|
+
before(:each) do
|
58
|
+
@api = BaseApiDummy.new(:parent=>mock('parent'))
|
59
|
+
@api.command_store.commands = [[:a, 1, 2, 3], [:b, {:some=>:args}]]
|
60
|
+
@api.stub!(:a).and_return('a')
|
61
|
+
@api.stub!(:b).and_return('b')
|
62
|
+
end
|
63
|
+
it 'should send each of the args arrays in the command list' do
|
64
|
+
@api.should_receive(:a).with(1, 2, 3).and_return('a')
|
65
|
+
@api.should_receive(:b).with({:some=>:args}).and_return('b')
|
66
|
+
@api.process_queued_commands
|
67
|
+
end
|
68
|
+
it 'should return the results as an array' do
|
69
|
+
@api.process_queued_commands.should == ['a', 'b']
|
70
|
+
end
|
71
|
+
it 'should clear the commands list' do
|
72
|
+
@api.process_queued_commands
|
73
|
+
@api.command_store.commands == []
|
74
|
+
end
|
75
|
+
it "should not store an unrecognized command" do
|
76
|
+
@api.command_store.commands << [:c, 1]
|
77
|
+
@api.process_queued_commands.should == ['a','b']
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#init_location?' do
|
82
|
+
before(:each) do
|
83
|
+
@api = BaseApiDummy.new(:parent=>mock('parent'))
|
84
|
+
@api.instance_variable_set '@tracking_command_location', :my_location
|
85
|
+
end
|
86
|
+
describe 'when the command location matches the init location' do
|
87
|
+
it 'should return true' do
|
88
|
+
@api.init_location?(:my_location).should be_true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
describe 'when the command location does not match the init location' do
|
92
|
+
it 'should return false' do
|
93
|
+
@api.init_location?(:not_my_location).should be_false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#init_location' do
|
99
|
+
before(:each) do
|
100
|
+
@api = BaseApiDummy.new
|
101
|
+
end
|
102
|
+
it 'should check for the init_location' do
|
103
|
+
@api.should_receive(:init_location?).with(:some_location).and_return(false)
|
104
|
+
@api.init_location(:some_location)
|
105
|
+
end
|
106
|
+
describe 'for a valid init location' do
|
107
|
+
before(:each) { @api.stub!(:init_location?).and_return(true) }
|
108
|
+
it 'should set initialized to true' do
|
109
|
+
@api.init_location(:some_location)
|
110
|
+
@api.initialized.should be_true
|
111
|
+
end
|
112
|
+
it 'should yield to the block and return its result' do
|
113
|
+
@api.init_location(:some_location) do
|
114
|
+
'result from the block'
|
115
|
+
end.should == 'result from the block'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
describe 'not for an init location' do
|
119
|
+
before(:each) do
|
120
|
+
@api.stub!(:init_location?).and_return(false)
|
121
|
+
end
|
122
|
+
it 'should return an empty string' do
|
123
|
+
@api.init_location(:not_my_init_location).should == ''
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe 'with a custom session_store' do
|
129
|
+
before(:each) do
|
130
|
+
@session = {}
|
131
|
+
@store = Analytical::SessionCommandStore.new @session, :some_module
|
132
|
+
end
|
133
|
+
it 'should use the session_store' do
|
134
|
+
@api = BaseApiDummy.new :session_store=>@store
|
135
|
+
@api.command_store.should == @store
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "Analytical::Modules::Chartbeat" 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::Modules::Chartbeat.new :parent=>@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::Modules::Chartbeat.new :parent=>@parent, :key=>12345, :domain =>'abcdef.com'
|
14
|
+
a.options.should == {:key=>12345, :domain => 'abcdef.com', :parent=>@parent}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe '#init_javascript' do
|
18
|
+
it 'should return the init javascript' do
|
19
|
+
@api = Analytical::Modules::Chartbeat.new :parent=>@parent, :key=>12345, :domain =>'abcdef.com'
|
20
|
+
@api.init_javascript(:head_prepend).should =~ /_sf_startpt=\(new.Date\(\)\)\.getTime\(\);/
|
21
|
+
@api.init_javascript(:head_append).should == ''
|
22
|
+
@api.init_javascript(:body_prepend).should == ''
|
23
|
+
@api.init_javascript(:body_append).should =~ /_sf_async_config=\{uid:12345,.*domain:"abcdef\.com"\};/
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "Analytical::Modules::Clicky" do
|
4
|
+
before(:each) do
|
5
|
+
@parent = mock('api', :options=>{:google=>{:key=>'abc'}})
|
6
|
+
end
|
7
|
+
describe 'on initialize' do
|
8
|
+
it 'should set the command_location' do
|
9
|
+
a = Analytical::Modules::Clicky.new :parent=>@parent, :key=>'abc'
|
10
|
+
a.tracking_command_location.should == :body_append
|
11
|
+
end
|
12
|
+
it 'should set the options' do
|
13
|
+
a = Analytical::Modules::Clicky.new :parent=>@parent, :key=>'abc'
|
14
|
+
a.options.should == {:key=>'abc', :parent=>@parent}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe '#track' do
|
18
|
+
it 'should return the tracking javascript' do
|
19
|
+
@api = Analytical::Modules::Clicky.new :parent=>@parent, :key=>'abcdef'
|
20
|
+
@api.track('pagename', {:some=>'data'}).should == "clicky.log(\"pagename\");"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
describe '#identify' do
|
24
|
+
it 'should return the init code string' do
|
25
|
+
@api = Analytical::Modules::Clicky.new :parent=>@parent, :key=>'abcdef'
|
26
|
+
@api.identify('user id', {:a=>'b'}).should =~ /#{Regexp.escape({:id=>'user id', :a=>'b'}.to_json)}/
|
27
|
+
end
|
28
|
+
end
|
29
|
+
describe '#init_javascript' do
|
30
|
+
it 'should return the init javascript' do
|
31
|
+
@api = Analytical::Modules::Clicky.new :parent=>@parent, :key=>'abcdef'
|
32
|
+
@api.init_javascript(:head_prepend).should == ''
|
33
|
+
@api.init_javascript(:head_append).should == ''
|
34
|
+
@api.init_javascript(:body_prepend).should == ''
|
35
|
+
@api.init_javascript(:body_append).should =~ /static.getclicky.com\/js/
|
36
|
+
@api.init_javascript(:body_append).should =~ /abcdef/
|
37
|
+
end
|
38
|
+
describe 'for an ssl connection' do
|
39
|
+
it 'should return the ssl init code' do
|
40
|
+
@api = Analytical::Modules::Clicky.new :parent=>@parent, :key=>'abcdef', :ssl=>true
|
41
|
+
@api.init_javascript(:body_append).should =~ /https/
|
42
|
+
end
|
43
|
+
end
|
44
|
+
describe 'with an identify command queued' do
|
45
|
+
@api = Analytical::Modules::Clicky.new :parent=>@parent, :key=>'abcdef'
|
46
|
+
@api.queue :identify, 'user id', {:email=>'someone@test.com'}
|
47
|
+
@api.init_javascript(:body_append).should =~ /"email":\w*"someone@test\.com"/
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "Analytical::Modules::Comscore" 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::Modules::Comscore.new :parent=>@parent, :key=>123
|
10
|
+
a.tracking_command_location.should == :head_append
|
11
|
+
end
|
12
|
+
it 'should set the options' do
|
13
|
+
a = Analytical::Modules::Comscore.new :parent=>@parent, :key=>1234
|
14
|
+
a.options.should == {:key=>1234, :parent=>@parent}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe '#init_javascript' do
|
18
|
+
it 'should return the init javascript' do
|
19
|
+
@api = Analytical::Modules::Comscore.new :parent=>@parent, :key=>1234
|
20
|
+
@api.init_javascript(:head_prepend).should == ''
|
21
|
+
@api.init_javascript(:head_append).should =~ /scorecardresearch.com\/beacon.js/
|
22
|
+
@api.init_javascript(:head_append).should =~ /1234/
|
23
|
+
@api.init_javascript(:body_prepend).should == ''
|
24
|
+
@api.init_javascript(:body_append).should == ''
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "Analytical::Modules::Google" do
|
4
|
+
before(:each) do
|
5
|
+
@parent = mock('api', :options=>{:google=>{:key=>'abc'}})
|
6
|
+
end
|
7
|
+
describe 'on initialize' do
|
8
|
+
it 'should set the command_location' do
|
9
|
+
a = Analytical::Modules::Google.new :parent=>@parent, :key=>'abc'
|
10
|
+
a.tracking_command_location.should == :head_append
|
11
|
+
end
|
12
|
+
it 'should set the options' do
|
13
|
+
a = Analytical::Modules::Google.new :parent=>@parent, :key=>'abc'
|
14
|
+
a.options.should == {:key=>'abc', :parent=>@parent}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe '#track' do
|
18
|
+
it 'should return the tracking javascript' do
|
19
|
+
@api = Analytical::Modules::Google.new :parent=>@parent, :key=>'abcdef'
|
20
|
+
@api.track.should == "_gaq.push(['_trackPageview']);"
|
21
|
+
@api.track('pagename', {:some=>'data'}).should == "_gaq.push(['_trackPageview', \"pagename\"]);"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
describe '#event' do
|
25
|
+
it 'should return the event javascript' do
|
26
|
+
@api = Analytical::Modules::Google.new :parent=>@parent, :key=>'abcdef'
|
27
|
+
@api.event('pagename').should == "_gaq.push(['_trackEvent', \"Event\", \"pagename\"]);"
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should include any passed in data' do
|
31
|
+
@api = Analytical::Modules::Google.new :parent=>@parent, :key=>'abcdef'
|
32
|
+
@api.event('pagename', {:some=>'data',:more=>'info'}).should == "_gaq.push(['_trackEvent', \"Event\", \"pagename\", '#{ {:some=>'data',:more=>'info'}.to_json }']);"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
describe '#init_javascript' do
|
36
|
+
it 'should return the init javascript' do
|
37
|
+
@api = Analytical::Modules::Google.new :parent=>@parent, :key=>'abcdef'
|
38
|
+
@api.init_javascript(:head_prepend).should == ''
|
39
|
+
@api.init_javascript(:head_append).should =~ /abcdef/
|
40
|
+
@api.init_javascript(:head_append).should =~ /google-analytics.com\/ga.js/
|
41
|
+
@api.init_javascript(:body_prepend).should == ''
|
42
|
+
@api.init_javascript(:body_append).should == ''
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "Analytical::Modules::KissMetrics" do
|
4
|
+
before(:each) do
|
5
|
+
@parent = mock('api', :options=>{:google=>{:js_url_key=>'abc'}})
|
6
|
+
end
|
7
|
+
describe 'on initialize' do
|
8
|
+
it 'should set the command_location' do
|
9
|
+
a = Analytical::Modules::KissMetrics.new :parent=>@parent, :js_url_key=>'abc'
|
10
|
+
a.tracking_command_location.should == :body_prepend
|
11
|
+
end
|
12
|
+
it 'should set the options' do
|
13
|
+
a = Analytical::Modules::KissMetrics.new :parent=>@parent, :js_url_key=>'abc'
|
14
|
+
a.options.should == {:js_url_key=>'abc', :parent=>@parent}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe '#identify' do
|
18
|
+
it 'should return a js string' do
|
19
|
+
@api = Analytical::Modules::KissMetrics.new :parent=>@parent, :js_url_key=>'abcdef'
|
20
|
+
@api.identify('id', {:email=>'test@test.com'}).should == "_kmq.push([\"identify\", \"test@test.com\"]);"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
describe '#event' do
|
24
|
+
it 'should return a js string' do
|
25
|
+
@api = Analytical::Modules::KissMetrics.new :parent=>@parent, :js_url_key=>'abcdef'
|
26
|
+
@api.event('Big Deal', {:something=>'good'}).should == "_kmq.push([\"record\", \"Big Deal\", #{{:something=>'good'}.to_json}]);"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
describe '#set' do
|
30
|
+
it 'should return a js string' do
|
31
|
+
@api = Analytical::Modules::KissMetrics.new :parent=>@parent, :js_url_key=>'abcdef'
|
32
|
+
@api.set({:something=>'good', :b=>2}).should == "_kmq.push([\"set\", #{{:something=>'good', :b=>2}.to_json}]);"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
describe '#alias_identity' do
|
36
|
+
it 'should return a js string' do
|
37
|
+
@api = Analytical::Modules::KissMetrics.new :parent=>@parent, :js_url_key=>'abcdef'
|
38
|
+
@api.alias_identity('foo', 'bar').should == "_kmq.push([\"alias\", \"foo\", \"bar\"]);"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
describe '#init_javascript' do
|
42
|
+
it 'should return the init javascript' do
|
43
|
+
@api = Analytical::Modules::KissMetrics.new :parent=>@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/
|
47
|
+
@api.init_javascript(:body_prepend).should =~ /abcdef/
|
48
|
+
@api.init_javascript(:body_append).should == ''
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "Analytical::Modules::Mixpanel" do
|
4
|
+
before(:each) do
|
5
|
+
@parent = mock('api', :options=>{:google=>{:js_url_key=>'abc'}})
|
6
|
+
end
|
7
|
+
describe 'on initialize' do
|
8
|
+
it 'should set the command_location' do
|
9
|
+
a = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abc'
|
10
|
+
a.tracking_command_location.should == :body_append
|
11
|
+
end
|
12
|
+
it 'should set the options' do
|
13
|
+
a = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abc'
|
14
|
+
a.options.should == {:js_url_key=>'abc', :parent=>@parent}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe '#identify' do
|
18
|
+
it 'should return a js string' do
|
19
|
+
@api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
|
20
|
+
@api.identify('id', {:email=>'test@test.com'}).should == "mpmetrics.identify('id');"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
describe '#track' do
|
24
|
+
it 'should return the tracking javascript' do
|
25
|
+
@api = Analytical::Modules::Mixpanel.new :parent=>@parent, :key=>'abcdef'
|
26
|
+
@api.track('pagename', {:some=>'data'}).should == "mpmetrics.track('pagename', {\"some\":\"data\"}, function(){});"
|
27
|
+
end
|
28
|
+
it 'should return the tracking javascript with a callback' do
|
29
|
+
@api = Analytical::Modules::Mixpanel.new :parent=>@parent, :key=>'abcdef'
|
30
|
+
@api.track('pagename', {:some=>'data', :callback=>'fubar'}).should == "mpmetrics.track('pagename', {\"some\":\"data\"}, fubar);"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
describe '#event' do
|
34
|
+
it 'should return a js string' do
|
35
|
+
@api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
|
36
|
+
@api.event('My Funnel', {:step=>5, :goal=>'thegoal'}).should == "mpmetrics.track_funnel('My Funnel', '5', 'thegoal', {}, function(){});"
|
37
|
+
end
|
38
|
+
describe 'without the proper data' do
|
39
|
+
it 'should return an error string with blank funnel' do
|
40
|
+
@api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
|
41
|
+
@api.event('', {:step=>5, :goal=>'thegoal'}).should =~ /Funnel is not set/
|
42
|
+
end
|
43
|
+
it 'should return an error string with blank step' do
|
44
|
+
@api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
|
45
|
+
@api.event('My Funnel', {:goal=>'thegoal'}).should =~ /Step is not set/
|
46
|
+
end
|
47
|
+
it 'should return an error string with step < 0' do
|
48
|
+
@api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
|
49
|
+
@api.event('My Funnel', {:step=>-1, :goal=>'thegoal'}).should =~ /Step is not set/
|
50
|
+
end
|
51
|
+
it 'should return an error string with blank goal' do
|
52
|
+
@api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
|
53
|
+
@api.event('My Funnel', {:step=>5}).should =~ /Goal is not set/
|
54
|
+
end
|
55
|
+
end
|
56
|
+
it 'should return a js string' do
|
57
|
+
@api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
|
58
|
+
@api.event('My Funnel', {:step=>5, :goal=>'thegoal', :callback=>'thecallback', :other=>'data'}).should == "mpmetrics.track_funnel('My Funnel', '5', 'thegoal', {\"other\":\"data\"}, thecallback);"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
describe '#init_javascript' do
|
62
|
+
it 'should return the init javascript' do
|
63
|
+
@api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
|
64
|
+
@api.init_javascript(:head_prepend).should == ''
|
65
|
+
@api.init_javascript(:head_append).should == ''
|
66
|
+
@api.init_javascript(:body_prepend).should == ''
|
67
|
+
@api.init_javascript(:body_append).should =~ /api\.mixpanel\.com\/site_media\/js\/api\/mixpanel\.js/
|
68
|
+
@api.init_javascript(:body_append).should =~ /new MixpanelLib\('.*'\)/
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "Analytical::Modules::Optimizely" 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::Modules::Optimizely.new :parent=>@parent, :key=>'abc'
|
10
|
+
a.tracking_command_location.should == :head_prepend
|
11
|
+
end
|
12
|
+
it 'should set the options' do
|
13
|
+
a = Analytical::Modules::Optimizely.new :parent=>@parent, :key=>'abc'
|
14
|
+
a.options.should == {:key=>'abc', :parent=>@parent}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe '#init_javascript' do
|
18
|
+
it 'should return the init javascript' do
|
19
|
+
@api = Analytical::Modules::Optimizely.new :parent=>@parent, :key=>'abcdef'
|
20
|
+
@api.init_javascript(:head_prepend).should =~ /cdn\.optimizely.com\/js\/abcdef\.js/
|
21
|
+
@api.init_javascript(:head_append).should == ''
|
22
|
+
@api.init_javascript(:body_prepend).should == ''
|
23
|
+
@api.init_javascript(:body_append).should == ''
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "Analytical::Modules::Quantcast" do
|
4
|
+
before(:each) do
|
5
|
+
@parent = mock('api', :options=>{:quantcast=>{:key=>1234}})
|
6
|
+
end
|
7
|
+
describe 'on initialize' do
|
8
|
+
it 'should set the command_location' do
|
9
|
+
a = Analytical::Modules::Quantcast.new :parent=>@parent, :key=>1234
|
10
|
+
a.tracking_command_location.should == [:head_append, :body_append]
|
11
|
+
end
|
12
|
+
it 'should set the options' do
|
13
|
+
a = Analytical::Modules::Quantcast.new :parent=>@parent, :key=>12345
|
14
|
+
a.options.should == {:key=>12345, :parent=>@parent}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe '#init_javascript' do
|
18
|
+
it 'should return the init javascript' do
|
19
|
+
@api = Analytical::Modules::Quantcast.new :parent=>@parent, :key=>12345
|
20
|
+
@api.init_javascript(:head_prepend).should =~ ''
|
21
|
+
@api.init_javascript(:head_append).should == /var._qevents.=._qevents.\|\|.\[\];/
|
22
|
+
@api.init_javascript(:body_prepend).should == ''
|
23
|
+
@api.init_javascript(:body_append).should =~ /_qevents.push\(.\{.qacct:"12345"\} \);/
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "Analytical::Modules::Reinvigorate" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@parent = mock('api', :options=>{:reinvigorate=>{:key=>'abc'}})
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'on initialize' do
|
10
|
+
|
11
|
+
it 'should set the command_location' do
|
12
|
+
a = Analytical::Modules::Reinvigorate.new :parent=>@parent, :key=>'abc'
|
13
|
+
a.tracking_command_location.should == :body_append
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should set the options' do
|
17
|
+
a = Analytical::Modules::Reinvigorate.new :parent=>@parent, :key=>'abc'
|
18
|
+
a.options.should == {:key=>'abc', :parent=>@parent}
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#init_javascript' do
|
24
|
+
|
25
|
+
it 'should return the init javascript' do
|
26
|
+
@api = Analytical::Modules::Reinvigorate.new :parent=>@parent, :key=>'abcdef'
|
27
|
+
@api.init_javascript(:head_prepend).should == ''
|
28
|
+
@api.init_javascript(:head_append).should == ''
|
29
|
+
@api.init_javascript(:body_prepend).should == ''
|
30
|
+
@api.init_javascript(:body_append).should =~ /reinvigorate/
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Analytical::SessionCommandStore do
|
4
|
+
|
5
|
+
describe 'with a session hash' do
|
6
|
+
before(:each) do
|
7
|
+
@session = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should add elements' do
|
11
|
+
@store = Analytical::SessionCommandStore.new @session, :some_module, ['a']
|
12
|
+
@store << 'b'
|
13
|
+
@session[:analytical_some_module].should == ['a', 'b']
|
14
|
+
end
|
15
|
+
it 'should unshift elements' do
|
16
|
+
@store = Analytical::SessionCommandStore.new @session, :some_module, ['b']
|
17
|
+
@store.unshift 'a'
|
18
|
+
@session[:analytical_some_module].should == ['a', 'b']
|
19
|
+
end
|
20
|
+
it 'should iterate over elements' do
|
21
|
+
@store = Analytical::SessionCommandStore.new @session, :some_module, ['a', 'b']
|
22
|
+
@store.each do |elem|
|
23
|
+
['a', 'b'].include?(elem).should be_true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
it 'should have size' do
|
27
|
+
@store = Analytical::SessionCommandStore.new @session, :some_module, ['a', 'b']
|
28
|
+
@store.size.should == 2
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should set up the :analytical session hash' do
|
32
|
+
@store = Analytical::SessionCommandStore.new @session, :some_module, ['a', 'b']
|
33
|
+
@session[:analytical_some_module].should_not be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'when flushing' do
|
37
|
+
it 'should empty the list' do
|
38
|
+
@store = Analytical::SessionCommandStore.new @session, :some_module, ['a', 'b']
|
39
|
+
@store.flush
|
40
|
+
@store.size.should == 0
|
41
|
+
end
|
42
|
+
it 'should empty the session key' do
|
43
|
+
@store = Analytical::SessionCommandStore.new @session, :some_module, ['a', 'b']
|
44
|
+
@store.flush
|
45
|
+
@session[:analytical_some_module].should == []
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|