Class: Kameleoon::Conversion

Inherits:
DuplicationSafeData show all
Defined in:
lib/kameleoon/data/conversion.rb

Overview

Conversion class uses for tracking conversion

Instance Attribute Summary collapse

Attributes inherited from Data

#instance

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Data

#mark_as_sent, #mark_as_transmitting, #mark_as_unsent, #sent, #transmitting, #unsent

Constructor Details

#initialize(goal_id, revenue = 0.0, negative = false, metadata: nil) ⇒ Conversion

Returns a new instance of Conversion.

Parameters:

  • goal_id (Integer)

    Id of the goal associated to the conversion

  • revenue (Float) (defaults to: 0.0)

    Optional field - Revenue associated to the conversion.

  • negative (Boolean) (defaults to: false)

    Optional field - If the revenue is negative. By default it’s positive.

  • metadata (Array) (defaults to: nil)

    Optional field - Metadata of the conversion. Array of CustomData objects.



24
25
26
27
28
29
30
31
# File 'lib/kameleoon/data/conversion.rb', line 24

def initialize(goal_id, revenue = 0.0, negative = false, metadata: nil)
  super(DataType::CONVERSION)
  @goal_id = goal_id
  @revenue = revenue || 0.0
  @negative = negative || false
  @metadata = 
  @assignment_time = Time.now.to_f
end

Instance Attribute Details

#assignment_timeObject (readonly)

Returns the value of attribute assignment_time.



13
14
15
# File 'lib/kameleoon/data/conversion.rb', line 13

def assignment_time
  @assignment_time
end

#goal_idObject (readonly)

Returns the value of attribute goal_id.



13
14
15
# File 'lib/kameleoon/data/conversion.rb', line 13

def goal_id
  @goal_id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



13
14
15
# File 'lib/kameleoon/data/conversion.rb', line 13

def 
  @metadata
end

#negativeObject (readonly)

Returns the value of attribute negative.



13
14
15
# File 'lib/kameleoon/data/conversion.rb', line 13

def negative
  @negative
end

#revenueObject (readonly)

Returns the value of attribute revenue.



13
14
15
# File 'lib/kameleoon/data/conversion.rb', line 13

def revenue
  @revenue
end

Class Method Details

.build_internal(goal_id, revenue = 0.0, negative = false, metadata: nil, assignment_time: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
37
38
# File 'lib/kameleoon/data/conversion.rb', line 34

def self.build_internal(goal_id, revenue = 0.0, negative = false, metadata: nil, assignment_time: nil)
  conversion = new(goal_id, revenue, negative, metadata: )
  conversion.instance_variable_set(:@assignment_time, assignment_time || Time.now.to_f)
  conversion
end

Instance Method Details

#queryObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kameleoon/data/conversion.rb', line 40

def query
  params = {
    eventType: 'conversion',
    goalId: @goal_id,
    revenue: @revenue,
    negative: @negative,
    nonce: nonce
  }
  params[:metadata] =  if @metadata&.length&.positive?
  Kameleoon::Network::UriHelper.encode_query(params)
end

#to_sObject



15
16
17
18
# File 'lib/kameleoon/data/conversion.rb', line 15

def to_s
  "Conversion{goal_id:#{@goal_id},revenue:#{@revenue},negative:#{@negative}," \
  "metadata:#{Utils::Strval.obj_to_s(@metadata)},assignment_time:#{@assignment_time}}"
end