Class: Mixpanelable::EventBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mixpanelable/event_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ EventBuilder

Returns a new instance of EventBuilder.



5
6
7
8
9
10
11
# File 'lib/mixpanelable/event_builder.rb', line 5

def initialize(args = {})
  @active_record = args[:active_record]
  @name = args[:name]
  @properties = args[:properties]
  @unique_to_request = args[:unique_to_request]
  self
end

Instance Attribute Details

#active_recordObject (readonly)

Returns the value of attribute active_record.



3
4
5
# File 'lib/mixpanelable/event_builder.rb', line 3

def active_record
  @active_record
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/mixpanelable/event_builder.rb', line 3

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



3
4
5
# File 'lib/mixpanelable/event_builder.rb', line 3

def properties
  @properties
end

#unique_to_requestObject (readonly)

Returns the value of attribute unique_to_request.



3
4
5
# File 'lib/mixpanelable/event_builder.rb', line 3

def unique_to_request
  @unique_to_request
end

Instance Method Details

#distinct_idObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mixpanelable/event_builder.rb', line 17

def distinct_id
  case
  when active_record.present?
    distinct_id_for(active_record)
  when unique_to_request
    request_uuid
  when current_user.present?
    distinct_id_for(current_user)
  else
    guest_uuid
  end
end

#eventObject



13
14
15
# File 'lib/mixpanelable/event_builder.rb', line 13

def event
  Event.new(distinct_id: distinct_id, token: token, name: name, properties: properties)
end