<NME> README.md
<BEF> # rack-google-analytics

Simple Rack middleware to help injecting the google analytics tracking code into the footer of your websites.

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.)

As of 0.6 the class is called Rack::GoogleAnalytics, in 0.5 and earlier this was incorrectly documented, and this name has now been decided upon.

As of `0.2.0` there are no tests as I have not had chance to do this right.

Version 0.2.0 implements the default code to be the asynchronous google code (see: http://bit.ly/async-analytics ).

## Usage

  require 'rack-google-analytics'
  use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x'
  
Note: since 0.2.0 this will use the asynchronous google tracker code, for the traditional behaviour please use:

## Usage

#### Gemfile

```ruby
gem 'rack-google-analytics'
```


## Change Log

* 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)
* 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`
* 27-12-2009 First Release, extracted from the Capistrano-Website project and packaged with Jeweler.
use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x'
```

#### Rails 3.X and Rails 4.X

```ruby
## application.rb:
config.middleware.use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x'
```

### Options

* `:anonymize_ip` -  sets the tracker to remove the last octet from all IP addresses, see https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApi_gat?hl=de#_gat._anonymizeIp for details.
* `:domain`     -  sets the domain name for the GATC cookies. Defaults to `auto`.
* `:site_speed_sample_rate` - Defines a new sample set size for Site Speed data collection, see https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiBasicConfiguration?hl=de#_gat.GA_Tracker_._setSiteSpeedSampleRate
* `:adjusted_bounce_rate_timeouts` - An array of times in seconds that the tracker will use to set timeouts for adjusted bounce rate tracking. See http://analytics.blogspot.ca/2012/07/tracking-adjusted-bounce-rate-in-google.html for details.
* `:enhanced_link_attribution` - Enables [Enhanced Link Attribution](https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#enhancedlink).
* `:advertising` - Enables [Display Features](https://developers.google.com/analytics/devguides/collection/analyticsjs/display-features).
* `:ecommerce` - Enables [Ecommerce Tracking](https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce).

If you are not sure what's best, go with the defaults, and read here if you should opt-out.

## Event Tracking

In your application controller, you may track an event. For example:

```ruby
ga_track_event("Users", "Login", "Standard")
```

See https://developers.google.com/analytics/devguides/collection/analyticsjs/events

## Custom Push

In your application controller, you may push arbritrary data. For example:

```ruby
ga_push("_addItem", "ID", "SKU")
```

## Dynamic Tracking Code

You may instead define your tracking code as a lambda taking the Rack environment, so that you may set the tracking code
dynamically based upon information in the Rack environment. For example:

```ruby
config.middleware.use Rack::GoogleAnalytics, :tracker => lambda { |env|
        return env[:site_ga].tracker if env[:site_ga]
}
```

## Special use case:  Event tracking only

If you already set up your Google Analytics `analytics.js` tracker object with pageview tracking in your templates/frontend (inside the `<head>`), the only thing you might want to use the `rack-google-analytics` middleware for is to track server-side events which you can't properly track in the forntend.  In that case simply use the middleware without specifying the `:tracker` option, then it will only render the event tracking code (`ga('send', hitType: 'event', ..)`) and nothing else.

    config.middleware.use Rack::GoogleAnalytics


## Thread Safety

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.

## Note on Patches/Pull Requests

* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
  future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
  (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)
* Send me a pull request. Bonus points for topic branches.

## Copyright

Copyright (c) 2009-2012 Lee Hambley. See LICENSE for details.
With thanks to [Ralph von der Heyden](https://github.com/ralph) and [Simon Schoeters](https://github.com/cimm) - And the biggest hand to [Arthur Chiu](https://github.com/achiu) for the huge work that went into the massive 0.9 re-factor.

<MSG> Fixing readme, and releasing 0.9.1

<DFF> @@ -1,18 +1,14 @@
-# rack-google-analytics
+# Rack google Analytics
 
 Simple Rack middleware to help injecting the google analytics tracking code into the footer of your websites.
 
-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.)
+This middleware injects either the synchronous or asynchronous google analytics tracker code into the correct place of any request with `Content-Type` containing `html` (therefore `text/html` and similar).
 
-As of 0.6 the class is called Rack::GoogleAnalytics, in 0.5 and earlier this was incorrectly documented, and this name has now been decided upon.
-
-As of `0.2.0` there are no tests as I have not had chance to do this right.
-
-Version 0.2.0 implements the default code to be the asynchronous google code (see: http://bit.ly/async-analytics ).
+Formerly this gem had an environments setting, that has been removed pending refactoring.
 
 ## Usage
 
-  require 'rack-google-analytics'
+  require 'rack/google-analytics'
   use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x'
   
 Note: since 0.2.0 this will use the asynchronous google tracker code, for the traditional behaviour please use:
@@ -28,6 +24,11 @@ This middleware *should* be thread safe. Although my experience in such areas is
 
 ## Change Log
 
+* 0.9.1 Updated readme to reflect 0.9.0 merge from achiu
+* 0.9.0 Include name changed from 'rack-google-analytics' to 'rack/google-analytics' more inline with the norm
+* 0.6.0 Class now named Rack::GoogleAnalytics, in 0.5 and earlier this was incorrectly documented as Rack::GoogleTracker
+* 0.2.0 Asynchronous code is now the default.
+
 * 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)
 * 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`
 * 27-12-2009 First Release, extracted from the Capistrano-Website project and packaged with Jeweler.

{'addition_count': 9, 'commit_subject': 'Fixing readme, and releasing 0.9.1', 'deletion_count': 8, 'file_extension': '.md', 'lang': 'md', 'license': 'mit', 'repo_name': 'kangguru/rack-google-analytics'}