Module: MixpanelRubyBatch::Events
- Defined in:
- lib/mixpanel-ruby-batch/events.rb
Instance Method Summary collapse
-
#track_batch(distinct_id, events, ip = nil) ⇒ Object
Tracks a batch of events for a single distinct_id.
Instance Method Details
#track_batch(distinct_id, events, ip = nil) ⇒ Object
Tracks a batch of events for a single distinct_id. Events should be passed as an array, with each element either a Hash or a string. Each Hash element should have a single key (the event name, as a string) with the value a Hash of properties. Each string element will be interpreted as an event name with no properties.
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"
}
}])
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mixpanel-ruby-batch/events.rb', line 29 def track_batch(distinct_id, events, ip=nil) data = events.map do |event_name_or_hash| event = event_name_or_hash properties = {} if event_name_or_hash.is_a?(Hash) event_data = event_name_or_hash.flatten event = event_data[0] properties = event_data[1] end properties = { "distinct_id" => distinct_id, "token" => @token, "time" => Time.now.to_i, "mp_lib" => "ruby", "$lib_version" => Mixpanel::VERSION }.merge(properties) properties["ip"] = ip if ip { "event" => event, "properties" => properties } end data.each_slice(50) do |slice| = { "data" => slice } @sink.call(:event, .to_json) end end |