Google Ads API is returning to beta status. Please read our blog post for more details.

Bidding Strategy Assignment

Standard bidding strategies

To use a standard bidding strategy with your campaign, set the campaign as follows:

This example demonstrates how to set a standard MAXIMIZE_CONVERSION_VALUE bidding strategy when creating a new campaign:

Java

// Creates the campaign.
Campaign campaign =
    Campaign.newBuilder()
        .setName(StringValue.of("Interplanetary Cruise #" + System.currentTimeMillis()))
        // Configures settings related to shopping campaigns including advertising channel type,
        // advertising sub-type and shopping setting.
        .setAdvertisingChannelType(AdvertisingChannelType.SHOPPING)
        .setAdvertisingChannelSubType(AdvertisingChannelSubType.SHOPPING_SMART_ADS)
        .setShoppingSetting(shoppingSetting)
        // Recommendation: Sets the campaign to PAUSED when creating it to prevent
        // the ads from immediately serving. Set to ENABLED once you've added
        // targeting and the ads are ready to serve.
        .setStatus(CampaignStatus.PAUSED)
        // Bidding strategy must be set directly on the campaign.
        // Setting a portfolio bidding strategy by resourceName is not supported.
        // Maximize conversion value is the only strategy supported for Smart Shopping
        // campaigns.
        // An optional ROAS (Return on Advertising Spend) can be set for
        // MaximizeConversionValue.
        // The ROAS value must be specified as a ratio in the API. It is calculated by dividing
        // "total value" by "total spend".
        // For more information on maximize conversion value, see the support article:
        // http://support.google.com/google-ads/answer/7684216)
        .setMaximizeConversionValue(
            MaximizeConversionValue.newBuilder().setTargetRoas(DoubleValue.of(3.5)).build())
        // Sets the budget.
        .setCampaignBudget(StringValue.of(budgetResourceName))
        .build();

C#

// Create the standard shopping campaign.
Campaign campaign = new Campaign()
{
    Name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString(),

    // Configures settings related to shopping campaigns including advertising channel
    // type, sub-type and shopping setting.
    AdvertisingChannelType = AdvertisingChannelType.Shopping,
    AdvertisingChannelSubType = AdvertisingChannelSubType.ShoppingSmartAds,

    ShoppingSetting = shoppingSetting,

    // Recommendation: Set the campaign to PAUSED when creating it to prevent
    // the ads from immediately serving. Set to ENABLED once you've added
    // targeting and the ads are ready to serve
    Status = CampaignStatus.Paused,

    // Bidding strategy must be set directly on the campaign.
    // Setting a portfolio bidding strategy by resourceName is not supported.
    // Maximize conversion value is the only strategy supported for Smart Shopping
    // campaigns.
    // An optional ROAS (Return on Advertising Spend) can be set for
    // MaximizeConversionValue.
    // The ROAS value must be specified as a ratio in the API. It is calculated by
    // dividingW "total value" by "total spend".
    // For more information on maximize conversion value, see the support article:
    // http://support.google.com/google-ads/answer/7684216)
    MaximizeConversionValue = new MaximizeConversionValue()
    {
        TargetRoas = 3.5
    },

    // Sets the budget.
    CampaignBudget = budgetResourceName
};

PHP

// Creates the campaign.
$campaign = new Campaign([
    'name' => new StringValue(['value' => 'Interplanetary Cruise Campaign #' . uniqid()]),
    // Configures settings related to shopping campaigns including
    // advertising channel type, advertising sub-type and shopping setting.
    'advertising_channel_type' => AdvertisingChannelType::SHOPPING,
    'advertising_channel_sub_type' => AdvertisingChannelSubType::SHOPPING_SMART_ADS,
    'shopping_setting' => $shoppingSettings,
    // Recommendation: Set the campaign to PAUSED when creating it to prevent
    // the ads from immediately serving. Set to ENABLED once you've added
    // targeting and the ads are ready to serve.
    'status' => CampaignStatus::PAUSED,
    // Bidding strategy must be set directly on the campaign.
    // Setting a portfolio bidding strategy by resource name is not supported.
    // Maximize conversion value is the only strategy supported for Smart Shopping
    // campaigns.
    // An optional ROAS (Return on Advertising Spend) can be set for
    // MaximizeConversionValue.
    // The ROAS value must be specified as a ratio in the API. It is calculated by dividing
    // "total value" by "total spend".
    // For more information on maximize conversion value, see the support article:
    // http://support.google.com/google-ads/answer/7684216.
    'maximize_conversion_value' => new MaximizeConversionValue([
        'target_roas' => new DoubleValue(['value' => 3.5])
    ]),
    // Sets the budget.
    'campaign_budget' => new StringValue(['value' => $budgetResourceName])
]);

Perl

my $campaign = Google::Ads::GoogleAds::V3::Resources::Campaign->new({
    name => "Interplanetary Cruise Campaign #" . uniqid(),
    # Configure settings related to shopping campaigns including advertising
    # channel type, advertising channel sub-type and shopping setting.
    advertisingChannelType    => SHOPPING,
    advertisingChannelSubType => SHOPPING_SMART_ADS,
    shoppingSetting =>
      Google::Ads::GoogleAds::V3::Resources::ShoppingSetting->new({
        merchantId => $merchant_center_id,
        # Set the sales country of products to include in the campaign.
        # Only products from Merchant Center targeting this country will
        # appear in the campaign.
        salesCountry => "US"
      }
      ),
    # Recommendation: Set the campaign to PAUSED when creating it to prevent
    # the ads from immediately serving. Set to ENABLED once you've added
    # targeting and the ads are ready to serve.
    status => Google::Ads::GoogleAds::V3::Enums::CampaignStatusEnum::PAUSED,
    # Bidding strategy must be set directly on the campaign.
    # Setting a portfolio bidding strategy by resource name is not supported.
    # Maximize conversion value is the only strategy supported for smart shopping
    # campaigns. An optional ROAS (Return on Advertising Spend) can be set for
    # MaximizeConversionValue. The ROAS value must be specified as a ratio in the
    # API. It is calculated by dividing "total value" by "total spend".
    # For more information on maximize conversion value, see the support article:
    # http://support.google.com/google-ads/answer/7684216.
    maximizeConversionValue =>
      Google::Ads::GoogleAds::V3::Common::MaximizeConversionValue->new(
      {targetRoas => 3.5}
      ),
    # Set the budget.
    campaignBudget => $budget_resource_name
  });

Portfolio bidding strategies

To use a portfolio bidding strategy with your campaign, you have two options:

  1. Use an existing BiddingStrategy.
  2. Use MutateBiddingStrategies to create a new one with the fields name and scheme set. As an example, for an ENHANCED_CPC bidding strategy, set the field enhanced_cpc with a new object typed as EnhancedCpc.

Once you've chosen a BiddingStrategy, configure your campaign to use it by setting the campaign's bidding_strategy field to its resource_name.

The following example demonstrates how to create a new portfolio ENHANCED_CPC bidding strategy for a new campaign.

Java

private String createBiddingStrategy(GoogleAdsClient googleAdsClient, long customerId) {
  try (BiddingStrategyServiceClient biddingStrategyServiceClient =
      googleAdsClient.getLatestVersion().createBiddingStrategyServiceClient()) {
    // Creates a portfolio bidding strategy.
    TargetSpend targetSpend =
        TargetSpend.newBuilder()
            .setCpcBidCeilingMicros(Int64Value.of(2_000_000L))
            .setTargetSpendMicros(Int64Value.of(20_000_000L))
            .build();
    BiddingStrategy portfolioBiddingStrategy =
        BiddingStrategy.newBuilder()
            .setName(StringValue.of("Maximize Clicks #" + System.currentTimeMillis()))
            .setTargetSpend(targetSpend)
            .build();
    // Constructs an operation that will create a portfolio bidding strategy.
    BiddingStrategyOperation operation =
        BiddingStrategyOperation.newBuilder().setCreate(portfolioBiddingStrategy).build();
    // Sends the operation in a mutate request.
    MutateBiddingStrategiesResponse response =
        biddingStrategyServiceClient.mutateBiddingStrategies(
            Long.toString(customerId), Lists.newArrayList(operation));

    MutateBiddingStrategyResult mutateBiddingStrategyResult = response.getResults(0);
    // Prints the resource name of the created object.
    System.out.printf(
        "Created portfolio bidding strategy with resource name: '%s'.%n",
        mutateBiddingStrategyResult.getResourceName());

    return mutateBiddingStrategyResult.getResourceName();
  }
}

C#

private string CreatePortfolioBiddingStrategy(GoogleAdsClient client,
    long customerId, string name, long bidCeiling, long spendTarget)
{
    // Get the BiddingStrategyService.
    BiddingStrategyServiceClient biddingStrategyService = client.GetService(
        Services.V3.BiddingStrategyService);

    // Create a portfolio bidding strategy.
    BiddingStrategy biddingStrategy = new BiddingStrategy()
    {
        Name = name,

        TargetSpend = new TargetSpend()
        {
            // Optionally set additional bidding scheme parameters.
            CpcBidCeilingMicros = bidCeiling,
            TargetSpendMicros = spendTarget
        }
    };

    // Create operation.
    BiddingStrategyOperation biddingOperation = new BiddingStrategyOperation()
    {
        Create = biddingStrategy
    };

    // Create the portfolio bidding strategy.
    MutateBiddingStrategiesResponse biddingResponse =
        biddingStrategyService.MutateBiddingStrategies(
            customerId.ToString(), new BiddingStrategyOperation[] { biddingOperation });

    return biddingResponse.Results[0].ResourceName;
}

PHP

private static function createBiddingStrategy(GoogleAdsClient $googleAdsClient, int $customerId)
{
    // Creates a portfolio bidding strategy.
    $portfolioBiddingStrategy = new BiddingStrategy([
        'name' => new StringValue(['value' => 'Maximize Clicks #' . uniqid()]),
        'target_spend' => new TargetSpend([
            'cpc_bid_ceiling_micros' => new Int64Value(['value' => 2000000]),
            'target_spend_micros' => new Int64Value(['value' => 20000000])
        ])
    ]);

    // Constructs an operation that will create a portfolio bidding strategy.
    $biddingStrategyOperation = new BiddingStrategyOperation();
    $biddingStrategyOperation->setCreate($portfolioBiddingStrategy);

    // Issues a mutate request to create the bidding strategy.
    $biddingStrategyServiceClient = $googleAdsClient->getBiddingStrategyServiceClient();
    $response = $biddingStrategyServiceClient->mutateBiddingStrategies(
        $customerId,
        [$biddingStrategyOperation]
    );
    /** @var BiddingStrategy $addedBiddingStrategy */
    $addedBiddingStrategy = $response->getResults()[0];

    // Prints out the resource name of the created bidding strategy.
    printf(
        "Created portfolio bidding strategy with resource name: '%s'.%s",
        $addedBiddingStrategy->getResourceName(),
        PHP_EOL
    );

    return $addedBiddingStrategy->getResourceName();
}

Python

# Create a portfolio bidding strategy.
bidding_strategy_operation = client.get_type('BiddingStrategyOperation',
                                             version='v3')
bidding_strategy = bidding_strategy_operation.create
bidding_strategy.name.value = 'Enhanced CPC %s' % uuid.uuid4()
target_spend = bidding_strategy.target_spend
target_spend.cpc_bid_ceiling_micros.value = 2000000
target_spend.target_spend_micros.value = 20000000

# Add portfolio bidding strategy.
try:
    bidding_strategy_response = (
        bidding_strategy_service.mutate_bidding_strategies(
            customer_id, [bidding_strategy_operation]))
except google.ads.google_ads.errors.GoogleAdsException as ex:
    print('Request with ID "%s" failed with status "%s" and includes the '
          'following errors:' % (ex.request_id, ex.error.code().name))
    for error in ex.failure.errors:
        print('\tError with message "%s".' % error.message)
        if error.location:
            for field_path_element in error.location.field_path_elements:
                print('\t\tOn field: %s' % field_path_element.field_name)
    sys.exit(1)

bidding_strategy_id = bidding_strategy_response.results[0].resource_name

print('Portfolio bidding strategy "%s" was created.' % bidding_strategy_id)

Ruby

# Create a portfolio bidding strategy.
bidding_strategy = client.resource.bidding_strategy do |bs|
  bs.name = "Enhanced CPC ##{(Time.new.to_f * 1000).to_i}"
  bs.enhanced_cpc = client.resource.enhanced_cpc
end

operation = client.operation.create_resource.bidding_strategy(bidding_strategy)

response = client.service.bidding_strategy.mutate_bidding_strategies(
    customer_id, [operation])
bidding_id = response.results.first.resource_name

puts "Portfolio bidding strategy #{bidding_id} was created"

Perl

sub create_bidding_strategy {
  my ($api_client, $customer_id) = @_;

  # Create a portfolio bidding strategy.
  my $portfolio_bidding_strategy =
    Google::Ads::GoogleAds::V3::Resources::BiddingStrategy->new({
      name        => "Maximize Clicks #" . uniqid(),
      targetSpend => Google::Ads::GoogleAds::V3::Common::TargetSpend->new({
          cpcBidCeilingMicros => 2000000,
          targetSpendMicros   => 20000000
        }
      ),
    });

  # Create a bidding strategy operation.
  my $bidding_strategy_operation =
    Google::Ads::GoogleAds::V3::Services::BiddingStrategyService::BiddingStrategyOperation
    ->new({
      create => $portfolio_bidding_strategy
    });

  # Add the bidding strategy.
  my $bidding_strategy_response =
    $api_client->BiddingStrategyService()->mutate({
      customerId => $customer_id,
      operations => [$bidding_strategy_operation]});

  my $bidding_strategy_resource_name =
    $bidding_strategy_response->{results}[0]{resourceName};

  printf "Created portfolio bidding strategy with resource name: '%s'.\n",
    $bidding_strategy_resource_name;

  return $bidding_strategy_resource_name;
}

Java

Campaign campaign =
    Campaign.newBuilder()
        .setName(StringValue.of("Interplanetary Cruise #" + System.currentTimeMillis()))
        .setStatus(CampaignStatus.PAUSED)
        .setCampaignBudget(StringValue.of(campaignBudgetResourceName))
        .setBiddingStrategy(StringValue.of(biddingStrategyResourceName))
        .setAdvertisingChannelType(AdvertisingChannelType.SEARCH)
        .setNetworkSettings(networkSettings)
        .build();

C#

// Create the campaign.
Campaign campaign = new Campaign()
{
    Name = name,
    AdvertisingChannelType = AdvertisingChannelType.Search,

    // Recommendation: Set the campaign to PAUSED when creating it to prevent
    // the ads from immediately serving. Set to ENABLED once you've added
    // targeting and the ads are ready to serve.
    Status = CampaignStatus.Paused,

    // Set the campaign budget.
    CampaignBudget = campaignBudgetResourceName,

    // Set bidding strategy (required).
    BiddingStrategy = biddingStrategyResourceName,

    // Set the campaign network options.
    NetworkSettings = new NetworkSettings()
    {
        TargetGoogleSearch = true,
        TargetSearchNetwork = true,
        TargetContentNetwork = true,
        TargetPartnerSearchNetwork = false
    }
};

PHP

// Creates a Search campaign.
$campaign = new Campaign([
    'name' => new StringValue(['value' => 'Interplanetary Cruise #' . uniqid()]),
    'advertising_channel_type' => AdvertisingChannelType::SEARCH,
    // Recommendation: Set the campaign to PAUSED when creating it to prevent
    // the ads from immediately serving. Set to ENABLED once you've added
    // targeting and the ads are ready to serve.
    'status' => CampaignStatus::PAUSED,
    // Configures the campaign network options.
    'network_settings' => new NetworkSettings([
        'target_google_search' => new BoolValue(['value' => true]),
        'target_search_network' => new BoolValue(['value' => true]),
        'target_content_network' => new BoolValue(['value' => true]),
    ]),
    // Sets the bidding strategy and budget.
    'bidding_strategy' => new StringValue(['value' => $biddingStrategyResourceName]),
    'campaign_budget' => new StringValue(['value' => $campaignBudgetResourceName])
]);

Python

# Create campaign.
campaign_operation = client.get_type('CampaignOperation', version='v3')
campaign = campaign_operation.create
campaign.name.value = 'Interplanetary Cruise %s' % uuid.uuid4()
campaign.advertising_channel_type = client.get_type(
    'AdvertisingChannelTypeEnum').SEARCH

# Recommendation: Set the campaign to PAUSED when creating it to prevent the
# ads from immediately serving. Set to ENABLED once you've added targeting
# and the ads are ready to serve.
campaign.status = client.get_type('CampaignStatusEnum', version='v3').PAUSED

# Set the bidding strategy and budget.
campaign.bidding_strategy.value = bidding_strategy_id
campaign.manual_cpc.enhanced_cpc_enabled.value = True
campaign.campaign_budget.value = campaign_budget_id

# Set the campaign network options.
campaign.network_settings.target_google_search.value = True
campaign.network_settings.target_search_network.value = True
campaign.network_settings.target_content_network.value = False
campaign.network_settings.target_partner_search_network.value = False

Ruby

# Create campaigns.
campaigns = 2.times.map do |i|
  client.resource.campaign do |c|
    c.name = "Interplanetary Cruise ##{(Time.new.to_f * 1000).to_i + i}"
    c.status = :PAUSED
    c.bidding_strategy = bidding_id
    c.campaign_budget = budget_id
    c.advertising_channel_type = :SEARCH
    c.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
    end
  end
end

Perl

# Create a search campaign.
my $campaign = Google::Ads::GoogleAds::V3::Resources::Campaign->new({
    name                   => "Interplanetary Cruise #" . uniqid(),
    advertisingChannelType => SEARCH,
    # Recommendation: Set the campaign to PAUSED when creating it to stop
    # the ads from immediately serving. Set to ENABLED once you've added
    # targeting and the ads are ready to serve.
    status => PAUSED,
    # Configures the campaign network options.
    networkSettings =>
      Google::Ads::GoogleAds::V3::Resources::NetworkSettings->new({
        targetGoogleSearch   => "true",
        targetSearchNetwork  => "true",
        targetContentNetwork => "true"
      }
      ),
    # Set the bidding strategy and budget.
    biddingStrategy => $bidding_strategy_resource_name,
    campaignBudget  => $campaign_budget_resource_name
  });

Bidding strategy transitions

To update a campaign's bidding strategy, in a CampaignOperation.update, set the fields of the Campaign as previously described.