Class: Invoicing::ConversionEventUploader
- Inherits:
-
Object
- Object
- Invoicing::ConversionEventUploader
- Defined in:
- app/services/invoicing/conversion_event_uploader.rb
Overview
Maps an offline click conversion to a Google Data Manager API events:ingest
payload and uploads it. This is the Data Manager replacement for the Google
Ads API uploadClickConversions path (offline conversions are being sunset on
the Google Ads API). The conversion action is the destination's
productDestinationId; the operating account comes from the
:google_data_manager credentials.
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#initialize(client: Marketing::DataManager::EventsClient.new) ⇒ ConversionEventUploader
constructor
A new instance of ConversionEventUploader.
-
#upload(conversion_action_id:, conversion_date_time:, conversion_value:, gclid: nil, gbraid: nil, wbraid: nil, hashed_email: nil, order_id: nil, validate_only: false) ⇒ Result
Upload one click conversion.
Constructor Details
#initialize(client: Marketing::DataManager::EventsClient.new) ⇒ ConversionEventUploader
Returns a new instance of ConversionEventUploader.
21 22 23 |
# File 'app/services/invoicing/conversion_event_uploader.rb', line 21 def initialize(client: Marketing::DataManager::EventsClient.new) @client = client end |
Instance Method Details
#upload(conversion_action_id:, conversion_date_time:, conversion_value:, gclid: nil, gbraid: nil, wbraid: nil, hashed_email: nil, order_id: nil, validate_only: false) ⇒ Result
Upload one click conversion. Exactly one of gclid/gbraid/wbraid must be set.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/services/invoicing/conversion_event_uploader.rb', line 36 def upload(conversion_action_id:, conversion_date_time:, conversion_value:, gclid: nil, gbraid: nil, wbraid: nil, hashed_email: nil, order_id: nil, validate_only: false) ids = { gclid:, gbraid:, wbraid: }.compact_blank return Result.new(status: :missing_identifier, request_id: nil, error: 'No gclid/gbraid/wbraid present') if ids.empty? if ids.size > 1 return Result.new(status: :failed_to_report, request_id: nil, error: "Exactly one of gclid/gbraid/wbraid expected, got #{ids.keys.join(', ')}") end event = build_event(ids, hashed_email:, conversion_date_time:, conversion_value:, order_id:) request_id = @client.ingest_events(conversion_action_id:, events: [event], validate_only:) Result.new(status: :reported, request_id:, error: nil) rescue StandardError => e Result.new(status: :failed_to_report, request_id: nil, error: e.) end |