rack-google-analytics 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rack-google-analytics.rb +15 -16
- metadata +28 -13
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Rack
|
2
|
-
|
3
|
-
class
|
4
|
-
|
5
|
-
TRACKER_CODE = <<-EOTC
|
2
|
+
|
3
|
+
class GoogleTracker
|
4
|
+
|
5
|
+
TRACKER_CODE = <<-EOTC
|
6
6
|
<script type="text/javascript">
|
7
7
|
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
8
8
|
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
@@ -13,7 +13,7 @@ module Rack
|
|
13
13
|
pageTracker._trackPageview();
|
14
14
|
} catch(err) {}</script>
|
15
15
|
EOTC
|
16
|
-
|
16
|
+
|
17
17
|
ASYNC_TRACKER_CODE = <<-EOTC
|
18
18
|
<script type="text/javascript">
|
19
19
|
|
@@ -34,18 +34,18 @@ module Rack
|
|
34
34
|
raise ArgumentError, "Tracker must be set!" unless options[:tracker] and !options[:tracker].empty?
|
35
35
|
@app = app
|
36
36
|
@tracker = options[:tracker]
|
37
|
-
@async = options[:async]
|
37
|
+
@async = options[:async]
|
38
|
+
@async = true if options[:async].nil?
|
39
|
+
@env = options[:env] || "production"
|
38
40
|
end
|
39
|
-
|
41
|
+
|
40
42
|
def call(env)
|
41
43
|
dup._call(env)
|
42
44
|
end
|
43
|
-
|
45
|
+
|
44
46
|
def _call(env)
|
45
|
-
|
46
47
|
@status, @headers, @response = @app.call(env)
|
47
|
-
return [@status, @headers, @response] unless @headers['Content-Type'] =~ /html/
|
48
|
-
|
48
|
+
return [@status, @headers, @response] unless @headers['Content-Type'] =~ /html/ && defined?(Rails) && Rails.env.casecmp(@env) == 0
|
49
49
|
@headers.delete('Content-Length')
|
50
50
|
response = Rack::Response.new([], @status, @headers)
|
51
51
|
@response.each do |fragment|
|
@@ -53,17 +53,16 @@ module Rack
|
|
53
53
|
end
|
54
54
|
response.finish
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def inject_tracker(response)
|
58
58
|
if @async
|
59
59
|
tracker_code = ASYNC_TRACKER_CODE.sub(/UA-xxxxxx-x/, @tracker)
|
60
|
-
response.sub!(/<body>/, "<body>\n#{tracker_code}\n") rescue response
|
61
60
|
else
|
62
61
|
tracker_code = TRACKER_CODE.sub(/UA-xxxxxx-x/, @tracker)
|
63
|
-
response.sub!(/<\/body>/, "#{tracker_code}\n</body>") rescue response
|
64
62
|
end
|
63
|
+
response.sub!(/<\/body>/, "\n#{tracker_code}\n</body>") rescue response
|
65
64
|
end
|
66
|
-
|
65
|
+
|
67
66
|
end
|
68
|
-
|
67
|
+
|
69
68
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-google-analytics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Lee Hambley
|
@@ -9,29 +14,35 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-06-29 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: thoughtbot-shoulda
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
20
25
|
requirements:
|
21
26
|
- - ">="
|
22
27
|
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
23
30
|
version: "0"
|
24
|
-
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
25
33
|
- !ruby/object:Gem::Dependency
|
26
34
|
name: yard
|
27
|
-
|
28
|
-
|
29
|
-
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
33
43
|
version: "0"
|
34
|
-
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
35
46
|
description: A simple Rack middleware compatible with Rails, Merb, Sinatra, etc. Easily installed inserts the google tracking code directly before the </body> of your Content-Type="*html" documents
|
36
47
|
email: lee.hambley@gmail.com
|
37
48
|
executables: []
|
@@ -63,21 +74,25 @@ rdoc_options:
|
|
63
74
|
require_paths:
|
64
75
|
- lib
|
65
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
66
78
|
requirements:
|
67
79
|
- - ">="
|
68
80
|
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 0
|
69
83
|
version: "0"
|
70
|
-
version:
|
71
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
75
91
|
version: "0"
|
76
|
-
version:
|
77
92
|
requirements: []
|
78
93
|
|
79
94
|
rubyforge_project:
|
80
|
-
rubygems_version: 1.3.
|
95
|
+
rubygems_version: 1.3.7
|
81
96
|
signing_key:
|
82
97
|
specification_version: 3
|
83
98
|
summary: Rack middleware to insert google analytics tracking code into the footer of HTML documents as served
|