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("Earth to Mars Cruises #" + System.currentTimeMillis())
          .setCampaign(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(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();
  }
}

C#

private string AddProductShoppingAdGroup(GoogleAdsClient client, long customerId,
            string campaignResourceName)
{
    // Get the AdGroupService.
    AdGroupServiceClient adGroupService = client.GetService(Services.V6.AdGroupService);

    // Creates an ad group.
    AdGroup adGroup = new AdGroup()
    {
        Name = "Earth to Mars Cruises #" + ExampleUtilities.GetRandomString(),
        Campaign = campaignResourceName,
        // Sets the ad group type to SHOPPING_PRODUCT_ADS. This is the only value possible
        // for ad groups that contain shopping product ads.
        Type = AdGroupType.ShoppingProductAds,
        CpcBidMicros = 1_000_000L,
        Status = AdGroupStatus.Enabled
    };

    // Creates an ad group operation.
    AdGroupOperation operation = new AdGroupOperation()
    {
        Create = adGroup
    };

    // Issues a mutate request to add an ad group.
    MutateAdGroupResult mutateAdGroupResult =
        adGroupService
            .MutateAdGroups(customerId.ToString(), new AdGroupOperation[] { operation })
            .Results[0];
    Console.WriteLine("Added a product shopping ad group with resource name: '{0}'.",
        mutateAdGroupResult.ResourceName);
    return mutateAdGroupResult.ResourceName;
}


PHP

private static function addShoppingProductAdGroup(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    string $campaignResourceName
) {
    // Creates an ad group.
    $adGroup = new AdGroup([
        'name' => 'Earth to Mars Cruise #' . uniqid(),
        // Sets the campaign.
        'campaign' => $campaignResourceName,
        // Sets the ad group type to SHOPPING_PRODUCT_ADS. This is the only value possible for
        // ad groups that contain shopping product ads.
        'type' => AdGroupType::SHOPPING_PRODUCT_ADS,
        'cpc_bid_micros' => 10000000,
        'status' => AdGroupStatus::ENABLED
    ]);

    // Creates an ad group operation.
    $adGroupOperation = new AdGroupOperation();
    $adGroupOperation->setCreate($adGroup);

    // Issues a mutate request to add an ad group.
    $adGroupServiceClient = $googleAdsClient->getAdGroupServiceClient();
    $response = $adGroupServiceClient->mutateAdGroups($customerId, [$adGroupOperation]);

    /** @var AdGroup $addedAdGroup */
    $addedAdGroup = $response->getResults()[0];
    printf(
        "Added a shopping product ad group with resource name '%s'.%s",
        $addedAdGroup->getResourceName(),
        PHP_EOL
    );

    return $addedAdGroup->getResourceName();
}

Python

def add_shopping_product_ad_group(client, customer_id, campaign_resource_name):
    """Creates a new shopping product ad group in the specified campaign."""
    ad_group_service = client.get_service("AdGroupService", version="v6")

    # Create ad group.
    ad_group_operation = client.get_type("AdGroupOperation", version="v6")
    ad_group = ad_group_operation.create
    ad_group.name = "Earth to Mars cruise %s" % uuid.uuid4()
    ad_group.status = client.get_type("AdGroupStatusEnum", version="v6").ENABLED
    ad_group.campaign = campaign_resource_name
    # Sets the ad group type to SHOPPING_PRODUCT_ADS. This is the only value
    # possible for ad groups that contain shopping product ads.
    ad_group.type = client.get_type(
        "AdGroupTypeEnum", version="v6"
    ).SHOPPING_PRODUCT_ADS
    ad_group.cpc_bid_micros = 10000000

    # Add the ad group.
    try:
        ad_group_response = ad_group_service.mutate_ad_groups(
            customer_id, [ad_group_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)

    ad_group_resource_name = ad_group_response.results[0].resource_name

    print(
        'Added a product shopping ad group with resource name "%s".'
        % ad_group_resource_name
    )

    return ad_group_resource_name

Ruby

def add_shopping_product_ad_group(client, customer_id, campaign_name)
  operation = client.operation.create_resource.ad_group do |ad_group|
    ad_group.name = "Earth to Mars cruise ##{(Time.new.to_f * 1000).to_i}"
    ad_group.status = :ENABLED
    ad_group.campaign = campaign_name
    ad_group.type = :SHOPPING_PRODUCT_ADS
    ad_group.cpc_bid_micros = 10_000_000
  end

  service = client.service.ad_group
  response = service.mutate_ad_groups(
    customer_id: customer_id,
    operations: [operation],
  )

  ad_group_name = response.results.first.resource_name

  puts "Added a product shopping ad group with resource name #{ad_group_name}."

  ad_group_name
end

Perl

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

  # Create an ad group.
  my $ad_group = Google::Ads::GoogleAds::V6::Resources::AdGroup->new({
    name     => "Earth to Mars Cruises #" . uniqid(),
    campaign => $campaign_resource_name,
    # Set the ad group type to SHOPPING_PRODUCT_ADS. This is the only value
    # possible for ad groups that contain shopping product ads.
    type         => SHOPPING_PRODUCT_ADS,
    cpcBidMicros => 1000000,
    status => Google::Ads::GoogleAds::V6::Enums::AdGroupStatusEnum::ENABLED
  });

  # Create an ad group operation.
  my $ad_group_operation =
    Google::Ads::GoogleAds::V6::Services::AdGroupService::AdGroupOperation->
    new({create => $ad_group});

  # Add the ad group.
  my $ad_group_resource_name = $api_client->AdGroupService()->mutate({
      customerId => $customer_id,
      operations => [$ad_group_operation]})->{results}[0]{resourceName};

  printf "Added a product shopping ad group with resource name: '%s'.\n",
    $ad_group_resource_name;

  return $ad_group_resource_name;
}

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("Earth to Mars Cruises #" + System.currentTimeMillis())
          .setCampaign(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();
  }
}

C#

private string AddSmartShoppingAdGroup(GoogleAdsClient client, long customerId,
            string campaignResourceName)
{
    // Get the AdGroupService.
    AdGroupServiceClient adGroupService = client.GetService(Services.V6.AdGroupService);

    // Creates an ad group.
    AdGroup adGroup = new AdGroup()
    {
        Name = "Earth to Mars Cruises #" + ExampleUtilities.GetRandomString(),
        Campaign = campaignResourceName,
        // Sets the ad group type to SHOPPING_SMART_ADS. This cannot be set to
        // other types.
        Type = AdGroupType.ShoppingSmartAds,
        CpcBidMicros = 1_000_000L,
        Status = AdGroupStatus.Enabled
    };

    // Creates an ad group operation.
    AdGroupOperation operation = new AdGroupOperation()
    {
        Create = adGroup
    };

    // Issues a mutate request to add an ad group.
    MutateAdGroupResult mutateAdGroupResult =
        adGroupService
            .MutateAdGroups(customerId.ToString(), new AdGroupOperation[] { operation })
            .Results[0];
    Console.WriteLine("Added a Smart Shopping ad group with resource name: '{0}'.",
        mutateAdGroupResult.ResourceName);
    return mutateAdGroupResult.ResourceName;
}


PHP

private static function addSmartShoppingAdGroup(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    string $campaignResourceName
) {
    // Creates an ad group.
    $adGroup = new AdGroup([
        'name' => 'Earth to Mars Cruise #' . uniqid(),
        'campaign' => $campaignResourceName,
        // Sets the ad group type to SHOPPING_SMART_ADS. This cannot be set to other types.
        'type' => AdGroupType::SHOPPING_SMART_ADS,
        'status' => AdGroupStatus::ENABLED
    ]);

    // Creates an ad group operation.
    $adGroupOperation = new AdGroupOperation();
    $adGroupOperation->setCreate($adGroup);

    // Issues a mutate request to add the ad group.
    $adGroupServiceClient = $googleAdsClient->getAdGroupServiceClient();
    $response = $adGroupServiceClient->mutateAdGroups($customerId, [$adGroupOperation]);

    /** @var AdGroup $addedAdGroup */
    $addedAdGroup = $response->getResults()[0];
    $addedAdGroupResourceName = $addedAdGroup->getResourceName();
    printf(
        "Added a Smart Shopping ad group with resource name: '%s'.%s",
        $addedAdGroupResourceName,
        PHP_EOL
    );

    return $addedAdGroupResourceName;
}

Ruby

def add_smart_shopping_ad_group(client, customer_id, campaign_name)
  operation = client.operation.create_resource.ad_group do |ad_group|
    ad_group.name = "Earth to Mars cruise ##{(Time.new.to_f * 1000).to_i}"
    ad_group.status = :ENABLED
    ad_group.campaign = campaign_name
    # Sets the ad group type to SHOPPING_SMART_ADS.
    # This cannot be set to other types.
    ad_group.type = :SHOPPING_SMART_ADS
  end

  service = client.service.ad_group
  response = service.mutate_ad_groups(
    customer_id: customer_id,
    operations: [operation],
  )

  ad_group_name = response.results.first.resource_name

  puts "Added a Smart Shopping ad group with resource name #{ad_group_name}."

  ad_group_name
end

Perl

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

  # Create an ad group.
  my $ad_group = Google::Ads::GoogleAds::V6::Resources::AdGroup->new({
    name     => "Earth to Mars Cruises #" . uniqid(),
    campaign => $campaign_resource_name,
    # Set the ad group type to SHOPPING_SMART_ADS. This cannot be set to
    # other types
    type =>
      Google::Ads::GoogleAds::V6::Enums::AdGroupTypeEnum::SHOPPING_SMART_ADS,
    status => Google::Ads::GoogleAds::V6::Enums::AdGroupStatusEnum::ENABLED
  });

  # Create an ad group operation.
  my $ad_group_operation =
    Google::Ads::GoogleAds::V6::Services::AdGroupService::AdGroupOperation->
    new({create => $ad_group});

  # Add the ad group.
  my $ad_group_resource_name = $api_client->AdGroupService()->mutate({
      customerId => $customer_id,
      operations => [$ad_group_operation]})->{results}[0]{resourceName};

  printf "Added a smart shopping ad group with resource name: '%s'.\n",
    $ad_group_resource_name;

  return $ad_group_resource_name;
}