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

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.



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

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
   = 
end

Instance Attribute Details

#goal_idObject (readonly)

Returns the value of attribute goal_id.



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

def goal_id
  @goal_id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



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

def 
  
end

#negativeObject (readonly)

Returns the value of attribute negative.



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

def negative
  @negative
end

#revenueObject (readonly)

Returns the value of attribute revenue.



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

def revenue
  @revenue
end

Instance Method Details

#obtain_full_post_text_lineObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kameleoon/data/conversion.rb', line 31

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

#to_sObject



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

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