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

创建购物广告组

要为购物广告系列投放广告,您必须创建 AdGroup

标准购物广告系列

标准购物广告系列支持 SHOPPING_PRODUCT_ADS 广告组类型。这是购物广告系列的默认广告组类型,用于投放标准产品广告。您可以通过提供广告组 type 字段对其进行设置。

标准购物广告系列可以包含多个广告组,每个广告组至少包含一个广告。

此代码示例演示了如何为标准购物广告系列创建广告组。它还设置了每次点击费用出价,以匹配广告系列的出价策略(在本例中的设置是 ManualCpc)。

Java

private String addShoppingProductAdGroup(
    GoogleAdsClient googleAdsClient, long customerId, String campaignResourceName) {
  // Creates an ad group.
  AdGroup adGroup =
      AdGroup.newBuilder()
          .setName(StringValue.of("Earth to Mars Cruises #" + System.currentTimeMillis()))
          .setCampaign(StringValue.of(campaignResourceName))
          // Sets the ad group type to SHOPPING_PRODUCT_ADS. This is the only value possible for
          // ad groups that contain shopping product ads.
          .setType(AdGroupType.SHOPPING_PRODUCT_ADS)
          .setCpcBidMicros(Int64Value.of(1_000_000L))
          .setStatus(AdGroupStatus.ENABLED)
          .build();

  // Creates an ad group operation.
  AdGroupOperation operation = AdGroupOperation.newBuilder().setCreate(adGroup).build();

  // Issues a mutate request to add an ad group.
  try (AdGroupServiceClient adGroupServiceClient = googleAdsClient.getLatestVersion().createAdGroupServiceClient()) {
    MutateAdGroupResult mutateAdGroupResult =
        adGroupServiceClient
            .mutateAdGroups(Long.toString(customerId), Collections.singletonList(operation))
            .getResults(0);
    System.out.printf(
        "Added a product shopping ad group with resource name: '%s'%n",
        mutateAdGroupResult.getResourceName());
    return mutateAdGroupResult.getResourceName();
  }
}

智能购物广告系列

智能购物广告系列支持 SHOPPING_SMART_ADS 广告组类型。这是唯一可用于智能购物广告系列的广告组类型。您可以通过提供广告组 type 字段对其进行设置。

智能购物广告系列只能包含一个广告组和一个广告。

此代码示例演示了如何为智能购物广告系列创建广告组。

Java

private String addSmartShoppingAdGroup(
    GoogleAdsClient googleAdsClient, long customerId, String campaignResourceName) {
  // Creates an ad group.
  AdGroup adGroup =
      AdGroup.newBuilder()
          .setName(StringValue.of("Earth to Mars Cruises #" + System.currentTimeMillis()))
          .setCampaign(StringValue.of(campaignResourceName))
          // Sets the ad group type to SHOPPING_SMART_ADS. This cannot be set to other types.
          .setType(AdGroupType.SHOPPING_SMART_ADS)
          .setStatus(AdGroupStatus.ENABLED)
          .build();

  // Creates an ad group operation.
  AdGroupOperation operation = AdGroupOperation.newBuilder().setCreate(adGroup).build();

  // Issues a mutate request to add an ad group.
  try (AdGroupServiceClient adGroupServiceClient = googleAdsClient.getLatestVersion().createAdGroupServiceClient()) {
    MutateAdGroupResult mutateAdGroupResult =
        adGroupServiceClient
            .mutateAdGroups(Long.toString(customerId), Collections.singletonList(operation))
            .getResults(0);
    System.out.printf(
        "Added a Smart Shopping ad group with resource name: '%s'%n",
        mutateAdGroupResult.getResourceName());
    return mutateAdGroupResult.getResourceName();
  }
}