Class: Rerout::Resources::Conversions

Inherits:
Object
  • Object
show all
Defined in:
lib/rerout/conversions_resource.rb

Overview

Conversion tracking namespace — record a conversion against a recorded click. Reach it via ‘client.conversions`.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Conversions

Returns a new instance of Conversions.

Parameters:



9
10
11
# File 'lib/rerout/conversions_resource.rb', line 9

def initialize(client)
  @client = client
end

Instance Method Details

#record(click_id, event_name, value_cents: nil, currency: nil) ⇒ Rerout::Models::RecordedConversion

Record a conversion for a click via ‘POST /v1/conversions`.

Parameters:

  • click_id (String)

    the id of the click being converted.

  • event_name (String)

    name of the conversion event (e.g. ‘“purchase”`).

  • value_cents (Integer, nil) (defaults to: nil)

    optional monetary value in the smallest currency unit (cents). Omitted when nil.

  • currency (String, nil) (defaults to: nil)

    optional ISO-4217 currency code (e.g. ‘“USD”`). Omitted when nil.

Returns:

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rerout/conversions_resource.rb', line 24

def record(click_id, event_name, value_cents: nil, currency: nil)
  raise ArgumentError, 'click_id is required' if click_id.nil? || click_id.to_s.empty?
  raise ArgumentError, 'event_name is required' if event_name.nil? || event_name.to_s.empty?

  body = { 'click_id' => click_id, 'event_name' => event_name }
  body['value_cents'] = value_cents unless value_cents.nil?
  body['currency'] = currency unless currency.nil?

  response = @client.request(method: :post, path: '/v1/conversions', body: body)
  Models::RecordedConversion.from_hash(response)
end