Configuration

  • Configuration is managed via a Config class, accessible through configuration files, dynamic instantiation, or environment variables.

  • A google_ads_config.rb file can be used for configuration, with the library looking in the GOOGLE_ADS_CONFIGURATION_FILE_PATH environment variable or the user's home directory if no specific path is provided.

  • Dynamic configuration allows setting or modifying configuration fields during or after client instantiation.

  • Environment variables can be used for configuration but need to be loaded explicitly using load_environment_config.

Configuration is managed using the Config class. You can configure the client by using a configuration file, specifying values dynamically upon creation, or loading values from environment variables.

Configuration file

You can specify a google_ads_config.rb file to use when instantiating the client.

If you pass no arguments when instantiating a GoogleAdsClient object, the library searches for a configuration file in the following order:

  1. The path specified in the GOOGLE_ADS_CONFIGURATION_FILE_PATH environment variable.
  2. A file named google_ads_config.rb in your HOME directory (~/google_ads_config.rb).

Alternatively, you can pass an explicit path when instantiating the GoogleAdsClient object:

client = Google::Ads::GoogleAds::GoogleAdsClient.new('path/to/file.rb')

To generate this file, copy google_ads_config.rb from the GitHub repository and modify it to include your refresh token, client ID, and client secret.

Dynamic configuration

You can set up the configuration dynamically when instantiating the library:

client = Google::Ads::GoogleAds::GoogleAdsClient.new do |config|
  config.client_id = 'INSERT_CLIENT_ID_HERE'
  # ... additional configuration
end

You can also modify the configuration after instantiation (which overrides settings loaded during initialization):

client.configure do |config|
  config.login_customer_id = 'INSERT_LOGIN_CUSTOMER_ID_HERE'
  # ... additional configuration
end

Configuration fields

The Config object supports the following fields.

General fields:

  • refresh_token: Your OAuth refresh token (GOOGLE_ADS_REFRESH_TOKEN).
  • client_id: Your OAuth client ID (GOOGLE_ADS_CLIENT_ID).
  • client_secret: Your OAuth client secret (GOOGLE_ADS_CLIENT_SECRET).
  • keyfile: Path to a service account JSON key file (GOOGLE_ADS_JSON_KEY_FILE_PATH).
  • impersonate: Email address to impersonate when using a service account with domain-wide delegation (GOOGLE_ADS_IMPERSONATED_EMAIL).
  • use_application_default_credentials: Set to true to authenticate using Application Default Credentials (GOOGLE_ADS_USE_APPLICATION_DEFAULT_CREDENTIALS). Supported in google-ads-googleads v36.1.0 and later.
  • authentication: Custom authentication object, such as a Proc (updater_proc), keyfile path or Hash, or GRPC::Core::Channel / GRPC::Core::ChannelCredentials. Overrides client_id, client_secret, refresh_token, and keyfile.
  • login_customer_id: See the login-customer-id documentation (GOOGLE_ADS_LOGIN_CUSTOMER_ID).
  • linked_customer_id: The linked customer ID (GOOGLE_ADS_LINKED_CUSTOMER_ID).
  • ads_assistant: Optional identifier for the Google Ads API Assistant header (GOOGLE_ADS_ASSISTANT; added as gaada in v37.0.0 and renamed to ads_assistant in v39.0.0).
  • http_proxy: Optional HTTP or HTTPS proxy URI (GOOGLE_ADS_RUBY_HTTP_PROXY).
  • api_endpoint: Optional API endpoint override (GOOGLE_ADS_ENDPOINT).
  • treat_deprecation_warnings_as_errors: Raise an exception instead of calling Warning#warn when deprecated library code is invoked (false by default).
  • warn_on_all_deprecations: Issue a deprecation warning on every call rather than once per call site (false by default).

Log fields (see the logging guide for complete details):

  • log_level: The minimum log level messages you want logged. For example, specifying 'DEBUG' logs all messages, and specifying 'INFO' excludes DEBUG messages while showing all other messages.
  • log_target: Where you want to log to, such as STDERR or a path.
  • logger: Specify your own custom logger. Specifying this overrides both log_level and log_target.

Environment variables

You can configure the client library using environment variables. They are not loaded by default, and require an explicit call after instantiating the client in order to load. See the complete list of standard environment variables.

To load the environment variables into your Config, call load_environment_config:

client = Google::Ads::GoogleAds::GoogleAdsClient.new
client.load_environment_config

Each time load_environment_config is called, any defined environment variables overwrite corresponding values already present in the Config (unset environment variables leave existing configuration values unchanged). With this mechanism, you can maintain a default configuration file and override specific values using environment variables, or configure the client entirely with environment variables.

In addition to the standard environment variables, the Ruby library supports two additional variables:

  • GOOGLE_ADS_RUBY_LOG_LEVEL: Equivalent to log_level as explained earlier.
  • GOOGLE_ADS_RUBY_HTTP_PROXY: Specify an HTTP proxy URL.