Create an Ad Group

In order to serve ads for your Local campaign, you must create at least one AdGroup using AdGroupService. Don't specify a type for the ad group.


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

  # Create an ad group.
  # Note that the ad group type must not be set.
  # Since the advertisingChannelSubType is LOCAL_CAMPAIGN:
  #   1. you cannot override bid settings at the ad group level.
  #   2. you cannot add ad group criteria.
  my $ad_group = Google::Ads::GoogleAds::V6::Resources::AdGroup->new({
    name     => "Earth to Mars Cruises #" . uniqid(),
    status   => Google::Ads::GoogleAds::V6::Enums::AdGroupStatusEnum::ENABLED,
    campaign => $campaign_resource_name

  # Create an ad group operation.
  my $ad_group_operation =
    new({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]});

  my $ad_group_resource_name =
  printf "Created ad group with resource name: '%s'.\n",

  return $ad_group_resource_name;