rack-google-analytics 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.rdoc +12 -2
- data/VERSION +1 -1
- data/lib/rack-google-analytics.rb +24 -2
- metadata +2 -3
- data/rack-google-analytics.gemspec +0 -59
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -4,12 +4,21 @@ Simple Rack middleware to help injecting the google analytics tracking code into
|
|
4
4
|
|
5
5
|
This middleware injects the code directly before the `</body>` tag of documents matching the `Content-Type` of `/html/` (therefore `text/html`). You should also be aware that as this rewrites the body length, the `Content-Length` header is also removed (sure, I could rewrite it, but i'm not aware of any benefits.)
|
6
6
|
|
7
|
-
As of `0.
|
7
|
+
As of `0.2.0` there are no tests as I have not had chance to do this right.
|
8
|
+
|
9
|
+
Version 0.2.0 implements the default code to be the asynchronous google code (see: http://bit.ly/async-analytics ).
|
8
10
|
|
9
11
|
== Usage
|
10
12
|
|
11
13
|
require 'rack-google-analytics'
|
12
14
|
use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x'
|
15
|
+
|
16
|
+
Note: since 0.2.0 this will use the asynchronous google tracker code, for the traditional behaviour please use:
|
17
|
+
|
18
|
+
require 'rack-google-analytics'
|
19
|
+
use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x', :async => false
|
20
|
+
|
21
|
+
If you are not sure what's best, go with the defaults, and read here if you should opt-out
|
13
22
|
|
14
23
|
== Thread Safety
|
15
24
|
|
@@ -17,7 +26,7 @@ This middleware *should* be thread safe. Although my experience in such areas is
|
|
17
26
|
|
18
27
|
== Caveats
|
19
28
|
|
20
|
-
I'm not aware of any, except
|
29
|
+
I'm not aware of any, except that I remove the `Content-Length` header; this may interfere with your caching, e-tags and other mechanisms, if you are aware of any problems, please report them via Github issue's system.
|
21
30
|
|
22
31
|
== Bugs & Feedback
|
23
32
|
|
@@ -27,6 +36,7 @@ This was of course software to scratch my itch; but I'd love to build on it and
|
|
27
36
|
|
28
37
|
== Change Log
|
29
38
|
|
39
|
+
* 19-01-2010 Second Release, patch from github.com/ralph - makes the default snippet the async version from google. Use regular synchronous code with: `:async => false`
|
30
40
|
* 27-12-2009 First Release, extracted from the Capistrano-Website project and packaged with Jeweler.
|
31
41
|
|
32
42
|
== Note on Patches/Pull Requests
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -14,10 +14,27 @@ module Rack
|
|
14
14
|
} catch(err) {}</script>
|
15
15
|
EOTC
|
16
16
|
|
17
|
+
ASYNC_TRACKER_CODE = <<-EOTC
|
18
|
+
<script type="text/javascript">
|
19
|
+
|
20
|
+
var _gaq = _gaq || [];
|
21
|
+
_gaq.push(['_setAccount', 'UA-xxxxxx-x']);
|
22
|
+
_gaq.push(['_trackPageview']);
|
23
|
+
|
24
|
+
(function() {
|
25
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
26
|
+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
27
|
+
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
|
28
|
+
})();
|
29
|
+
|
30
|
+
</script>
|
31
|
+
EOTC
|
32
|
+
|
17
33
|
def initialize(app, options = {})
|
18
34
|
raise ArgumentError, "Tracker must be set!" unless options[:tracker] and !options[:tracker].empty?
|
19
35
|
@app = app
|
20
36
|
@tracker = options[:tracker]
|
37
|
+
@async = options[:async] || true
|
21
38
|
end
|
22
39
|
|
23
40
|
def call(env)
|
@@ -38,8 +55,13 @@ module Rack
|
|
38
55
|
end
|
39
56
|
|
40
57
|
def inject_tracker(response)
|
41
|
-
|
42
|
-
|
58
|
+
if @async
|
59
|
+
tracker_code = ASYNC_TRACKER_CODE.sub(/UA-xxxxxx-x/, @tracker)
|
60
|
+
response.sub!(/<body>/, "<body>\n#{tracker_code}\n")
|
61
|
+
else
|
62
|
+
tracker_code = TRACKER_CODE.sub(/UA-xxxxxx-x/, @tracker)
|
63
|
+
response.sub!(/<\/body>/, "#{tracker_code}\n</body>")
|
64
|
+
end
|
43
65
|
end
|
44
66
|
|
45
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-google-analytics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Hambley
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-19 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -51,7 +51,6 @@ files:
|
|
51
51
|
- VERSION
|
52
52
|
- lib/._rack-google-analytics.rb
|
53
53
|
- lib/rack-google-analytics.rb
|
54
|
-
- rack-google-analytics.gemspec
|
55
54
|
- test/helper.rb
|
56
55
|
- test/test_rack-google-analytics.rb
|
57
56
|
has_rdoc: true
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{rack-google-analytics}
|
8
|
-
s.version = "0.1.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Lee Hambley"]
|
12
|
-
s.date = %q{2010-01-14}
|
13
|
-
s.description = %q{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}
|
14
|
-
s.email = %q{lee.hambley@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
"._README.rdoc",
|
21
|
-
".document",
|
22
|
-
".gitignore",
|
23
|
-
"LICENSE",
|
24
|
-
"README.rdoc",
|
25
|
-
"Rakefile",
|
26
|
-
"VERSION",
|
27
|
-
"lib/._rack-google-analytics.rb",
|
28
|
-
"lib/rack-google-analytics.rb",
|
29
|
-
"rack-google-analytics.gemspec",
|
30
|
-
"test/helper.rb",
|
31
|
-
"test/test_rack-google-analytics.rb"
|
32
|
-
]
|
33
|
-
s.homepage = %q{http://github.com/leehambley/rack-google-analytics}
|
34
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
-
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = %q{1.3.5}
|
37
|
-
s.summary = %q{Rack middleware to insert google analytics tracking code into the footer of HTML documents as served}
|
38
|
-
s.test_files = [
|
39
|
-
"test/helper.rb",
|
40
|
-
"test/test_rack-google-analytics.rb"
|
41
|
-
]
|
42
|
-
|
43
|
-
if s.respond_to? :specification_version then
|
44
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
-
s.specification_version = 3
|
46
|
-
|
47
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
-
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
49
|
-
s.add_development_dependency(%q<yard>, [">= 0"])
|
50
|
-
else
|
51
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
52
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
53
|
-
end
|
54
|
-
else
|
55
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
56
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|