Page Summary
-
Configuration is managed via a
Configclass, accessible through configuration files, dynamic instantiation, or environment variables. -
A
google_ads_config.rbfile can be used for configuration, with the library looking in theGOOGLE_ADS_CONFIGURATION_FILE_PATHenvironment 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:
- The path specified in the
GOOGLE_ADS_CONFIGURATION_FILE_PATHenvironment variable. - A file named
google_ads_config.rbin yourHOMEdirectory (~/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 totrueto authenticate using Application Default Credentials (GOOGLE_ADS_USE_APPLICATION_DEFAULT_CREDENTIALS). Supported ingoogle-ads-googleadsv36.1.0 and later.authentication: Custom authentication object, such as aProc(updater_proc), keyfile path orHash, orGRPC::Core::Channel/GRPC::Core::ChannelCredentials. Overridesclient_id,client_secret,refresh_token, andkeyfile.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 asgaadain v37.0.0 and renamed toads_assistantin 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 callingWarning#warnwhen deprecated library code is invoked (falseby default).warn_on_all_deprecations: Issue a deprecation warning on every call rather than once per call site (falseby 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'excludesDEBUGmessages while showing all other messages.log_target: Where you want to log to, such asSTDERRor a path.logger: Specify your own custom logger. Specifying this overrides bothlog_levelandlog_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 tolog_levelas explained earlier.GOOGLE_ADS_RUBY_HTTP_PROXY: Specify an HTTP proxy URL.