Google Ads

Bidding  |  AdWords API  |  Google Developers

Google Ads gives you several ways to bid for your
ads
, depending on what matters
most to you and your business.

In the AdWords API, all bidding parameters are managed via one or both of the following:

With either object, you can use its biddingStrategyType field, its biddingScheme field, or
both, to specify a bidding type. The biddingScheme allows you to set additional
parameters specific to a bidding type. When both fields are specified, their types must
match.

Strategy types

In the table below, the Valid Contexts column indicates whether a given
BiddingStrategyType and associated BiddingScheme type can be used in one
or both of the contexts mentioned above:

  • A standard strategy with a BiddingStrategyConfiguration object.
  • A portfolio strategy with a SharedBiddingStrategy object.

Errors result if you try to use a BiddingStrategyType or BiddingScheme in
the wrong context:

  • Using a portfolio-only type or scheme in the context of a standard strategy generates a BiddingErrors
    error with reason INVALID_ANONYMOUS_BIDDING_STRATEGY_TYPE.
  • Using a standard-only type or scheme in the context of a portfolio strategy generates a BiddingErrors
    error with reasonBIDDING_STRATEGY_NOT_SUPPORTED.

Specifying the strategy for a campaign

Standard bidding strategies

To use a standard bidding strategy with your campaign, configure the campaign’s
biddingStrategyConfiguration
as follows:

  • If you do not need to configure additional attributes of the strategy,
    simply set its
    biddingStrategyType.
  • If you need to configure additional attributes of the strategy, such as the
    enhancedCpcEnabled
    attribute for a MANUAL_CPC strategy, set the configuration’s
    biddingStrategyScheme.
  • Do not set the bidding strategy configuration’s biddingStrategyId or
    biddingStrategyName.

Portfolio bidding strategies

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

  1. Use an existing SharedBiddingStrategy.
  2. Use the BiddingStrategyService
    to create a new
    SharedBiddingStrategy
    and set its parameters.

Once you’ve chosen a SharedBiddingStrategy, configure your campaign to use
the strategy by setting the campaign’s
biddingStrategyConfiguration
to a configuration with the
biddingStrategyId
set to the shared bidding strategy’s
id.

Bidding strategy transitions

You can update a campaign’s bidding strategy using
CampaignService mutate() and a SET
operation. The operand should
be a Campaign with the id set to the campaign’s ID, and the
biddingStrategyConfiguration configured as described above in
specifying the strategy for a campaign.

Overriding strategy settings

Overriding target ROAS at the ad group level

The targetRoas of a standard TARGET_ROAS strategy’s
TargetRoasBiddingScheme
can be overridden at the ad group level by setting the
targetRoasOverride
of the ad group’s bidding strategy configuration. The other fields of the
strategy’s bidding scheme cannot be overridden.

To remove an override, set the targetRoasOverride of the ad group’s
BiddingStrategyConfiguration to 0.

Attempting to override the targetRoas of a portfolio TargetRoasBiddingScheme
will result in an error.

Overriding target CPA at the ad group level

The targetCpa of a TARGET_CPA strategy’s
TargetCpaBiddingScheme
can be overridden at the ad group level by adding a
CpaBid to the ad group’s bidding strategy
configuration. The other fields of the strategy’s bidding scheme cannot be
overridden.

Overriding standard bidding strategies set at higher levels

You can’t set a different bidding strategy at a lower level from that at a
higher level. For example, setting a MANUAL_CPM strategy at the ad group level
when a MANUAL_CPC strategy exists at the campaign level will throw an error.

You can set a MANUAL_CPC strategy at a lower level when another
MANUAL_CPC exists at a higher level; however, you would be better off just
setting the bid directly.

Setting bids

Bids can be set at the ad group and ad group criterion levels. A criterion bid will override an
ad group bid. Attempts to set bids at the campaign level will fail.

Multiple bids of different types can be set in a single BiddingStrategyConfiguration
simultaneously (for example, CpcBid and CpmBid) but only the bid that’s relevant
for the currently selected biddingStrategyType will be used to bid for your
ads.

The following code example uses a mutate call to add a CPC bid at the ad group
level.

Java

// Get the AdGroupService.
AdGroupServiceInterface adGroupService =
    adWordsServices.get(session, AdGroupServiceInterface.class);

// Create an ad group with the specified ID.
AdGroup adGroup = new AdGroup();
adGroup.setId(adGroupId);
// Update the CPC bid if specified.
if (bidMicroAmount != null) {
  BiddingStrategyConfiguration biddingStrategyConfiguration =
      new BiddingStrategyConfiguration();
  Money cpcBidMoney = new Money();
  cpcBidMoney.setMicroAmount(bidMicroAmount);
  CpcBid cpcBid = new CpcBid();
  cpcBid.setBid(cpcBidMoney);
  biddingStrategyConfiguration.setBids(new Bids[] {cpcBid});
  adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
}
// Pause the ad group.
adGroup.setStatus(AdGroupStatus.PAUSED);

// Create operations.
AdGroupOperation operation = new AdGroupOperation();
operation.setOperand(adGroup);
operation.setOperator(Operator.SET);

AdGroupOperation[] operations = new AdGroupOperation[] {operation};

// Update ad group.
AdGroupReturnValue result = adGroupService.mutate(operations);

C#

// Create an ad group with the specified ID.
AdGroup adGroup = new AdGroup
{
    id = adGroupId,

    // Pause the ad group.
    status = AdGroupStatus.PAUSED
};

// Update the CPC bid if specified.
if (bidMicroAmount != null)
{
    BiddingStrategyConfiguration biddingStrategyConfiguration =
        new BiddingStrategyConfiguration();
    Money cpcBidMoney = new Money
    {
        microAmount = bidMicroAmount.Value
    };
    CpcBid cpcBid = new CpcBid
    {
        bid = cpcBidMoney
    };
    biddingStrategyConfiguration.bids = new Bids[]
    {
        cpcBid
    };
    adGroup.biddingStrategyConfiguration = biddingStrategyConfiguration;
}

// Create the operation.
AdGroupOperation operation = new AdGroupOperation
{
    @operator = Operator.SET,
    operand = adGroup
};

try
{
    // Update the ad group.
    AdGroupReturnValue retVal = adGroupService.mutate(new AdGroupOperation[]
    {
        operation
    });

Python

# Initialize appropriate service.
ad_group_service = client.GetService('AdGroupService', version='v201809')

# Construct operations and update an ad group.
operations = [{
    'operator': 'SET',
    'operand': {
        'id': ad_group_id,
        'status': 'PAUSED'
    }
}]

if bid_micro_amount:
  operations[0]['operand']['biddingStrategyConfiguration'] = {
      'bids': [{
          'xsi_type': 'CpcBid',
          'bid': {
              'microAmount': bid_micro_amount,
          }
      }]
  }

ad_groups = ad_group_service.mutate(operations)

PHP

$adGroupService = $adWordsServices->get($session, AdGroupService::class);

$operations = [];
// Create ad group with the specified ID.
$adGroup = new AdGroup();
$adGroup->setId($adGroupId);

// Update the CPC bid if specified.
if (!is_null($cpcBidMicroAmount)) {
    $bid = new CpcBid();
    $money = new Money();
    $money->setMicroAmount($cpcBidMicroAmount);
    $bid->setBid($money);
    $biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    $biddingStrategyConfiguration->setBids([$bid]);
    $adGroup->setBiddingStrategyConfiguration($biddingStrategyConfiguration);
}

// Create ad group operation and add it to the list.
$operation = new AdGroupOperation();
$operation->setOperand($adGroup);
$operation->setOperator(Operator::SET);
$operations[] = $operation;

// Update the ad group on the server.
$result = $adGroupService->mutate($operations);

Perl

# Create an ad group with the specified ID.
# Pause the ad group.
my $ad_group = Google::Ads::AdWords::v201809::AdGroup->new({
  id     => $ad_group_id,
  status => "PAUSED"
});

# Update the CPC bid if specified.
if ($cpc_bid_micro_amount) {
  my $bidding_strategy_configuration =
    Google::Ads::AdWords::v201809::BiddingStrategyConfiguration->new({
      bids => [
        Google::Ads::AdWords::v201809::CpcBid->new({
            bid => Google::Ads::AdWords::v201809::Money->new({
                microAmount => $cpc_bid_micro_amount
            }),
          }),
      ]
    });
  $ad_group->set_biddingStrategyConfiguration(
    $bidding_strategy_configuration);
}

# Create operation.
my $operation = Google::Ads::AdWords::v201809::AdGroupOperation->new({
  operand  => $ad_group,
  operator => "SET"
});

# Update ad group.
my $result = $client->AdGroupService()->mutate({operations => [$operation]});

Ruby

ad_group_srv = adwords.service(:AdGroupService, API_VERSION)

# Create an ad group with the specified ID.
ad_group = {
  :status => 'PAUSED',
  :id => ad_group_id
}

# Update the CPC bid if specified.
unless cpc_bid_micro_amount.nil?
  ad_group[:bidding_strategy_configuration] = {
    :bids => [{
      :xsi_type => 'CpcBid',
      :bid => {
        :micro_amount => cpc_bid_micro_amount
      }
    }]
  }
end

operation = {
  :operator => 'SET',
  :operand => ad_group
}

# Update ad group.
response = ad_group_srv.mutate([operation])

VB.NET

' Create an ad group with the specified ID.
Dim adGroup As New AdGroup
adGroup.id = adGroupId

' Pause the ad group.
adGroup.status = AdGroupStatus.PAUSED

' Update the CPC bid if specified.
If bidMicroAmount.HasValue() Then
    Dim biddingStrategyConfiguration As New BiddingStrategyConfiguration()
    Dim cpcBidMoney = New Money()
    cpcBidMoney.microAmount = bidMicroAmount.Value
    Dim cpcBid As New CpcBid()
    cpcBid.bid = cpcBidMoney
    biddingStrategyConfiguration.bids = New Bids() {cpcBid}
    adGroup.biddingStrategyConfiguration = biddingStrategyConfiguration
End If

' Create the operation.
Dim operation As New AdGroupOperation
operation.operator = [Operator].SET
operation.operand = adGroup

Try
    ' Update the ad group.
    Dim retVal As AdGroupReturnValue = adGroupService.mutate(
        New AdGroupOperation() {operation})

Removing bids

To remove a bid from a BiddingStrategyConfiguration, update
its bid field to a Money
object with microAmount set to 0.

Display Network criteria dimensions

For ads running on the Display Network, there are a number of different dimensions for which an
ad group bid can be set. If multiple bids are set in different dimensions, the
contentBidCriterionTypeGroup
field can be used to specify the dimension that should be used for absolute bids. Ads on the search
network will always use keyword bids.

You can also set a bid adjustment
which will be used when the criterion is not in an absolute bidding dimension. It can be accessed
via the bidModifier field of the
BiddableAdGroupCriterion.

Bid modifiers

Campaign and ad group-level bid adjustments give you more control over your bids in
Google Ads campaigns, providing the option to increase or decrease bids for certain
criteria.

Within the AdWords API, campaign-level adjustments are accessible via
CampaignCriterionService and
CampaignBidModifierService,
and ad group-level adjustments are accessible via
AdGroupBidModifierService.

Retrieving bid adjustments

To retrieve existing bid adjustments, use the get()
or query() method of CampaignCriterionService,
AdGroupBidModifierService, or
CampaignBidModifierService.
Similar to other services, the get()
method accepts a generic selector, allowing you to select response fields and
filter the results set.

The code below retrieves all bid modifiers for an ad group:

Java

public static void runExample(AdWordsServicesInterface adWordsServices,
    AdWordsSession session) throws RemoteException {
  // Get the AdGroupBidModifierService.
  AdGroupBidModifierServiceInterface adGroupBidModifierService =
      adWordsServices.get(session, AdGroupBidModifierServiceInterface.class);

  // Create selector.
  Selector selector = new SelectorBuilder()
      .fields(
          AdGroupBidModifierField.CampaignId,
          AdGroupBidModifierField.AdGroupId,
          AdGroupBidModifierField.BidModifier,
          AdGroupBidModifierField.Id)
      .offset(0)
      .limit(PAGE_SIZE)
      .build();

  AdGroupBidModifierPage page = adGroupBidModifierService.get(selector);
  if (page.getEntries() != null) {
    for (AdGroupBidModifier bidModifierResult : page.getEntries()) {
      String bidModifierValue =
          bidModifierResult.getBidModifier() != null
              ? bidModifierResult.getBidModifier().toString()
              : "unset";
      System.out.printf("Campaign ID %d, AdGroup ID %d, Criterion ID %d, "
          + "has ad group level modifier: %s%n",
          bidModifierResult.getCampaignId(),
          bidModifierResult.getAdGroupId(),
          bidModifierResult.getCriterion().getId(),
          bidModifierValue);
    }
  } else {
    System.out.println("No ad group level bid modifiers were found.");
  }
}

C#

public void Run(AdWordsUser user, long campaignId)

Python

def main(client):
  # Initialize appropriate service.
  ad_group_bid_modifier_service = client.GetService(
      'AdGroupBidModifierService', version='v201809')

  # Get all ad group bid modifiers for the campaign.
  selector = {
      'fields': ['CampaignId', 'AdGroupId', 'BidModifier', 'Id'],
      'paging': {
          'startIndex': '0',
          'numberResults': str(PAGE_SIZE)
      }
  }

  # Set initial values.
  offset, page = 0, {}
  more_results = True

  while more_results:
    page = ad_group_bid_modifier_service.get(selector)
    if page['entries']:
      for modifier in page['entries']:
        value = (modifier['bidModifier'] if 'bidModifier' in modifier
                 else 'unset')
        print('Campaign ID %s, AdGroup ID %s, Criterion ID %s has ad group '
              'level modifier: %s' %
              (modifier['campaignId'], modifier['adGroupId'],
               modifier['criterion']['id'], value))

      # Increment values to request the next page.
      offset += PAGE_SIZE
      selector['paging']['startIndex'] = str(offset)
    else:
      print('No ad group bid modifiers returned.')
    more_results = int(page['totalNumEntries']) > offset

PHP

public static function runExample(
    AdWordsServices $adWordsServices,
    AdWordsSession $session

Perl

sub get_ad_group_bid_modifier {
  my $client = shift;

  # Create selector.
  my $paging = Google::Ads::AdWords::v201809::Paging->new({
      startIndex    => 0,
      numberResults => PAGE_SIZE
  });
  my $selector = Google::Ads::AdWords::v201809::Selector->new({
      fields => ["CampaignId", "AdGroupId", "BidModifier", "Id"],
      paging => $paging
  });

  # Paginate through results.
  Google::Ads::AdWords::Utilities::PageProcessor->new({
      client   => $client,
      service  => $client->AdGroupBidModifierService(),
      selector => $selector
    }
    )->process_entries(
    sub {
      my ($modifier) = @_;
      my $modifier_value = $modifier->get_bidModifier() || "unset";
      printf "Campaign ID %s, AdGroup ID %s, Criterion ID %s has ad group " .
        "level modifier: %sn", $modifier->get_campaignId(),
        $modifier->get_adGroupId(), $modifier->get_criterion()->get_id(),
        $modifier_value;
    });

  return 1;
}

Ruby

def get_ad_group_bid_modifiers(campaign_id)
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
  # when called without parameters.
  adwords = AdwordsApi::Api.new

  # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
  # the configuration file or provide your own logger:
  # adwords.logger = Logger.new('adwords_xml.log')

  bid_modifier_srv = adwords.service(:AdGroupBidModifierService, API_VERSION)

  # Get all ad group bid modifiers for the campaign.
  selector = {
    :fields => ['CampaignId', 'AdGroupId', 'Id', 'BidModifier'],
    :predicates => [
      {:field => 'CampaignId', :operator => 'EQUALS', :values => [campaign_id]}
    ],
    :paging => {
      :start_index => 0,
      :number_results => PAGE_SIZE
    }
  }

  # Set initial values.
  offset, page = 0, {}

  begin
    page = bid_modifier_srv.get(selector)
    if page[:entries]
      page[:entries].each do |modifier|
        value = modifier[:bid_modifier] || 'unset'
        puts ('Campaign ID %d, AdGroup ID %d, Criterion ID %d has ad group ' +
           'level modifier: %s') %
           [modifier[:campaign_id], modifier[:ad_group_id],
            modifier[:criterion][:id], value]
      end
      # Increment values to request the next page.
      offset += PAGE_SIZE
      selector[:paging][:start_index] = offset
    else
      puts 'No ad group level bid overrides returned.'
    end
  end while page[:total_num_entries] > offset
end

VB.NET

Public Sub Run(ByVal user As AdWordsUser, ByVal campaignId As Long)
    ' Get the AdGroupBidModifierService.
    Using adGroupBidModifierService As AdGroupBidModifierService = CType(
        user.GetService(
            AdWordsService.v201809.AdGroupBidModifierService),
        AdGroupBidModifierService)

        ' Get all ad group bid modifiers for the campaign.
        Dim selector As New Selector()
        selector.fields = New String() { _
                                           AdGroupBidModifier.Fields.CampaignId,
                                           AdGroupBidModifier.Fields.AdGroupId,
                                           AdGroupBidModifier.Fields.BidModifier,
                                           AdGroupBidModifier.Fields.BidModifierSource,
                                           Criterion.Fields.CriteriaType,
                                           Criterion.Fields.Id
                                       }

        Dim predicate As New Predicate()
        predicate.field = "CampaignId"
        predicate.[operator] = PredicateOperator.EQUALS
        predicate.values = New String() {campaignId.ToString()}
        selector.predicates = New Predicate() { _
                                                  Predicate.Equals(
                                                      AdGroupBidModifier.Fields.CampaignId,
                                                      campaignId)
                                              }
        selector.paging = Paging.Default

        Dim page As New AdGroupBidModifierPage()

        Try
            Do
                ' Get the ad group bids.
                page = adGroupBidModifierService.get(selector)

                ' Display the results.
                If (Not page Is Nothing) AndAlso (Not page.entries Is Nothing) Then
                    Dim i As Integer = selector.paging.startIndex
                    For Each adGroupBidModifier As AdGroupBidModifier In page.entries
                        Dim bidModifier As String = ""
                        If adGroupBidModifier.bidModifierSpecified Then
                            bidModifier = adGroupBidModifier.bidModifier.ToString()
                        Else
                            bidModifier = "UNSET"
                        End If
                        Console.WriteLine(
                            "{0}) Campaign ID {1}, AdGroup ID {2}, Criterion ID {3} has " &
                            "ad group level modifier: {4}, source = {5}.",
                            i + 1, adGroupBidModifier.campaignId,
                            adGroupBidModifier.adGroupId, adGroupBidModifier.criterion.id,
                            bidModifier, adGroupBidModifier.bidModifierSource)
                        i = i + 1
                    Next
                End If
                selector.paging.IncreaseOffset()
            Loop While selector.paging.startIndex < page.totalNumEntries
            Console.WriteLine("Number of adgroup bid modifiers found: {0}",
                              page.totalNumEntries)
        Catch e As Exception
            Throw _
                New System.ApplicationException("Failed to retrieve adgroup bid modifiers.",
                                                e)
        End Try
    End Using

Adding, updating, and removing bid adjustments

Use the mutate() method of CampaignCriterionService,
AdGroupBidModifierService,
or CampaignBidModifierService
to add or amend a bid adjustment:

  • To add a new bid modifier, use the ADD operator.
  • To update an existing bid override to a new value, use the SET operator.
  • To remove a bid modifier override, use the REMOVE operator.
  • Performing an ADD operation on a an existing CampaignBidModifier,
    AdGroupBidModifier, or AdGroupCriterion will cause the operation to be treated
    like a SET.

This example demonstrates how to add a new ad group-level mobile bid
adjustment:

Java

public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session,
    Long adGroupId) throws RemoteException {
  // Get the AdGroupBidModifierService.
  AdGroupBidModifierServiceInterface adGroupBidModifierService =
      adWordsServices.get(session, AdGroupBidModifierServiceInterface.class);

  // Create mobile platform. The ID can be found in the documentation.
  // https://developers.google.com/adwords/api/docs/appendix/platforms
  Platform mobile = new Platform();
  mobile.setId(30001L);

  AdGroupBidModifier adGroupBidModifier = new AdGroupBidModifier();
  adGroupBidModifier.setAdGroupId(adGroupId);
  adGroupBidModifier.setBidModifier(BID_MODIFIER);
  adGroupBidModifier.setCriterion(mobile);

  // Create ADD operation.
  AdGroupBidModifierOperation operation = new AdGroupBidModifierOperation();
  operation.setOperand(adGroupBidModifier);
  // Use 'ADD' to add a new modifier and 'SET' to update an existing one. A
  // modifier can be removed with the 'REMOVE' operator.
  operation.setOperator(Operator.ADD);

  // Update ad group bid modifier.
  AdGroupBidModifierReturnValue result =
      adGroupBidModifierService.mutate(new AdGroupBidModifierOperation[] {operation});
  for (AdGroupBidModifier bidModifierResult : result.getValue()) {
    System.out.printf(
        "Campaign ID %d, ad group ID %d was updated with ad group level modifier: %.4f%n",
        bidModifierResult.getCampaignId(), bidModifierResult.getAdGroupId(),
        bidModifierResult.getBidModifier());
  }
}

C#

public void Run(AdWordsUser user, long adGroupId, double bidModifier)

Python

def main(client, ad_group_id, bid_modifier):
  # Initialize appropriate service.
  ad_group_bid_modifier_service = client.GetService(
      'AdGroupBidModifierService', version='v201809')

  # Mobile criterion ID.
  criterion_id = '30001'

  # Prepare to add an ad group level override.
  operation = {
      # Use 'ADD' to add a new modifier and 'SET' to update an existing one. A
      # modifier can be removed with the 'REMOVE' operator.
      'operator': 'ADD',
      'operand': {
          'adGroupId': ad_group_id,
          'criterion': {
              'xsi_type': 'Platform',
              'id': criterion_id
          },
          'bidModifier': bid_modifier
      }
  }

  # Add ad group level mobile bid modifier.
  response = ad_group_bid_modifier_service.mutate([operation])
  if response and response['value']:
    modifier = response['value'][0]
    value = modifier['bidModifier'] if 'bidModifier' in modifier else 'unset'
    print('Campaign ID %s, AdGroup ID %s, Criterion ID %s was updated with '
          'ad group level modifier: %s' %
          (modifier['campaignId'], modifier['adGroupId'],
           modifier['criterion']['id'], value))
  else:
    print('No modifiers were added.')

PHP

public static function runExample(
    AdWordsServices $adWordsServices,
    AdWordsSession $session,
    $adGroupId,
    $bidModifier

Perl

sub add_ad_group_bid_modifier {
  my $client      = shift;
  my $ad_group_id = shift;

  # Create mobile platform. The ID can be found in the documentation.
  # https://developers.google.com/adwords/api/docs/appendix/platforms
  my $mobile = Google::Ads::AdWords::v201809::Platform->new({id => 30001});

  # Create the bid modifier.
  my $modifier = Google::Ads::AdWords::v201809::AdGroupBidModifier->new({
      adGroupId   => $ad_group_id,
      criterion   => $mobile,
      bidModifier => BID_MODIFIER
  });

  # Create ADD operation.
  my $operation =
    Google::Ads::AdWords::v201809::AdGroupBidModifierOperation->new({
      operator => "ADD",
      operand  => $modifier
    });

  # Update campaign criteria.
  my $result =
    $client->AdGroupBidModifierService()->mutate({operations => [$operation]});

  # Display campaign criteria.
  if ($result->get_value()) {
    foreach my $modifier (@{$result->get_value()}) {
      printf "Ad Group ID '%s', criterion ID '%s', " .
        "and type '%s' was modified with bid %.2f.n",
        $modifier->get_adGroupId(),
        $modifier->get_criterion()->get_id(),
        $modifier->get_criterion()->get_type(),
        $modifier->get_bidModifier();
    }
  } else {
    print "No ad group bid modifier was added.n";
  }

  return 1;
}

Ruby

def add_ad_group_bid_modifier(ad_group_id, bid_modifier)
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
  # when called without parameters.
  adwords = AdwordsApi::Api.new

  # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
  # the configuration file or provide your own logger:
  # adwords.logger = Logger.new('adwords_xml.log')

  bid_modifier_srv = adwords.service(:AdGroupBidModifierService, API_VERSION)

  # Mobile criterion ID.
  criterion_id = 30001

  # Prepare to add an ad group level override.
  operation = {
    # Use 'ADD' to add a new modifier and 'SET' to update an existing one. A
    # modifier can be removed with the 'REMOVE' operator.
    :operator => 'ADD',
    :operand => {
      :ad_group_id => ad_group_id,
      :criterion => {
        :xsi_type => 'Platform',
        :id => criterion_id
      },
      :bid_modifier => bid_modifier
    }
  }

  # Add ad group level mobile bid modifier.
  response = bid_modifier_srv.mutate([operation])
  if response and response[:value]
    modifier = response[:value].first
    value = modifier[:bid_modifier] || 'unset'
    puts ('Campaign ID %d, AdGroup ID %d, Criterion ID %d was updated with ' +
        'ad group level modifier: %s') %
           [modifier[:campaign_id], modifier[:ad_group_id],
            modifier[:criterion][:id], value]
  else
    puts 'No modifiers were added.'
  end
end

VB.NET

Public Sub Run(ByVal user As AdWordsUser, ByVal adGroupId As Long,
               ByVal bidModifier As Double)
    Using adGroupBidModifierService As AdGroupBidModifierService = CType(
        user.GetService(
            AdWordsService.v201809.AdGroupBidModifierService),
        AdGroupBidModifierService)

        ' Mobile criterion ID.
        Dim criterionId As Long = 30001

        ' Create the adgroup bid modifier.
        Dim adGroupBidModifier As New AdGroupBidModifier()
        adGroupBidModifier.bidModifier = bidModifier
        adGroupBidModifier.adGroupId = adGroupId

        Dim platform As New Platform()
        platform.id = criterionId

        adGroupBidModifier.criterion = platform

        Dim operation As New AdGroupBidModifierOperation()
        operation.operator = [Operator].ADD
        operation.operand = adGroupBidModifier

        Try
            ' Add ad group level mobile bid modifier.
            Dim retval As AdGroupBidModifierReturnValue = adGroupBidModifierService.mutate(
                New AdGroupBidModifierOperation() {operation})

            ' Display the results.
            If Not retval Is Nothing AndAlso Not retval.value Is Nothing AndAlso
               retval.value.Length > 0 Then
                Dim newBidModifier As AdGroupBidModifier = retval.value(0)
                Console.WriteLine(
                    "AdGroup ID {0}, Criterion ID {1} was updated with ad group " &
                    "level modifier: {2}", newBidModifier.adGroupId,
                    newBidModifier.criterion.id,
                    newBidModifier.bidModifier)
            Else
                Console.WriteLine("No bid modifiers were added to the adgroup.")
            End If
        Catch e As Exception
            Throw New _
                System.ApplicationException("Failed to add bid modifiers to adgroup.", e)
        End Try
    End Using

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Close