Giter VIP home page Giter VIP logo

mixpanel_client's Introduction

Mixpanel Data API Client

Gem Version Code Climate

Ruby access to the Mixpanel web analytics tool.

Mixpanel Data API Reference

Installation

gem install mixpanel_client

or if you use a Gemfile

gem 'mixpanel_client'

Usage

require 'rubygems'
require 'mixpanel_client'

client = Mixpanel::Client.new(
  api_key:    'changeme',
  api_secret: 'changeme'
)

data = client.request(
  'events/properties',
  event:     'splash features',
  name:      'feature',
  values:    '["uno", "dos"]',
  type:      'unique',
  unit:      'day',
  from_date: '2013-12-1',
  to_date:   '2014-3-1',
  limit:     5
)

puts data.inspect

# The API also supports passing a time interval rather than an explicit date range
data = client.request(
  'events/properties',
  event:    'splash features',
  name:     'feature',
  values:   '["uno", "dos"]',
  type:     'unique',
  unit:     'day',
  interval: 7,
  limit:    5
)

# Use the import API, which allows one to specify a time in the past, unlike the track API.
# note that you need to include your api token in the data. More details at:
# https://mixpanel.com/docs/api-documentation/importing-events-older-than-31-days
data_to_import = {'event' => 'firstLogin', 'properties' => {'distinct_id' => guid, 'time' => time_as_integer_seconds_since_epoch, 'token' => api_token}}
require 'base64' # co-located with the Base64 call below for clarity
encoded_data = Base64.encode64(data_to_import.to_json)
data = client.request('import', {:data => encoded_data, :api_key => api_key})
# data == [1] # => true # you can only import one event at a time

Parallel

You may also make requests in parallel by passing in the parallel: true option.

require 'rubygems'
require 'mixpanel_client'

client = Mixpanel::Client.new(
  api_key:    'changeme',
  api_secret: 'changeme',
  parallel:   true
)

first_request = client.request(
  'events/properties',
  ...
)

second_request = client.request(
  'events/properties',
  ...
)

third_request = client.request(
  'events/properties',
  ...
)

...

client.run_parallel_requests

puts first_request.response.handled_response
puts second_request.response.handled_response
puts third_request.response.handled_response

Development

List of rake tasks.

rake -T

Run specs.

rake spec

Run external specs.

cp config/mixpanel.template.yml config/mixpanel.yml
vi config/mixpanel.yml
rake spec:externals

Run rubocop and fix offences.

rubocop

Changelog

Changelog

Collaborators and Maintainers

Contributors

Copyright

Copyright (c) 2009+ Keolo Keagy. See license for details.

mixpanel_client's People

Contributors

alpinegizmo avatar bderusha avatar burnettk avatar ctborg avatar darrennix avatar hebo avatar jasonlogsdon avatar keolo avatar mferrier avatar pearsons avatar pedrogimenez avatar pwim avatar rgabo avatar rodxavier avatar seodma avatar wizardofcrowds avatar yaotti avatar

Watchers

 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.