diff --git a/README.md b/README.md index b23163a..4681322 100755 --- a/README.md +++ b/README.md @@ -8,13 +8,35 @@ Formerly this gem had an environments setting, that has been removed pending ref ## Usage - require 'rack/google-analytics' - use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x' +#### Gemfile: + gem 'rack-google-analytics', :require => 'rack/google-analytics' + +#### Sinatra + ## app.rb + use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x' + +#### Padrino + + ## app/app.rb + use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x' + +#### Rails + + ## environment.rb: + config.gem 'rack-google-analytcs', :lib => 'rack/google-analytics' + config.middleware.use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x' + + +### Options + +* :async - sets to use asyncronous tracker +* :multiple - sets track for multiple sub domains. (must also set :domain) +* :top_level - sets tracker for multiple top-level domains. (must also set :domain) + Note: since 0.2.0 this will use the asynchronous google tracker code, for the traditional behaviour please use: - require 'rack-google-analytics' - use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x', :async => false + use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x', :async => false If you are not sure what's best, go with the defaults, and read here if you should opt-out diff --git a/lib/rack/google-analytics.rb b/lib/rack/google-analytics.rb index 8f66356..e829215 100644 --- a/lib/rack/google-analytics.rb +++ b/lib/rack/google-analytics.rb @@ -32,7 +32,7 @@ def inject(response) if @options[:async] response.gsub(%r{}, @template.result(binding) + "") else - response.gsub(%r{}, "" + @template.result(binding)) + response.gsub(%r{}, @template.result(binding) + "") end end diff --git a/lib/rack/templates/async.erb b/lib/rack/templates/async.erb index 6b01a5a..6c010e0 100644 --- a/lib/rack/templates/async.erb +++ b/lib/rack/templates/async.erb @@ -10,6 +10,7 @@ _gaq.push(['_setAllowLinker', true]); <% end %> _gaq.push(['_trackPageview']); + _gaq.push(['_trackPageLoadTime']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; diff --git a/test/test_rack-google-analytics.rb b/test/test_rack-google-analytics.rb index 09e2ccf..5c5d210 100755 --- a/test/test_rack-google-analytics.rb +++ b/test/test_rack-google-analytics.rb @@ -10,7 +10,7 @@ class TestRackGoogleAnalytics < Test::Unit::TestCase assert_match %r{\_gaq\.push}, last_response.body assert_match %r{\'\_setAccount\', \"somebody\"}, last_response.body assert_match %r{}, last_response.body - assert_equal "495", last_response.headers['Content-Length'] + assert_equal "532", last_response.headers['Content-Length'] end should "not add tracker to none html content-type" do @@ -31,7 +31,7 @@ class TestRackGoogleAnalytics < Test::Unit::TestCase should "add multiple domain script" do get "/" assert_match %r{'_setDomainName', \"mydomain.com\"}, last_response.body - assert_equal "542", last_response.headers['Content-Length'] + assert_equal "579", last_response.headers['Content-Length'] end end @@ -51,7 +51,7 @@ class TestRackGoogleAnalytics < Test::Unit::TestCase should "show non-asyncronous tracker" do get "/bob" assert_match %r{_gat._getTracker}, last_response.body - assert_match %r{}, last_response.body assert_match %r{\"whatthe\"}, last_response.body end end