Giter Site home page Giter Site logo

snogmetrics's Introduction

SNOGmetrics

SNOGmetrics is a bridge between Rails and KISSmetrics' JavaScript API.

But KISSmetrics has a Ruby API!

Yes, but it's not as good as the JavaScript one, they even say so themselves:

One thing to note about the Ruby API is that it is not as full featured as the JavaScript client. Therefore, in most cases we recommend using the JavaScript client. However, some things are easier to track server-side, therefore we have provided a basic Ruby client.

It's true, but why settle for either or?

SNOGmetrics works similarly to flash messages. Events are recorded and saved to the session, and are then sent when the next page is rendered. This way you get all of the benefits of the JavaScript API, but you can record events in your controllers. All you have to do is install this gem, configure it, and add a snipplet of code to your layout.

How do I use it?

  1. gem install snogmetrics
  2. Edit config/environment.rb and add config.gem 'snogmetrics'
  3. Edit your layout(s) and add <%= km.js! %> where you keep your JavaScript includes.
  4. Replace all your KM.record(...) and KM.identify(...) calls in JavaScript with calls to km.record(...) and km.identify(...)

Have a look at the included example application to see it in action.

Does it use the asynchronous API?

Yes it does.

What if I want to call KISSmetrics from both my controllers and JavaScript?

Just do it. You need to make sure that the _kmq array exists, though. SNOGmetrics will define it where you place <%= km.js! %>, but that is usually at the bottom of the page (with the async API you could probably put it at the top if you wanted to), so if you want to add things to _kmq before that you need to define it yourself. Just add var _kmq = _kmq || [] and you're set.

What about A/B testing

SNOGmetrics implements #set, which is equivalent to _kmq.push(["set", ...]), the preferred way of recording which version a user saw in an A/B test. SNOGmetrics does not support the KM.ab function, because that's something you want to do in JavaScript only.

Anything else I should know?

Yes, SNOGmetrics will not output the KISSmetrics API code unless RAILS_ENV is production. Instead it will output code that logs all calls to the console (if console is defined).

In a future version this behaviour might be overrideable.

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) 2010 Theo Hultberg / Burt. See LICENSE for details.

snogmetrics's People

Contributors

iconara avatar

Stargazers

Jason Morrison avatar

Watchers

James Cloos 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.