google_analytics 1.1.3 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +12 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +4 -4
- data/Rakefile +19 -3
- data/lib/google_analytics.rb +2 -0
- data/lib/rubaidh/google_analytics.rb +4 -2
- data/test/google_analytics_test.rb +64 -1
- data/test/test_helper.rb +2 -3
- metadata +24 -9
data/CHANGELOG
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
= 1.1.5
|
2
|
+
|
3
|
+
* Tidy up documentation a little.
|
4
|
+
* Wrap the generated JS code in an exception-catching block, just in case.
|
5
|
+
* Start keeping a CHANGELOG!
|
6
|
+
|
7
|
+
= 1.1.4
|
8
|
+
|
9
|
+
This version was never properly released as a gem on Rubyforge. Oops.
|
10
|
+
|
11
|
+
* Be careful to retain body tag attributes.
|
12
|
+
* Allow the body tags to be in uppercase. We won't judge. :)
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -17,11 +17,11 @@ following to controllers that don't want it:
|
|
17
17
|
|
18
18
|
If you are running rails 2.1 or above add install this by adding:
|
19
19
|
|
20
|
-
config.gem '
|
20
|
+
config.gem 'google_analytics'
|
21
21
|
|
22
22
|
and run:
|
23
23
|
|
24
|
-
rake gems:
|
24
|
+
rake gems:unpack
|
25
25
|
|
26
26
|
Simple. :-)
|
27
27
|
|
@@ -76,7 +76,7 @@ JavaScript files, updated via a rake task and served courtesy of the Rails
|
|
76
76
|
AssetTagHelper methods. So even if you use asset hosts, the JS will be served
|
77
77
|
from the correct source and under the correct protocol (HTTP/HTTPS).
|
78
78
|
|
79
|
-
To enable cached copies
|
79
|
+
To enable cached copies add the following to your initialization code:
|
80
80
|
|
81
81
|
Rubaidh::GoogleAnalytics.local_javascript = true
|
82
82
|
|
@@ -121,4 +121,4 @@ options.
|
|
121
121
|
Note: You will need to have the mocha gem installed to run the tests for this
|
122
122
|
plugin.
|
123
123
|
|
124
|
-
Copyright (c) 2006-
|
124
|
+
Copyright (c) 2006-2009 Rubaidh Ltd, released under the MIT license.
|
data/Rakefile
CHANGED
@@ -2,6 +2,7 @@ require 'rake'
|
|
2
2
|
require 'rake/testtask'
|
3
3
|
require 'rake/rdoctask'
|
4
4
|
require 'rake/gempackagetask'
|
5
|
+
require 'rcov/rcovtask'
|
5
6
|
require 'rubyforge'
|
6
7
|
|
7
8
|
desc 'Default: run unit tests.'
|
@@ -16,12 +17,18 @@ Rake::TestTask.new(:test) do |t|
|
|
16
17
|
t.verbose = true
|
17
18
|
end
|
18
19
|
|
20
|
+
Rcov::RcovTask.new do |t|
|
21
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
22
|
+
t.verbose = true
|
23
|
+
t.rcov_opts = ["-x", "^/"]
|
24
|
+
end
|
25
|
+
|
19
26
|
desc 'Generate documentation for the google_analytics plugin.'
|
20
27
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
21
28
|
rdoc.rdoc_dir = 'rdoc'
|
22
|
-
rdoc.title = '
|
23
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
24
|
-
rdoc.rdoc_files
|
29
|
+
rdoc.title = 'Google Analytics'
|
30
|
+
rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README.rdoc'
|
31
|
+
rdoc.rdoc_files << 'README.rdoc' << 'CHANGELOG' << 'CREDITS' << 'MIT-LICENSE'
|
25
32
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
26
33
|
end
|
27
34
|
|
@@ -38,3 +45,12 @@ task :release => [:clean, :package] do |t|
|
|
38
45
|
rubyforge.login
|
39
46
|
rubyforge.add_release gem_spec.rubyforge_project, gem_spec.name, gem_spec.version.to_s, "pkg/#{gem_spec.name}-#{gem_spec.version}.gem"
|
40
47
|
end
|
48
|
+
|
49
|
+
begin
|
50
|
+
gem 'ci_reporter'
|
51
|
+
require 'ci/reporter/rake/test_unit'
|
52
|
+
task :bamboo => "ci:setup:testunit"
|
53
|
+
rescue LoadError
|
54
|
+
end
|
55
|
+
|
56
|
+
task :bamboo => [ :package, :test ]
|
@@ -18,9 +18,9 @@ module Rubaidh # :nodoc:
|
|
18
18
|
# (see http://www.google.com/support/googleanalytics/bin/answer.py?answer=55527&topic=11006)
|
19
19
|
def add_google_analytics_code
|
20
20
|
if GoogleAnalytics.defer_load
|
21
|
-
response.body.sub!
|
21
|
+
response.body.sub! /<\/[bB][oO][dD][yY]>/, "#{google_analytics_code}</body>" if response.body.respond_to?(:sub!)
|
22
22
|
else
|
23
|
-
response.body.sub!
|
23
|
+
response.body.sub! /(<[bB][oO][dD][yY][^>]*>)/, "\\1#{google_analytics_code}" if response.body.respond_to?(:sub!)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -174,10 +174,12 @@ module Rubaidh # :nodoc:
|
|
174
174
|
code << <<-HTML
|
175
175
|
<script type="text/javascript">
|
176
176
|
<!--//--><![CDATA[//><!--
|
177
|
+
try {
|
177
178
|
var pageTracker = _gat._getTracker('#{request_tracker_id}');
|
178
179
|
#{extra_code}
|
179
180
|
pageTracker._initData();
|
180
181
|
pageTracker._trackPageview(#{request_tracked_path});
|
182
|
+
} catch(err) {}
|
181
183
|
//--><!]]>
|
182
184
|
</script>
|
183
185
|
HTML
|
@@ -4,6 +4,29 @@ require 'rubygems'
|
|
4
4
|
require 'mocha'
|
5
5
|
RAILS_ENV = 'test'
|
6
6
|
|
7
|
+
class TestMixin
|
8
|
+
class MockRequest
|
9
|
+
attr_accessor :format
|
10
|
+
end
|
11
|
+
class MockResponse
|
12
|
+
attr_accessor :body
|
13
|
+
end
|
14
|
+
|
15
|
+
include Rubaidh::GoogleAnalyticsMixin
|
16
|
+
attr_accessor :request, :response
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
self.request = MockRequest.new
|
20
|
+
self.response = MockResponse.new
|
21
|
+
end
|
22
|
+
|
23
|
+
# override the mixin's method
|
24
|
+
def google_analytics_code
|
25
|
+
"Google Code"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
7
30
|
class GoogleAnalyticsTest < Test::Unit::TestCase
|
8
31
|
def setup
|
9
32
|
@ga = Rubaidh::GoogleAnalytics.new
|
@@ -115,5 +138,45 @@ class GoogleAnalyticsTest < Test::Unit::TestCase
|
|
115
138
|
foo = Rubaidh::GoogleAnalytics.request_tracked_path
|
116
139
|
assert_nil(Rubaidh::GoogleAnalytics.override_trackpageview)
|
117
140
|
end
|
118
|
-
|
141
|
+
|
142
|
+
# Test the before_filter method does what we expect by subsituting the body tags and inserting
|
143
|
+
# some google code for us automagically.
|
144
|
+
def test_add_google_analytics_code
|
145
|
+
# setup our test mixin
|
146
|
+
mixin = TestMixin.new
|
147
|
+
|
148
|
+
# bog standard body tag
|
149
|
+
Rubaidh::GoogleAnalytics.defer_load = false
|
150
|
+
mixin.response.body = "<body><p>some text</p></body>"
|
151
|
+
mixin.add_google_analytics_code
|
152
|
+
assert_equal mixin.response.body, '<body>Google Code<p>some text</p></body>'
|
153
|
+
|
154
|
+
Rubaidh::GoogleAnalytics.defer_load = true
|
155
|
+
mixin.response.body = "<body><p>some text</p></body>"
|
156
|
+
mixin.add_google_analytics_code
|
157
|
+
assert_equal mixin.response.body, '<body><p>some text</p>Google Code</body>'
|
158
|
+
|
159
|
+
# body tag upper cased (ignoring this is semantically incorrect)
|
160
|
+
Rubaidh::GoogleAnalytics.defer_load = false
|
161
|
+
mixin.response.body = "<BODY><p>some text</p></BODY>"
|
162
|
+
mixin.add_google_analytics_code
|
163
|
+
assert_equal mixin.response.body, '<BODY>Google Code<p>some text</p></BODY>'
|
164
|
+
|
165
|
+
Rubaidh::GoogleAnalytics.defer_load = true
|
166
|
+
mixin.response.body = "<BODY><p>some text</p></BODY>"
|
167
|
+
mixin.add_google_analytics_code
|
168
|
+
assert_equal mixin.response.body, '<BODY><p>some text</p>Google Code</body>'
|
169
|
+
|
170
|
+
# body tag has additional attributes
|
171
|
+
Rubaidh::GoogleAnalytics.defer_load = false
|
172
|
+
mixin.response.body = '<body style="background-color:red"><p>some text</p></body>'
|
173
|
+
mixin.add_google_analytics_code
|
174
|
+
assert_equal mixin.response.body, '<body style="background-color:red">Google Code<p>some text</p></body>'
|
175
|
+
|
176
|
+
Rubaidh::GoogleAnalytics.defer_load = true
|
177
|
+
mixin.response.body = '<body style="background-color:red"><p>some text</p></body>'
|
178
|
+
mixin.add_google_analytics_code
|
179
|
+
assert_equal mixin.response.body, '<body style="background-color:red"><p>some text</p>Google Code</body>'
|
180
|
+
end
|
181
|
+
|
119
182
|
end
|
data/test/test_helper.rb
CHANGED
@@ -3,6 +3,5 @@ ENV['RAILS_ENV'] = 'test'
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'test/unit'
|
5
5
|
|
6
|
-
|
7
|
-
require
|
8
|
-
|
6
|
+
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
7
|
+
require 'google_analytics'
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_analytics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Graeme Mathieson
|
8
|
+
- Rubaidh Ltd
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date: 2009-
|
13
|
+
date: 2009-05-11 00:00:00 +01:00
|
13
14
|
default_executable:
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
@@ -32,16 +33,23 @@ dependencies:
|
|
32
33
|
- !ruby/object:Gem::Version
|
33
34
|
version: "0"
|
34
35
|
version:
|
35
|
-
description:
|
36
|
+
description: |
|
37
|
+
By default this gem will output google analytics code forevery page automatically, if it's configured correctly.This is done by adding:
|
38
|
+
Rubaidh::GoogleAnalytics.tracker_id = 'UA-12345-67'
|
39
|
+
|
36
40
|
email: mathie@rubaidh.com
|
37
41
|
executables: []
|
38
42
|
|
39
43
|
extensions: []
|
40
44
|
|
41
|
-
extra_rdoc_files:
|
42
|
-
|
45
|
+
extra_rdoc_files:
|
46
|
+
- README.rdoc
|
47
|
+
- CHANGELOG
|
48
|
+
- CREDITS
|
49
|
+
- MIT-LICENSE
|
43
50
|
files:
|
44
51
|
- CREDITS
|
52
|
+
- CHANGELOG
|
45
53
|
- MIT-LICENSE
|
46
54
|
- README.rdoc
|
47
55
|
- Rakefile
|
@@ -50,14 +58,21 @@ files:
|
|
50
58
|
- test/test_helper.rb
|
51
59
|
- test/view_helpers_test.rb
|
52
60
|
- lib/rubaidh.rb
|
61
|
+
- lib/google_analytics.rb
|
53
62
|
- lib/rubaidh/google_analytics.rb
|
54
63
|
- lib/rubaidh/view_helpers.rb
|
55
64
|
- tasks/google_analytics.rake
|
56
65
|
has_rdoc: true
|
57
66
|
homepage: http://rubaidh.com/portfolio/open-source/google-analytics/
|
58
|
-
|
59
|
-
rdoc_options: []
|
67
|
+
licenses: []
|
60
68
|
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options:
|
71
|
+
- --title
|
72
|
+
- Google Analytics
|
73
|
+
- --main
|
74
|
+
- README.rdoc
|
75
|
+
- --line-numbers
|
61
76
|
require_paths:
|
62
77
|
- lib
|
63
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -75,9 +90,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
90
|
requirements: []
|
76
91
|
|
77
92
|
rubyforge_project: rubaidh
|
78
|
-
rubygems_version: 1.3.
|
93
|
+
rubygems_version: 1.3.3
|
79
94
|
signing_key:
|
80
|
-
specification_version:
|
95
|
+
specification_version: 3
|
81
96
|
summary: "[Rails] Easily enable Google Analytics support in your Rails application."
|
82
97
|
test_files: []
|
83
98
|
|