rack-google-analytics 0.6.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- = rack-google-analytics
1
+ # rack-google-analytics
2
2
 
3
3
  Simple Rack middleware to help injecting the google analytics tracking code into the footer of your websites.
4
4
 
@@ -10,7 +10,7 @@ As of `0.2.0` there are no tests as I have not had chance to do this right.
10
10
 
11
11
  Version 0.2.0 implements the default code to be the asynchronous google code (see: http://bit.ly/async-analytics ).
12
12
 
13
- == Usage
13
+ ## Usage
14
14
 
15
15
  require 'rack-google-analytics'
16
16
  use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x'
@@ -22,30 +22,17 @@ Note: since 0.2.0 this will use the asynchronous google tracker code, for the tr
22
22
 
23
23
  If you are not sure what's best, go with the defaults, and read here if you should opt-out
24
24
 
25
- == Environments
26
-
27
- There is a Rails-only (send a patch!) feature for only enabling this in certain environments, you can specify which by sending the `:env => 'some-env'` option when initializing the code. (Right now this conditionally requires the `Rails` constant.) The default is `production`.
28
-
29
- == Thread Safety
25
+ ## Thread Safety
30
26
 
31
27
  This middleware *should* be thread safe. Although my experience in such areas is limited, having taken the advice of those with more experience; I defer the call to a shallow copy of the environment, if this is of consequence to you please review the implementation.
32
28
 
33
- == Caveats
34
-
35
- 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.
36
-
37
- == Bugs & Feedback
38
-
39
- More than welcome, of course please see the notes below for contributor's tips, otherwise drop me a mail or open an issue.
40
-
41
- This was of course software to scratch my itch; but I'd love to build on it and learn from the experiences of others using it.
42
-
43
- == Change Log
29
+ ## Change Log
44
30
 
31
+ * 22-07-2010 Major re-write from Arthur Chiu, now correctly writes the Content-Length leader, and comes with tests (High five to @achiu) - this patch also backs-out the changes from @cimm - but they were un-tested (I intend to bring these back as soon as possible; this will probably constitute a 1.0 release when it happens)
45
32
  * 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`
46
33
  * 27-12-2009 First Release, extracted from the Capistrano-Website project and packaged with Jeweler.
47
34
 
48
- == Note on Patches/Pull Requests
35
+ ## Note on Patches/Pull Requests
49
36
 
50
37
  * Fork the project.
51
38
  * Make your feature addition or bug fix.
@@ -55,7 +42,7 @@ This was of course software to scratch my itch; but I'd love to build on it and
55
42
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
56
43
  * Send me a pull request. Bonus points for topic branches.
57
44
 
58
- == Copyright
45
+ ## Copyright
59
46
 
60
47
  Copyright (c) 2009 Lee Hambley. See LICENSE for details.
61
- With thanks to Ralph von der Heyden http://github.com/ralph/ and Simon `cimm` Schoeters http://github.com/cimm/
48
+ With thanks to Ralph von der Heyden http://github.com/ralph/ and Simon `cimm` Schoeters http://github.com/cimm/ - And the biggest hand to Arthur `achiu` Chiu for the huge work that went into the massive 0.9 re-factor.
data/Rakefile CHANGED
@@ -1,24 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "rack-google-analytics"
8
- gem.summary = %Q{Rack middleware to insert google analytics tracking code into the footer of HTML documents as served}
9
- gem.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}
10
- gem.email = "lee.hambley@gmail.com"
11
- gem.homepage = "http://github.com/leehambley/rack-google-analytics"
12
- gem.authors = ["Lee Hambley"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
- gem.add_development_dependency "yard", ">= 0"
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
- end
21
-
22
4
  require 'rake/testtask'
23
5
  Rake::TestTask.new(:test) do |test|
24
6
  test.libs << 'lib' << 'test'
@@ -39,8 +21,6 @@ rescue LoadError
39
21
  end
40
22
  end
41
23
 
42
- task :test => :check_dependencies
43
-
44
24
  task :default => :test
45
25
 
46
26
  begin
metadata CHANGED
@@ -4,66 +4,33 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 6
8
- - 1
9
- version: 0.6.1
7
+ - 9
8
+ - 0
9
+ version: 0.9.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Lee Hambley
13
+ - Arthur Chiu
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-07-06 00:00:00 +02:00
18
+ date: 2010-07-22 00:00:00 +02:00
18
19
  default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: thoughtbot-shoulda
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
31
- type: :development
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: yard
35
- prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
37
- none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- version: "0"
44
- type: :development
45
- version_requirements: *id002
20
+ dependencies: []
21
+
46
22
  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
47
- email: lee.hambley@gmail.com
23
+ email: lee.hambley@gmail.com, Mr.Arthur.Chiu@gmail.com
48
24
  executables: []
49
25
 
50
26
  extensions: []
51
27
 
52
- extra_rdoc_files:
53
- - LICENSE
54
- - README.rdoc
28
+ extra_rdoc_files: []
29
+
55
30
  files:
56
- - ._README.rdoc
57
- - .document
58
- - .gitignore
59
31
  - LICENSE
60
- - README.rdoc
32
+ - README.md
61
33
  - Rakefile
62
- - VERSION
63
- - lib/._rack-google-analytics.rb
64
- - lib/rack-google-analytics.rb
65
- - test/helper.rb
66
- - test/test_rack-google-analytics.rb
67
34
  has_rdoc: true
68
35
  homepage: http://github.com/leehambley/rack-google-analytics
69
36
  licenses: []
@@ -96,6 +63,5 @@ rubygems_version: 1.3.7
96
63
  signing_key:
97
64
  specification_version: 3
98
65
  summary: Rack middleware to insert google analytics tracking code into the footer of HTML documents as served
99
- test_files:
100
- - test/helper.rb
101
- - test/test_rack-google-analytics.rb
66
+ test_files: []
67
+
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,25 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
22
- ._*
23
- *.gem
24
- pkg/*
25
- rack-google-analytics.gemspec
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.6.1
@@ -1,68 +0,0 @@
1
- module Rack
2
-
3
- class GoogleAnalytics
4
-
5
- TRACKER_CODE = <<-EOTC
6
- <script type="text/javascript">
7
- var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
8
- document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
9
- </script>
10
- <script type="text/javascript">
11
- try{
12
- var pageTracker = _gat._getTracker("UA-xxxxxx-x");
13
- pageTracker._trackPageview();
14
- } catch(err) {}</script>
15
- EOTC
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
-
33
- def initialize(app, options = {})
34
- raise ArgumentError, "Tracker must be set!" unless options[:tracker] and !options[:tracker].empty?
35
- @app = app
36
- @tracker = options[:tracker]
37
- @async = options[:async]
38
- @async = true if options[:async].nil?
39
- @env = options[:env] || "production"
40
- end
41
-
42
- def call(env)
43
- dup._call(env)
44
- end
45
-
46
- def _call(env)
47
- @status, @headers, @response = @app.call(env)
48
- return [@status, @headers, @response] unless @headers['Content-Type'] =~ /html/ && defined?(Rails) && Rails.env.casecmp(@env) == 0
49
- @headers.delete('Content-Length')
50
- response = Rack::Response.new([], @status, @headers)
51
- @response.each do |fragment|
52
- response.write(inject_tracker(fragment))
53
- end
54
- response.finish
55
- end
56
-
57
- def inject_tracker(response)
58
- if @async
59
- tracker_code = ASYNC_TRACKER_CODE.sub(/UA-xxxxxx-x/, @tracker)
60
- else
61
- tracker_code = TRACKER_CODE.sub(/UA-xxxxxx-x/, @tracker)
62
- end
63
- response.sub!(/<\/body>/, "\n#{tracker_code}\n</body>") rescue response
64
- end
65
-
66
- end
67
-
68
- end
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'rack-google-analytics'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestRackGoogleAnalytics < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end