Class: Marketing::DataManager::EventsClient

Inherits:
Client
  • Object
show all
Defined in:
app/services/marketing/data_manager/events_client.rb

Overview

Data Manager API client specialized for conversion events (offline
click-conversion import — the Data Manager replacement for the Google Ads
API uploadClickConversions). The conversion action is the destination's
productDestinationId. Transport is inherited from Client.

Constant Summary collapse

MAX_EVENTS_PER_REQUEST =

Google's cap: 2,000 events per ingest request.

2_000

Constants inherited from Client

Client::API_BASE, Client::API_HOST, Client::GOOGLE_ADS, Client::HTTP_OPEN_TIMEOUT, Client::HTTP_TIMEOUT, Client::OAUTH_TOKEN_URL, Client::REQUIRED_KEYS

Instance Method Summary collapse

Methods inherited from Client

#initialize, #request_status

Constructor Details

This class inherits a constructor from Marketing::DataManager::Client

Instance Method Details

#ingest_events(conversion_action_id:, events:, validate_only: false) ⇒ String

Ingest conversion events against a Google Ads conversion action.

Parameters:

  • conversion_action_id (String)

    the conversion action id (productDestinationId)

  • events (Array<Hash>)

    Event payloads (see ConversionUploader)

  • validate_only (Boolean) (defaults to: false)

    dry-run without committing

Returns:

  • (String)

    the requestId

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/marketing/data_manager/events_client.rb', line 20

def ingest_events(conversion_action_id:, events:, validate_only: false)
  raise ArgumentError, "events exceeds #{MAX_EVENTS_PER_REQUEST} per request" if events.size > MAX_EVENTS_PER_REQUEST

  body = {
    destinations: [destination(conversion_action_id)],
    events: events,
    consent: { adUserData: 'CONSENT_GRANTED', adPersonalization: 'CONSENT_GRANTED' },
    encoding: 'HEX',
    validateOnly: validate_only
  }
  post('/v1/events:ingest', body).fetch('requestId').to_s
end