factories provides a high-level interface for creating operations and resources with the client library.

Factories methods are automatically generated for all resources, enums, operations, and service types provided by the Google Ads API.


The library provides client.operation.create_resource.<resource_type>, client.operation.update_resource.<resource_type>, and client.operation.remove_resource.<resource_type> convenience methods to easily create operations to work with the Google Ads API.

Here is an example for creating a resource:

campaign_budget_operation = client.operation.create_resource.campaign_budget do |cb|
  cb.name = "Interplanetary Budget #{(Time.new.to_f * 1000).to_i}"

  cb.delivery_method = :STANDARD
  cb.amount_micros = 500000

return_budget = client.service.campaign_budget.mutate_campaign_budgets(

Note that the object yielded to the block cb is a new instance of CampaignBudget that you can then mutate, and the appropriate create operation for the CampaignBudgetService is returned.

Similarly, we provide convenience methods for updating:

# if you only have a resource name
update_operation = client.operation.update_resource.campaign(campaign_resource_name) do |camp|
  camp.status = :PAUSED

campaign_service.mutate_campaigns(customer_id, [update_operation])

# if you have a full resource proto
update_operation = client.operation.update_resource.campaign(campaign) do
  campaign.name = "A different interplanetary Cruise #{(Time.new.to_f * 1000).to_i}"

campaign_service.mutate_campaigns(customer_id, [update_operation])

These calls return a well-formed update operation, with a prepopulated field mask to update the resource in the Google Ads API.

Here is an example of removing a resource using a resource path:

remove_operation = client.operation.remove_resource.campaign(campaign_resource_name)
campaign_service.mutate_campaigns(customer_id, [remove_operation])

If you'd prefer to work with the operation yourself, you can get a raw operation and then manually populate the fields.

operation = client.operation.campaign


The library provides client.resource.<resource_type> as a convenient way to initialize resource objects:

campaign.network_settings = client.resource.network_settings do |ns|
  ns.target_google_search = true
  ns.target_search_network = true
  ns.target_content_network = false
  ns.target_partner_search_network = false

A new instance of the resource type requested is yielded to the passed block for setting fields.


The library provides client.service.<service_name> as a convenient way to get service objects:

campaign_service = client.service.campaign


We recommend using the symbol syntax for statically setting enum fields (e.g., campaign.status = :PAUSED). However, if you want to enumerate all the valid values for an enum, we also provide methods for that:

client.enum.ad_type.each { |x| p x }

Explicitly setting Google Ads API versions

You can also explicitly set a version: