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

Creating a Shopping Ad Group

To serve ads for your Shopping campaign, you must create an AdGroup.

Standard Shopping campaigns

Standard Shopping campaigns support the SHOPPING_PRODUCT_ADS ad group type. This is the default ad group type for Shopping campaigns, serving standard product ads. It can be set by providing the ad group type field.

Standard Shopping campaigns can contain multiple ad groups, each containing at least one ad.

This code example demonstrates how to create an ad group for a standard Shopping campaign. The example also sets a CPC bid to match the campaign's bid strategy, which is set to 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();
  }
}

Smart Shopping campaigns

Smart Shopping campaigns support the SHOPPING_SMART_ADS ad group type. This is the only ad group type that can be used with Smart Shopping campaigns. It can be set by providing the ad group type field.

Smart Shopping campaigns can only contain a single ad group and a single ad.

This code example demonstrates how to create an ad group for a Smart Shopping campaign.

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