Create an Ad Group

Stay organized with collections Save and categorize content based on your preferences.

To create an ad group for your Smart Display campaign, follow the same process you use for other ad groups. However, since Google Ads manages most aspects of a Smart Display campaign, targeting options at the ad group level are not allowed.


private static String createAdGroup(
    GoogleAdsClient googleAdsClient, long customerId, String campaignResourceName) {
  // Creates the ad group.
  AdGroup adGroup =
          .setName("Earth to Mars Cruises #" + getPrintableDateTime())

  // Creates the operation.
  AdGroupOperation operation = AdGroupOperation.newBuilder().setCreate(adGroup).build();

  // Creates the ad group service client.
  try (AdGroupServiceClient adGroupServiceClient =
      googleAdsClient.getLatestVersion().createAdGroupServiceClient()) {
    MutateAdGroupsResponse response =
            Long.toString(customerId), ImmutableList.of(operation));
    String adGroupResourceName = response.getResults(0).getResourceName();
    // Displays the results.
    System.out.printf("Added ad group with resource name '%s'.%n", adGroupResourceName);
    return adGroupResourceName;


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

    // Create the ad group.
    AdGroup adGroup = new AdGroup()
        Name = $"Earth to Mars Cruises #{ExampleUtilities.GetRandomString()}",
        Status = AdGroupStatusEnum.Types.AdGroupStatus.Enabled,
        Campaign = campaignResourceName,

    // Create the operation.
    AdGroupOperation operation = new AdGroupOperation()
        Create = adGroup

    // Create the ad groups.
    MutateAdGroupsResponse response = adGroupService.MutateAdGroups(
        customerId.ToString(), new[] { operation });

    string adGroupResourceName = response.Results.First().ResourceName;

    // Print out some information about the added ad group.
    Console.WriteLine($"Added ad group with resource name = '{adGroupResourceName}'.");

    return adGroupResourceName;


private static function createAdGroup(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    string $campaignResourceName
) {
    // Constructs an ad group and set its type.
    $adGroup = new AdGroup([
        'name' => 'Earth to Mars Cruises #' . Helper::getPrintableDatetime(),
        'campaign' => $campaignResourceName,
        'status' => AdGroupStatus::PAUSED,

    // Creates an ad group operation.
    $adGroupOperation = new AdGroupOperation();

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

    // Print out some information about the added ad group.
    $adGroupResourceName = $adGroupResponse->getResults()[0]->getResourceName();
    printf("Added ad group named '%s'.%s", $adGroupResourceName, PHP_EOL);

    return $adGroupResourceName;


def create_ad_group(client, customer_id, campaign_resource_name):
    ad_group_service = client.get_service("AdGroupService")
    ad_group_operation = client.get_type("AdGroupOperation")
    ad_group = ad_group_operation.create = f"Earth to Mars Cruises #{uuid4()}"
    ad_group_status_enum = client.enums.AdGroupStatusEnum
    ad_group.status = ad_group_status_enum.PAUSED
    ad_group.campaign = campaign_resource_name

        ad_group_response = ad_group_service.mutate_ad_groups(
            customer_id=customer_id, operations=[ad_group_operation]
    except GoogleAdsException as ex:

    return ad_group_response.results[0].resource_name


def create_ad_group(client, customer_id, campaign)
  # Creates an ad group operation.
  operation = client.operation.create_resource.ad_group do |ag| = "Earth to Mars Cruises #{( * 1000).to_i}"
    ag.campaign = campaign
    ag.status = :PAUSED

  # Issues a mutate request to add the ad group.
  response = client.service.ad_group.mutate_ad_groups(
    customer_id: customer_id,
    operations: [operation],

  # Print out some information about the added ad group.
  resource_name = response.results.first.resource_name
  puts "Added ad group named #{resource_name}"



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

  # Construct an ad group and set its type.
  my $ad_group = Google::Ads::GoogleAds::V11::Resources::AdGroup->new({
    name     => "Earth to Mars Cruises #" . uniqid(),
    campaign => $campaign_resource_name,
    status   => Google::Ads::GoogleAds::V11::Enums::AdGroupStatusEnum::PAUSED

  # Create an ad group operation.
  my $ad_group_operation =
      create => $ad_group

  # Issue a mutate request to add the ad group.
  my $ad_groups_response = $api_client->AdGroupService()->mutate({
      customerId => $customer_id,
      operations => [$ad_group_operation]});

  # Print out some information about the added ad group.
  my $ad_group_resource_name =
  printf "Added ad group named '%s'.\n", $ad_group_resource_name;

  return $ad_group_resource_name;