Page Summary
-
Creating a Things to do ad involves creating an Ad and setting its travel_ad to an instance of TravelAdInfo.
-
The second step is to create an AdGroupAd and associate the previously created Ad to it.
-
To serve ads for your ad group, you need one AdGroupAd whose ad is set and whose status is ENABLED.
-
It is recommended to create only one ad per ad group to make tracking ad performance easier.
Creating a Things to do ad involves two steps:
Creating an
Adand setting itstravel_adto an instance ofTravelAdInfo.Creating an
AdGroupAdand associating the previously createdAdto it.
Java
private String addAddGroupAd( GoogleAdsClient googleAdsClient, long customerId, String adGroupResourceName) { // Creates a new travel ad. Ad ad = Ad.newBuilder().setTravelAd(TravelAdInfo.newBuilder()).build(); // Creates a new ad group ad and sets its ad to the travel ad. AdGroupAd adGroupAd = AdGroupAd.newBuilder() // Sets the ad to the ad created above. .setAd(ad) // Set the ad group ad to enabled. Setting this to paused will cause an error for // Things to do campaigns. Pausing should happen at either the ad group or campaign // level. .setStatus(AdGroupAdStatus.ENABLED) // Sets the ad group. .setAdGroup(adGroupResourceName) .build(); // Creates an ad group ad operation. AdGroupAdOperation operation = AdGroupAdOperation.newBuilder().setCreate(adGroupAd).build(); // Issues a mutate request to add an ad group ad. try (AdGroupAdServiceClient adGroupAdServiceClient = googleAdsClient.getLatestVersion().createAdGroupAdServiceClient()) { MutateAdGroupAdResult mutateAdGroupAdResult = adGroupAdServiceClient .mutateAdGroupAds(Long.toString(customerId), Collections.singletonList(operation)) .getResults(0); System.out.printf( "Added an ad group ad with resource name: '%s'%n", mutateAdGroupAdResult.getResourceName()); return mutateAdGroupAdResult.getResourceName(); } }
C#
private static void CreateAdGroupAd(GoogleAdsClient client, long customerId, string adGroup) { // Get the AdGroupAdService. AdGroupAdServiceClient adGroupAdService = client.GetService(Services.V22.AdGroupAdService); // Creates a new ad group ad and sets a travel ad info. AdGroupAd adGroupAd = new AdGroupAd() { Ad = new Ad() { TravelAd = new TravelAdInfo() }, // Set the ad group ad to enabled. Setting this to paused will cause an error for // Things to do campaigns. Pausing should happen at either the ad group or campaign // level. Status = AdGroupAdStatus.Enabled, AdGroup = adGroup }; MutateAdGroupAdsResponse response = adGroupAdService.MutateAdGroupAds( customerId.ToString(), new AdGroupAdOperation[] { new AdGroupAdOperation() { Create = adGroupAd }} ); string adGroupAdResourceName = response.Results[0].ResourceName; Console.WriteLine("Ad group ad with resource name = '{0}' was added.", adGroupAdResourceName); }
PHP
private static function addAdGroupAd( GoogleAdsClient $googleAdsClient, int $customerId, string $adGroupResourceName ) { // Creates a new ad group ad and sets a travel ad info. $adGroupAd = new AdGroupAd([ 'ad' => new Ad(['travel_ad' => new TravelAdInfo()]), // Set the ad group ad to enabled. Setting this to paused will cause an error for Things // to do campaigns. Pausing should happen at either the ad group or campaign level. 'status' => AdGroupAdStatus::ENABLED, // Sets the ad group. 'ad_group' => $adGroupResourceName ]); // Creates an ad group ad operation. $adGroupAdOperation = new AdGroupAdOperation(); $adGroupAdOperation->setCreate($adGroupAd); // Issues a mutate request to add an ad group ad. $adGroupAdServiceClient = $googleAdsClient->getAdGroupAdServiceClient(); $response = $adGroupAdServiceClient->mutateAdGroupAds( MutateAdGroupAdsRequest::build($customerId, [$adGroupAdOperation]) ); /** @var AdGroupAd $addedAdGroupAd */ $addedAdGroupAd = $response->getResults()[0]; printf( "Added an ad group ad with resource name '%s'.%s", $addedAdGroupAd->getResourceName(), PHP_EOL ); }