bacchanalytics 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.travis.yml +11 -0
- data/Appraisals +14 -0
- data/CHANGELOG.md +53 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +20 -0
- data/README.md +94 -0
- data/Rakefile +17 -0
- data/bacchanalytics.gemspec +27 -0
- data/gemfiles/2.3.gemfile +8 -0
- data/gemfiles/2.3.gemfile.lock +31 -0
- data/gemfiles/3.0.gemfile +8 -0
- data/gemfiles/3.0.gemfile.lock +33 -0
- data/gemfiles/3.1.gemfile +8 -0
- data/gemfiles/3.1.gemfile.lock +33 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/bacchanalytics.rb +5 -0
- data/lib/bacchanalytics/adwords_conversion.rb +95 -0
- data/lib/bacchanalytics/analytics.rb +62 -0
- data/lib/bacchanalytics/google_analytics.rb +74 -0
- data/lib/bacchanalytics/version.rb +3 -0
- data/lib/bacchanalytics/website_optimizer.rb +204 -0
- data/test/integration/bacchanalytics_integration_test.rb +64 -0
- data/test/test_helper.rb +8 -0
- data/test/unit/adwords_conversion_test.rb +96 -0
- data/test/unit/bacchanalytics_test.rb +70 -0
- data/test/unit/website_optimizer_test.rb +63 -0
- metadata +190 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'bacchanalytics'
|
3
|
+
|
4
|
+
ENV['RACK_ENV'] = 'test'
|
5
|
+
|
6
|
+
class BacchanalyticsTest < Test::Unit::TestCase
|
7
|
+
include Rack::Test::Methods
|
8
|
+
include Bacchanalytics::GoogleAnalytics::TrackingCode
|
9
|
+
include Bacchanalytics::GoogleAnalytics::Base
|
10
|
+
|
11
|
+
WEB_PROPERTY_ID = "UA-12345-6"
|
12
|
+
|
13
|
+
def app
|
14
|
+
response = Rack::Response.new(HTML_DOCUMENT)
|
15
|
+
mock_app = lambda do |env|
|
16
|
+
[200, {'Content-Type' => 'text/html'}, response]
|
17
|
+
end
|
18
|
+
Bacchanalytics::Analytics.new(mock_app, :web_property_id => WEB_PROPERTY_ID)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_only_instrument_html_requests
|
22
|
+
assert app.should_instrument?({'Content-Type' => 'text/html'})
|
23
|
+
assert !app.should_instrument?({'Content-Type' => 'text/xhtml'})
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_should_insert_gatc_inside_head
|
27
|
+
get "/"
|
28
|
+
|
29
|
+
gatc_expected = google_analytics_tracking_code(WEB_PROPERTY_ID).gsub(/\s/, '')
|
30
|
+
gatc_rack = Nokogiri::HTML(last_response.body).xpath("/html/head/script")[0].to_html.gsub(/\s/, '')
|
31
|
+
assert gatc_rack.include?(gatc_expected), gatc_rack
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_insert_the_web_property
|
35
|
+
get "/"
|
36
|
+
|
37
|
+
gatc_rack = Nokogiri::HTML(last_response.body).xpath("/html/head/script")[0].to_html
|
38
|
+
assert gatc_rack.include?("_gaq.push(['_setAccount', 'UA-12345-6']);"), gatc_rack
|
39
|
+
end
|
40
|
+
|
41
|
+
HTML_DOCUMENT = <<-HTML
|
42
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
43
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
44
|
+
|
45
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
46
|
+
<head>
|
47
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
48
|
+
<title>Listing things</title>
|
49
|
+
</head>
|
50
|
+
<body>
|
51
|
+
|
52
|
+
<h1>Listing things</h1>
|
53
|
+
|
54
|
+
<table>
|
55
|
+
<tr>
|
56
|
+
<th>Name</th>
|
57
|
+
</tr>
|
58
|
+
<tr>
|
59
|
+
<td>Thing 1</td>
|
60
|
+
</tr>
|
61
|
+
<tr>
|
62
|
+
<td>Thing 2</td>
|
63
|
+
</tr>
|
64
|
+
</table>
|
65
|
+
|
66
|
+
</body>
|
67
|
+
</html>
|
68
|
+
HTML
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'bacchanalytics'
|
3
|
+
|
4
|
+
ENV['RACK_ENV'] = 'test'
|
5
|
+
|
6
|
+
class WebsiteOptimizerTest < Test::Unit::TestCase
|
7
|
+
include Rack::Test::Methods
|
8
|
+
include Bacchanalytics::GoogleAnalytics::Base
|
9
|
+
extend Bacchanalytics::GoogleAnalytics::Base
|
10
|
+
|
11
|
+
WEB_PROPERTY_ID = "UA-12345-6"
|
12
|
+
|
13
|
+
def app
|
14
|
+
response = Rack::Response.new(HTML_DOCUMENT)
|
15
|
+
mock_app = lambda do |env|
|
16
|
+
[200, {'Content-Type' => 'text/html'}, response]
|
17
|
+
end
|
18
|
+
Bacchanalytics::WebsiteOptimizer.new(mock_app, {:skip_ga_src => true,
|
19
|
+
:account_id => 'UA-20891683-1',
|
20
|
+
:ab => {'1924712694' => {:a => ["/"],
|
21
|
+
:b => ["/home"],
|
22
|
+
:goal => ["/welcome"]}}})
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_must_not_include_if_specify_skip
|
26
|
+
get "/", {}, {"REQUEST_URI" => "/"}
|
27
|
+
|
28
|
+
times = 0
|
29
|
+
last_response.body.gsub(load_ga_src) { |m| times += 1 }
|
30
|
+
|
31
|
+
assert_equal 1, times
|
32
|
+
end
|
33
|
+
|
34
|
+
HTML_DOCUMENT = <<-HTML
|
35
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
36
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
37
|
+
|
38
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
39
|
+
<head>
|
40
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
41
|
+
<title>Listing things</title>
|
42
|
+
#{load_ga_src}
|
43
|
+
</head>
|
44
|
+
<body>
|
45
|
+
|
46
|
+
<h1>Listing things</h1>
|
47
|
+
|
48
|
+
<table>
|
49
|
+
<tr>
|
50
|
+
<th>Name</th>
|
51
|
+
</tr>
|
52
|
+
<tr>
|
53
|
+
<td>Thing 1</td>
|
54
|
+
</tr>
|
55
|
+
<tr>
|
56
|
+
<td>Thing 2</td>
|
57
|
+
</tr>
|
58
|
+
</table>
|
59
|
+
|
60
|
+
</body>
|
61
|
+
</html>
|
62
|
+
HTML
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bacchanalytics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 9
|
10
|
+
version: 0.1.9
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "David P\xC3\xA9rez"
|
14
|
+
- Paco Guzman
|
15
|
+
- Javier Vidal
|
16
|
+
- ASPgems developers
|
17
|
+
autorequire:
|
18
|
+
bindir: bin
|
19
|
+
cert_chain: []
|
20
|
+
|
21
|
+
date: 2011-11-02 00:00:00 Z
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: rack
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 13
|
32
|
+
segments:
|
33
|
+
- 1
|
34
|
+
- 1
|
35
|
+
version: "1.1"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: activesupport
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 7
|
47
|
+
segments:
|
48
|
+
- 2
|
49
|
+
version: "2"
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: appraisal
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
- 3
|
64
|
+
- 8
|
65
|
+
version: 0.3.8
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: rack-test
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 7
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
- 6
|
80
|
+
version: "0.6"
|
81
|
+
type: :development
|
82
|
+
version_requirements: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: nokogiri
|
85
|
+
prerelease: false
|
86
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ~>
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 5
|
92
|
+
segments:
|
93
|
+
- 1
|
94
|
+
- 5
|
95
|
+
version: "1.5"
|
96
|
+
type: :development
|
97
|
+
version_requirements: *id005
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rake
|
100
|
+
prerelease: false
|
101
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ~>
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 25
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
- 9
|
110
|
+
version: "0.9"
|
111
|
+
type: :development
|
112
|
+
version_requirements: *id006
|
113
|
+
description: |-
|
114
|
+
Bacchanalytics is a rack middleware that inserts the Asynchronous Google Analytics
|
115
|
+
Tracking Code in your application.
|
116
|
+
email:
|
117
|
+
- dperez@aspgems.com
|
118
|
+
- fjguzman@aspgems.com
|
119
|
+
- javier.vidal@aspgems.com
|
120
|
+
- developers@aspgems.com
|
121
|
+
executables: []
|
122
|
+
|
123
|
+
extensions: []
|
124
|
+
|
125
|
+
extra_rdoc_files: []
|
126
|
+
|
127
|
+
files:
|
128
|
+
- .gitignore
|
129
|
+
- .travis.yml
|
130
|
+
- Appraisals
|
131
|
+
- CHANGELOG.md
|
132
|
+
- Gemfile
|
133
|
+
- MIT-LICENSE
|
134
|
+
- README.md
|
135
|
+
- Rakefile
|
136
|
+
- bacchanalytics.gemspec
|
137
|
+
- gemfiles/2.3.gemfile
|
138
|
+
- gemfiles/2.3.gemfile.lock
|
139
|
+
- gemfiles/3.0.gemfile
|
140
|
+
- gemfiles/3.0.gemfile.lock
|
141
|
+
- gemfiles/3.1.gemfile
|
142
|
+
- gemfiles/3.1.gemfile.lock
|
143
|
+
- init.rb
|
144
|
+
- install.rb
|
145
|
+
- lib/bacchanalytics.rb
|
146
|
+
- lib/bacchanalytics/adwords_conversion.rb
|
147
|
+
- lib/bacchanalytics/analytics.rb
|
148
|
+
- lib/bacchanalytics/google_analytics.rb
|
149
|
+
- lib/bacchanalytics/version.rb
|
150
|
+
- lib/bacchanalytics/website_optimizer.rb
|
151
|
+
- test/integration/bacchanalytics_integration_test.rb
|
152
|
+
- test/test_helper.rb
|
153
|
+
- test/unit/adwords_conversion_test.rb
|
154
|
+
- test/unit/bacchanalytics_test.rb
|
155
|
+
- test/unit/website_optimizer_test.rb
|
156
|
+
homepage: https://github.com/aspgems/bacchanalytics
|
157
|
+
licenses: []
|
158
|
+
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options: []
|
161
|
+
|
162
|
+
require_paths:
|
163
|
+
- lib
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
none: false
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
hash: 3
|
170
|
+
segments:
|
171
|
+
- 0
|
172
|
+
version: "0"
|
173
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
|
+
none: false
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
hash: 3
|
179
|
+
segments:
|
180
|
+
- 0
|
181
|
+
version: "0"
|
182
|
+
requirements: []
|
183
|
+
|
184
|
+
rubyforge_project:
|
185
|
+
rubygems_version: 1.8.10
|
186
|
+
signing_key:
|
187
|
+
specification_version: 3
|
188
|
+
summary: Bacchanalytics is a rack middleware that inserts the Asynchronous Google Analytics Tracking Code in your application.
|
189
|
+
test_files: []
|
190
|
+
|