README.rdoc in mixpanel-1.0.0 vs README.rdoc in mixpanel-1.1.1
- old
+ new
@@ -26,10 +26,16 @@
Rails::Initializer.run do |config|
config.middleware.use "Mixpanel::Tracker::Middleware", "YOUR_MIXPANEL_API_TOKEN", :async => true
+By default the scripts are inserted into the head of the html response. If you'd prefer the scripts to run after all rendering has completed you can set the insert_js_last flag and they'll be added at the end of the body tag. This will work whether or not you opt for the aynchronous version of the API. However, when inserting js into an ajax response it will have no effect:
+
+ Rails::Initializer.run do |config|
+
+ config.middleware.use "Mixpanel::Tracker::Middleware", "YOUR_MIXPANEL_API_TOKEN", :async => true, :insert_js_last => true
+
In your application_controller class add a method to instance mixpanel.
before_filter :initialize_mixpanel
def initialize_mixpanel
@@ -49,11 +55,41 @@
To execute any javascript API call
@mixpanel.append_api("register", {:some => "property"})
@mixpanel.append_api("identify", "Unique Identifier")
+== Resque and Rails example
+If you don't want to use the built in Mixpanel Gem async feature bellow there is an example about how to make async calls using Resque.
+
+{Resque is a Redis-backed Ruby library for creating background jobs}[https://github.com/defunkt/resque]
+
+ class MixpanelTrackEventJob
+ @queue = :slow
+
+ def mixpanel(request_env)
+ Mixpanel.new(MIXPANEL_TOKEN, request_env)
+ end
+
+ def perform(name, params, request_env)
+ mixpanel(request_env).track_event(name, params)
+ end
+ end
+
+ class UsersController < ApplicationController
+ def create
+ @user = User.new(params[:user])
+
+ if @user.save
+ MixpanelTrackEventJob.enqueue("Sign up", {:invited => params[:invited]}, request.env)
+ redirect_to user_root_path
+ else
+ render :new
+ end
+ end
+ end
+
== 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.
@@ -62,12 +98,17 @@
For a short term this method will be accepted but it will be deprecated soon.
Mixpanel.new
+== Collaborations
+
+All collaborations are welcome to this project, please fork and make a pull request.
+
== Collaborators and Maintainers
* {Alvaro Gil}[https://github.com/zevarito] (Author)
* {Nathan Baxter}[https://github.com/LogicWolfe]
* {Jake Mallory}[https://github.com/tinomen]
* {Logan Bowers}[https://github.com/loganb]
-* {jakemack} [https://github.com/jakemack]
+* {jakemack}[https://github.com/jakemack]
+* {James Ferguson}[https://github.com/JamesFerguson]