Giter VIP home page Giter VIP logo

rack-google-analytics's Introduction

Rack google Analytics

Build Status

Simple Rack middleware to help injecting the Google Analytics tracking code in your website.

This middleware injects either the synchronous or asynchronous Google Analytics tracking code into the correct place of any request only when the response's Content-Type header contains html (therefore text/html and similar).

Usage

Gemfile

gem '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 2.X

## environment.rb:
config.gem 'rack-google-analytics', :lib => 'rack/google-analytics'
config.middleware.use Rack::GoogleAnalytics, :tracker => 'UA-xxxxxx-x'

Rails 3.X

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

Options

Note: since 0.2.0 this will use the asynchronous Google Analytics tracking code, for the traditional behaviour please use:

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.

Custom Variable Tracking

In your application controller, you may track a custom variable. For example:

set_ga_custom_var(1, "LoggedIn", value, GoogleAnalytics::CustomVar::SESSION_LEVEL)

See https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables for details.

Event Tracking

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

track_ga_event("Users", "Login", "Standard")

See https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide

Custom Push

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

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

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 and Simon Schoeters - And the biggest hand to Arthur Chiu for the huge work that went into the massive 0.9 re-factor.

rack-google-analytics's People

Contributors

achiurizo avatar briandonahue avatar cimm avatar ingooooooo avatar leehambley avatar lloydpick avatar ralph avatar rymai avatar salrepe avatar thibaudgg avatar tmaier avatar

Watchers

 avatar  avatar  avatar

Forkers

digideskio

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.