Learn more about migrating to the Google Ads API by watching our latest webinar

Configuration

Configuration is done using a Config class. You can access this class in multiple ways, such as writing a configuration file, specifying values on 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 use no arguments when instantiating:

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

then the library will look in the location specified in the GOOGLE_ADS_CONFIGURATION_FILE_PATH environment variable. If that variable is not set, then the library will look in your HOME directory for the file.

Alternatively, you can specify a path:

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

in which case the client will look for the file at that filepath.

The easiest way to generate this file is to copy the 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, or even afterwards:

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

You can even modify the configuration after instantiation:

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

Configuration fields

The Config object supports the following fields.

General fields:

  • refresh_token: Your OAuth refresh token.
  • client_id: Your OAuth client ID.
  • client_secret: Your OAuth client secret.
  • developer_token: Your developer token for accessing the API.
  • login_customer_id: See the login-customer-id documentation.

Logging fields. See the logging guide for complete details.

  • log_level: The minimum log level messages you want logged. For example, specifying 'DEBUG' will ensure you see all log messages, and specifying 'INFO' will exclude DEBUG messages but show all other messages.
  • log_target: Where you want to log to, such as STDERR.
  • logger: Specify your own custom logger. Specifying this will override 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 additional call after instantiating the client in order to load. See the complete list of environment variables supported by all languages.

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

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

Each time this is called, the current state of the environment variables will overwrite anything that is already present in the Config. With this mechanism, you can for example have a default config but override specific values using environment variables, or you can entirely configure with environment variables.

In addition to the environment variables supported by all libraries, the Ruby library has two additional variables:

  • GOOGLE_ADS_RUBY_LOG_LEVEL: As log_level above.
  • GOOGLE_ADS_RUBY_HTTP_PROXY: Specify an HTTP proxy.