0.0
No commit activity in last 3 years
No release in over 3 years
Simple lib to track events in Mixpanel service. It can be used in any rack based framework.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
>= 0
>= 0
 Project Readme

What is Mixpanel (the service) ?¶ ↑

Mixpanel is a real-time analytics service that helps companies understand how users interact with web applications. mixpanel.com

What does this Gem do?¶ ↑

  • Track events with properties directly from your backend.

  • Track events with properties through javascript using a rack middleware.

How to install?¶ ↑

gem install mixpanel

How to use it with a Rails application?¶ ↑

In your environment config file add this.

Rails::Initializer.run do |config|

  config.middleware.use "MixpanelMiddleware", "YOUR_MIXPANEL_API_TOKEN"

If you want to use the asynchronous version of Mixpanel’s javascript API

Rails::Initializer.run do |config|

  config.middleware.use "MixpanelMiddleware", "YOUR_MIXPANEL_API_TOKEN", :async => true

In your application_controller class add a method to instance mixpanel.

before_filter :initialize_mixpanel

def initialize_mixpanel
  @mixpanel = Mixpanel.new("YOUR_MIXPANEL_API_TOKEN", request.env, true)
end

Then in each request you want to track some event you can use:

To track events directly from your backend…

@mixpanel.track_event("Sign in", {:some => "property"})

To track events after response with javascript…

@mixpanel.append_event("Sign in", {:some => "property"})

To execute any javascript API call

@mixpanel.append_api("register", {:some => "property"})
@mixpanel.append_api("identify", "Unique Identifier")

Notes¶ ↑

There are two forms of async operation:

  • Using MixpanelMiddleware, events are queued via Mixpanel#append_event and inserted into a JavaScript block within the HTML response.

  • Using Mixpanel.new(…, …, true), events are sent to a subprocess via a pipe and the sub process which asynchronously send events to Mixpanel. This process uses a single thread to upload events, and may start dropping events if your application generates them at a very high rate.

Collaborators and Maintainers¶ ↑