Page Summary
-
To serve ads for your Things to do campaign, you must create an AdGroup with at least one ad in the ad group.
-
A campaign supports only an ad group of the TRAVEL_ADS type.
To serve ads for your Things to do campaign, you must create an
AdGroup with at least one ad in the ad group. As
shown later, a campaign supports only an ad group of the
TRAVEL_ADS type,
which you can set in the type field.
Java
private String addAdGroup( GoogleAdsClient googleAdsClient, long customerId, String campaignResourceName) { // Creates an ad group. AdGroup adGroup = AdGroup.newBuilder() .setName("Earth to Mars Cruises #" + getPrintableDateTime()) .setCampaign(campaignResourceName) // Sets the ad group type to TRAVEL_ADS. This cannot be set to other types. .setType(AdGroupType.TRAVEL_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 an ad group with resource name: '%s'%n", mutateAdGroupResult.getResourceName()); return mutateAdGroupResult.getResourceName(); } }
C#
private static string CreateAdGroup(GoogleAdsClient client, long customerId, string campaign) { // Get the AdGroupService. AdGroupServiceClient adGroupService = client.GetService(Services.V22.AdGroupService); // Create the ad group. AdGroup adGroup = new AdGroup() { Name = $"Earth to Mars Cruises #{ExampleUtilities.GetRandomString()}", Status = AdGroupStatus.Enabled, Campaign = campaign, Type = AdGroupType.TravelAds }; MutateAdGroupsResponse response = adGroupService.MutateAdGroups( customerId.ToString(), new AdGroupOperation[] { new AdGroupOperation() { Create = adGroup }} ); string adGroupResourceName = response.Results[0].ResourceName; Console.WriteLine("Ad group with resource name = '{0}' was added.", adGroupResourceName); return adGroupResourceName; }
PHP
private static function addAdGroup( GoogleAdsClient $googleAdsClient, int $customerId, string $campaignResourceName ) { // Creates an ad group. $adGroup = new AdGroup([ 'name' => 'Earth to Mars Cruise #' . Helper::getPrintableDatetime(), // Sets the campaign. 'campaign' => $campaignResourceName, // Sets the ad group type to TRAVEL_ADS. This cannot be set to other types. 'type' => AdGroupType::TRAVEL_ADS, '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( MutateAdGroupsRequest::build($customerId, [$adGroupOperation]) ); /** @var AdGroup $addedAdGroup */ $addedAdGroup = $response->getResults()[0]; printf( "Added an ad group with resource name '%s'.%s", $addedAdGroup->getResourceName(), PHP_EOL ); return $addedAdGroup->getResourceName(); }