Method: BitAnalytics#mark_event
- Defined in:
- lib/bit_analytics.rb
#mark_event(event_name, uuid, now: nil, track_hourly: nil) ⇒ Object
Marks an event for hours, days, weeks and months.
-
event_name
- The name of the event, could be “active” or “new_signups” -
uuid
- An unique id, typically user id. The id should not be huge, read Redis documentation why (bitmaps) -
now
- Which date should be used as a reference point, default is ‘Time.now.getutc` -
track_hourly
- Should hourly stats be tracked
Example
Mark id 1 as active @bit_analytics.mark_event(‘active’, 1) Mark task completed for id 252 @bit_analytics.mark_event(‘tasks:completed’, 252)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bit_analytics.rb', line 27 def mark_event(event_name, uuid, now: nil, track_hourly: nil) # Has memory applications track_hourly ||= false now ||= Time.now.getutc # E.g. ['2014', '03'] for 17th of January 2014 iso_date = now.strftime('%Y-%V').split('-') events = [ MonthEvents.new(event_name, now.year, now.month), WeekEvents.new(event_name, iso_date[0], iso_date[1]), DayEvents.new(event_name, now.year, now.month, now.day), ] if track_hourly events << HourEvents.new(event_name, now.year, now.month, now.day, now.hour) end @redis.pipelined do events.each do |event| @redis.setbit(event.redis_key, uuid, 1) end end end |