Jirafe Analytics Ruby Client

Build Status Code Climate

This is the official Jirafe rubygem. It fully wraps Jirafe's API.

This client library can be used to add Jirafe analytics to your eCommerce software.


Note: If you are using ruby 1.8.x. You will also need to install a JSON library.

gem install jirafe

Or, add the jirafe gem to your project's Gemfile

gem "jirafe"

Then from your project's root, run:


If you're using Jirafe in a rails app, drop this into config/initializers/jirafe.rb:

Jirafe.configure do |config|
  config.token  = '12345abcde'                # required
  config.logger = Logger.new('/dev/null')     # defaults to Rails.logger or Logger.new(STDOUT).
                                              # Set to Logger.new('/dev/null') to disable logging.


Each resource in the Jirafe API is represented by an object e.g:

  • Jirafe::Resource::Application
  • Jirafe::Resource::Site
  • Jirafe::Resource::Sites::Products

To register a new application with Jirafe:

application = Jirafe::Resource::Application.create!(:name => "My New Account")

To get all sites associated with this application:


To send order data events:

site = application.sites.first

# Jirafe will send a GET request to your site's store_api_url with a confirmToken parameter
token = params['confirmToken']

event = Jirafe::Callback::Events::Order.new(:version => 1,
                                            :action => :create,
                                            :identifier => 1,
                                            :grand_total => 100.00,
                                            :sub_total => 80.00,
                                            :tax_amount => 20.00,
                                            :discount_amount => 0.00,
                                            :status => :pending)
Jirafe::Callback::Event.send(site.identifier, token, [event])

To place javascript tags for visit tracking:

data = { "id" => "999" } # 999 is your site id

Which will generate for placement on a page:

<script type='text/javascript' id='jirafe_analytics'>
  var jirafe = {"id":"999"};
  var d=document,g=d.createElement('script'),s=d.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(g, s);



The Jirafe gem uses rspec 2 for tests. To run the test suite, just type rake or bundle exec rake spec in the gem's base directory.

For troubleshooting you can set the following environment variables:

DEBUG_JIRAFE=true # prints out httparty details
CALLTHROUGH=true # Ignore VCR fixtures and call through to underlying service. For internal development only.


  1. Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  2. Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  3. Fork the project.
  4. Start a feature/bugfix branch
  5. Commit and push until you are happy with your contribution. Make sure to add tests so the change does not cause a regression.
  6. Send a pull request.


Test on Ruby 1.9.3-p194 and Ruby 1.8.7-p370


Copyright 2012, Jirafe, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at


Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.