出价

AdWords 为您提供了多种广告出价方式,具体使用哪种方式取决于对您和您的业务而言什么最重要。

在 AdWords API 中,所有出价参数都通过下面的一个或全部两个对象加以管理:

对于任一对象,您可以使用其 biddingStrategyType 字段、biddingScheme 字段或同时使用这两者来指定出价类型。借助 biddingScheme,您可以设置某种出价类型所特有的更多参数。如果同时指定这两个字段,它们的类型必须匹配。

策略类型

在下表中,有效上下文列指示是否可在上述一个或两个上下文中使用给定的 BiddingStrategyType 和关联的 BiddingScheme 类型:

  • BiddingStrategyConfiguration 对象表示的标准策略。
  • SharedBiddingStrategy 对象表示的组合策略。
BiddingStrategyType BiddingScheme 描述性名称 有效上下文
BUDGET_OPTIMIZER

不再提供。请改用 TARGET_SPEND

BudgetOptimizerBiddingScheme 预算优化工具 标准
CONVERSION_OPTIMIZER

不再提供。请改用 TARGET_CPA

ConversionOptimizerBiddingScheme 关注转化 - 使用每次转化费用出价 标准
ENHANCED_CPC EnhancedCpcBiddingScheme 智能点击付费 组合
MANUAL_CPC

对于 201802 版或更高版本,enhancedCpcEnabled 默认为 true。

ManualCpcBiddingScheme 关注点击 - 使用每次点击费用的最高出价 标准
MANUAL_CPM ManualCpmBiddingScheme CPM(每千次展示费用)。

仅适用于“仅限展示广告网络”广告系列

标准
MAXIMIZE_CONVERSIONS MaximizeConversionsBiddingScheme 尽可能提高转化次数

仅适用于搜索广告系列

标准
PAGE_ONE_PROMOTED PageOnePromotedBiddingScheme 目标搜索页位置 组合
TARGET_CPA TargetCpaBiddingScheme 目标每次转化费用 (CPA) - 必须满足资格要求 组合
标准
TARGET_OUTRANK_SHARE TargetOutrankShareBiddingScheme 排名胜出率目标 组合
TARGET_ROAS TargetRoasBiddingScheme 目标广告支出回报率 - 必须符合资格要求 组合
标准
TARGET_SPEND

(仅适用于 201710 版)enhancedCpcEnabled 只能在标准策略中设置。

TargetSpendBiddingScheme 尽可能争取更多点击次数 组合
标准
NONE 用于清除 AdGroup 和 AdGroupCriterion 一级的出价策略的特殊出价策略类型。 组合
标准

如果您尝试在错误的上下文中使用 BiddingStrategyTypeBiddingScheme,则会导致错误:

  • 在标准策略的上下文中使用纯组合类型或方案会产生 BiddingErrors 错误,原因为 INVALID_ANONYMOUS_BIDDING_STRATEGY_TYPE
  • 在组合策略的上下文中使用纯标准类型或方案会产生 BiddingErrors 错误,原因为 BIDDING_STRATEGY_NOT_SUPPORTED

指定广告系列策略

标准出价策略

要将标准出价策略用于您的广告系列,请按以下方式配置广告系列的 biddingStrategyConfiguration

  • 如果您不需要配置策略的其他属性,只需设置其 biddingStrategyType 即可。
  • 如果您需要配置策略的其他属性,例如 MANUAL_CPC 策略的 enhancedCpcEnabled 属性,请设置配置的 biddingStrategyScheme
  • 不要设置出价策略配置的 biddingStrategyIdbiddingStrategyName

组合出价策略

要将组合出价策略用于您的广告系列,您有两个选择:

  1. 使用现有的 SharedBiddingStrategy
  2. 使用 BiddingStrategyService 创建新的 SharedBiddingStrategy 并设置其参数。

选择 SharedBiddingStrategy 后,通过将广告系列的 biddingStrategyConfiguration 设置为配置,并将 biddingStrategyId 设置为共享出价策略的 id 来配置广告系列,从而使用该策略。

变换出价策略

您可以使用 CampaignService mutate()SET operation 更新广告系列的出价策略。operand 应该是一个 Campaign(其 id 设置为广告系列的 ID),并按照指定广告系列策略中的说明配置 biddingStrategyConfiguration

替换策略设置

在广告组一级替换目标每次转化费用

通过设置广告组出价策略配置的 targetRoasOverride,您可以在广告组一级替换标准 TARGET_ROAS 策略的 TargetRoasBiddingSchemetargetRoas。不能替换此策略出价方案的其他字段。

要移除替换,请将广告组的 BiddingStrategyConfigurationtargetRoasOverride 设置为 0

尝试替换组合 TargetRoasBiddingSchemetargetRoas 会导致错误。

在广告组一级替换目标每次转化费用

通过将 CpaBid 添加到广告组的出价策略配置,您可以在广告组一级替换 TARGET_CPA 策略的 TargetCpaBiddingSchemetargetCpa。不能替换此策略出价方案的其他字段。

替换在较高级别设置的标准出价策略

您不能在较低级别设置与较高级别不同的出价策略。例如,如果广告系列一级存在 MANUAL_CPC 策略,那么在广告组一级设置 MANUAL_CPM 策略就会引发错误。

当较高级别存在 MANUAL_CPC 策略时,您才可以在较低级别设置 MANUAL_CPC 策略;不过,您最好直接设置出价

设置出价

可以在广告组和广告组条件一级设置出价。条件一级的出价将会替换广告组一级的出价。尝试在广告系列一级设置出价将会失败。

可以在单个 BiddingStrategyConfiguration 中同时设置不同类型的多个出价,例如,CpcBidCpmBid,但系统只会将与当前所选 biddingStrategyType 相关的出价作为广告的出价。

以下代码示例使用 mutate 调用在广告组一级添加每次点击费用出价。

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);

CSharp

// Create an ad group with the specified ID.
AdGroup adGroup = new AdGroup();
adGroup.id = adGroupId;

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

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

// Create the operation.
AdGroupOperation operation = new AdGroupOperation();
operation.@operator = Operator.SET;
operation.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='v201802')

# 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::v201802::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::v201802::BiddingStrategyConfiguration->new({
      bids => [
        Google::Ads::AdWords::v201802::CpcBid->new({
            bid => Google::Ads::AdWords::v201802::Money->new({
                microAmount => $cpc_bid_micro_amount
            }),
          }),
      ]
    });
  $ad_group->set_biddingStrategyConfiguration(
    $bidding_strategy_configuration);
}

# Create operation.
my $operation = Google::Ads::AdWords::v201802::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})

移除出价

要从 BiddingStrategyConfiguration 中移除出价,请将其 bid 字段更新为 Money 对象,并将 microAmount 设置为 0

展示广告网络的条件维度

对于投放在展示广告网络上的广告,您可以针对一些不同维度设置广告组出价。如果在不同维度中设置了多个出价,可使用 contentBidCriterionTypeGroup 字段指定应当用于绝对出价的维度。搜索网络上的广告会始终使用关键字出价。

您还可以设置出价调整,当条件不在绝对出价维度中时将会用到所设的出价调整。您可以通过 BiddableAdGroupCriterionbidModifier 字段来获取出价调整。

出价系数

广告系列和广告组级出价调整可让您针对特定条件上下调整出价,从而更好地控制 AdWords 广告系列中的出价。

在 AdWords API 中,您可以通过 CampaignCriterionServiceCampaignBidModifierService 访问广告系列一级的调整,通过 AdGroupBidModifierService 访问广告组一级的调整。

检索出价调整

要检索现有出价调整,请使用 CampaignCriterionServiceAdGroupBidModifierServiceCampaignBidModifierServiceget()query() 方法。与其他服务类似,get() 方法接受通用的选择器,允许您选择响应字段并过滤结果集。

以下代码会检索广告组的所有出价系数:

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.");
  }
}

CSharp

public void Run(AdWordsUser user, long campaignId) {
  using (AdGroupBidModifierService adGroupBidModifierService =
      (AdGroupBidModifierService) user.GetService(
          AdWordsService.v201802.AdGroupBidModifierService)) {

    // Get all ad group bid modifiers for the campaign.
    Selector selector = new Selector() {
      fields = new String[] {
      AdGroupBidModifier.Fields.CampaignId, AdGroupBidModifier.Fields.AdGroupId,
      AdGroupBidModifier.Fields.BidModifier, AdGroupBidModifier.Fields.BidModifierSource,
      Criterion.Fields.CriteriaType, Criterion.Fields.Id
    },
      predicates = new Predicate[] {
      Predicate.Equals(AdGroupBidModifier.Fields.CampaignId, campaignId)
    },
      paging = Paging.Default
    };

    AdGroupBidModifierPage page = new AdGroupBidModifierPage();

    try {
      do {
        // Get the campaigns.
        page = adGroupBidModifierService.get(selector);

        // Display the results.
        if (page != null && page.entries != null) {
          int i = selector.paging.startIndex;
          foreach (AdGroupBidModifier adGroupBidModifier in page.entries) {
            string bidModifier = (adGroupBidModifier.bidModifierSpecified) ?
                adGroupBidModifier.bidModifier.ToString() : "UNSET";
            Console.WriteLine("{0}) Campaign ID {1}, AdGroup ID {2}, Criterion ID {3} has " +
                "ad group level modifier: {4} and source = {5}.",
                i + 1, adGroupBidModifier.campaignId,
                adGroupBidModifier.adGroupId, adGroupBidModifier.criterion.id, bidModifier,
                adGroupBidModifier.bidModifierSource);
            i++;
          }
        }
        selector.paging.IncreaseOffset();
      } while (selector.paging.startIndex < page.totalNumEntries);
      Console.WriteLine("Number of adgroup bid modifiers found: {0}", page.totalNumEntries);
    } catch (Exception e) {
      throw new System.ApplicationException("Failed to retrieve adgroup bid modifiers.", e);
    }
  }
}

Python

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

  # 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::v201802::Paging->new({
      startIndex    => 0,
      numberResults => PAGE_SIZE
  });
  my $selector = Google::Ads::AdWords::v201802::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: %s\n", $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.v201802.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

添加、更新和移除出价调整

使用 CampaignCriterionServiceAdGroupBidModifierServiceCampaignBidModifierServicemutate() 方法可添加或修改出价调整。

  • 要添加新的出价系数,请使用 ADD 运算符。
  • 要将现有出价覆盖设置更新为新值,请使用 SET 运算符。
  • 要移除出价系数覆盖设置,请使用 REMOVE 运算符。
  • 对现有的 CampaignBidModifier、AdGroupBidModifier 或 AdGroupCriterion 执行 ADD 操作会导致该操作被视为 SET

下面示例演示了如何添加新的广告组级移动设备出价调整:

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());
  }
}

CSharp

public void Run(AdWordsUser user, long adGroupId, double bidModifier) {
  using (AdGroupBidModifierService adGroupBidModifierService =
      (AdGroupBidModifierService) user.GetService(
          AdWordsService.v201802.AdGroupBidModifierService)) {

    // Mobile criterion ID.
    long criterionId = 30001;

    // Create the adgroup bid modifier.
    AdGroupBidModifier adGroupBidModifier = new AdGroupBidModifier();
    adGroupBidModifier.bidModifier = bidModifier;
    adGroupBidModifier.adGroupId = adGroupId;

    Platform platform = new Platform();
    platform.id = criterionId;

    adGroupBidModifier.criterion = platform;

    AdGroupBidModifierOperation operation = new AdGroupBidModifierOperation();
    operation.@operator = Operator.ADD;
    operation.operand = adGroupBidModifier;

    try {
      // Add ad group level mobile bid modifier.
      AdGroupBidModifierReturnValue retval = adGroupBidModifierService.mutate(
          new AdGroupBidModifierOperation[] { operation });

      // Display the results.
      if (retval != null && retval.value != null && retval.value.Length > 0) {
        AdGroupBidModifier newBidModifier = 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.");
      }
    } catch (Exception e) {
      throw new System.ApplicationException("Failed to add bid modifiers to adgroup.", e);
    }
  }
}

Python

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

  # 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::v201802::Platform->new({id => 30001});

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

  # Create ADD operation.
  my $operation =
    Google::Ads::AdWords::v201802::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.v201802.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

发送以下问题的反馈:

此网页
AdWords API
AdWords API
需要帮助?请访问我们的支持页面