mixpanel-ruby-batch
Simple batch operations using mixpanel-ruby
mixpanel-ruby-batch adds a simple interface for performing batch operations
using the mixpanel-ruby[https://github.com/mixpanel/mixpanel-ruby] gem.
mixpanel-ruby[https://github.com/mixpanel/mixpanel-ruby] already provides a BufferedConsumer class to
facilitate batch operations:
buffered_consumer = Mixpanel::BufferedConsumer.new
begin
tracker = Mixpanel::Tracker.new(YOUR_TOKEN) do |type, message|
buffered_consumer.send(type, message)
end
tracker.track("Signup Begin")
tracker.track("Signup Complete", {'User Sign-up Cohort' => 'July 2013'})
tracker.track("Welcome Email Sent", {
'Email Template' => 'Pretty Pink Welcome',
'User Sign-up Cohort' => 'July 2013'
})
ensure
buffered_consumer.flush
end
mixpanel-ruby-batch adds a slightly higher-level API by adding the
Mixpanel::Events#track_batch
and Mixpanel::People#batch
methods.
Installation
gem install mixpanel-ruby-batch
Usage
tracker = Mixpanel::Tracker.new
tracker.track_batch("12345", [
"Signup Begin",
{
"Signup Complete" => {
"User Sign-up Cohort" => "July 2013"
}
},
{
"Welcome Email Sent" => {
"Email Template" => "Pretty Pink Welcome",
"User Sign-up Cohort" => "July 2013"
}
}])
tracker = Mixpanel::Tracker.new
tracker.people.batch([
{
"12345" => {
"$set" => {
"$firstname" => "David"
},
"$unset" => ["Levels Completed"]
}
},
{
"67890" => {
"$set" => {
"$firstname" => "Mick"
},
"$unset" => ["Levels Completed"]
}
}
])
Both methods handle slicing the data into 50-message chunks, so it is safe to
pass as many messages to either message as memory will allow.
Additional Information
For more information please visit: