GithubHelp home page GithubHelp logo

where / analytical Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jkrall/analytical

1.0 37.0 0.0 270 KB

Gem for managing multiple analytics services in your rails app.

Home Page: http://transfs.com/devblog/2010/05/05/tame-your-analytics-libraries-with-analytical/

License: MIT License

JavaScript 6.08% Ruby 93.92%

analytical's Introduction

Analytical

Gem for managing multiple analytics services in your rails app.

Service implementations include:

Usage

Add the following to your controllers:

analytical :modules=>[:console, :google, :clicky]

Add a configuration file (config/analytical.yml) to declare your API keys, like so:

google:
  key: UA-5555555-5
clicky:
  key: 55555

Then, in your template files, you’ll want to add the analytical helper methods for initializing the tracking javascript:

<!DOCTYPE html>
<html>
  <head>
    <%= raw analytical.head_prepend_javascript %>
    <title>Example</title>
    <%= stylesheet_link_tag :all %>
    <%= javascript_include_tag :defaults %>
    <%= csrf_meta_tag %>
    <% analytical.identify '5', :email=>'[email protected]' %>
    <%= raw analytical.head_append_javascript %>
  </head>
  <body>
    <%= raw analytical.body_prepend_javascript %>
    <%= yield %>
    <%= raw analytical.body_append_javascript %>
  </body>
</html>

Note the example above also includes an identify() command that will apply to every page. More likely, you’ll want to make this identify() command conditional so that it only applies when you have a logged-in user:

<% analytical.identify(current_user.id, :email=>current_user.email) if current_user %>

You can sprinkle the track() and event() tracking methods throughout your views & controllers as needed.

analytical.track '/a/really/nice/url'
analytical.event 'Some Awesome Event', :with=>:data

By default, Analytical will be disabled in development mode… and it will enable the Console module only. To change this behavior, you can pass a Proc/lambda to the :disable_if option, as well as specify the :development_modules that you want to use:

analytical :modules=>[:google], :development_modules=>[], :disable_if=>lambda{ |controller| controller.i_can_haz_tracking? }

Adding new modules

New modules should be fairly easy to add. Follow the structure that I’ve used in the Clicky, Google, and KISSMetrics modules… and you should be fine. All modules should include the Analytical::Base::Api module, so that they have some default behavior for methods that they don’t support or need.

Note on Patches/Pull Requests

I would be extremely happy to accept contributions to this project! If you think something should work differently, send me a message and I’d love to discuss your ideas. Even better:

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add specs 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.

Current Contributors

These fine folks have contributed patches and new features to this project:

Thanks guys!

Copyright © 2010 Joshua Krall. See LICENSE for details.

analytical's People

Contributors

bryanl avatar jingta avatar jkrall avatar nwp avatar scudco avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

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.