Creating a Hotel Ad Group Ad

  • Creating a Hotel ad requires two steps: creating an Ad with hotel_ad set to a HotelAdInfo instance, and then creating an AdGroupAd associated with that Ad.

  • To serve Hotel Ads, you need at least one AdGroupAd with its ad set and its status set to ENABLED.

  • It is recommended to create only one AdGroupAd per ad group for easier metric distinction, as impressions are shared among multiple ad group ads within the same ad group.

Creating a Hotel ad involves two steps:

  1. Creating an Ad and setting its hotel_ad to an instance of HotelAdInfo.

  2. Creating an AdGroupAd and associating the previously created Ad to it.

Java

private String addHotelAdGroupAd(
    GoogleAdsClient googleAdsClient, long customerId, String adGroupResourceName) {
  // Creates a new hotel ad.
  Ad ad = Ad.newBuilder().setHotelAd(HotelAdInfo.newBuilder().build()).build();
  // Creates a new ad group ad and sets the hotel ad to it.
  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 hotel campaigns.  For hotels 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 a hotel ad group ad with resource name: '%s'%n",
        mutateAdGroupAdResult.getResourceName());
    return mutateAdGroupAdResult.getResourceName();
  }
}
      

C#

private static void AddHotelAdGroupAd(GoogleAdsClient client, long customerId,
    string adGroupResourceName)
{
    // Get the AdGroupAdService.
    AdGroupAdServiceClient service = client.GetService(Services.V22.AdGroupAdService);

    // Create a new ad group ad and sets the hotel ad to it.
    AdGroupAd adGroupAd = new AdGroupAd()
    {
        // Create a new hotel ad.
        Ad = new Ad()
        {
            HotelAd = new HotelAdInfo(),
        },
        // Set the ad group.
        AdGroup = adGroupResourceName,
        // Set the ad group ad to enabled.  Setting this to paused will cause an error
        // for hotel campaigns.  For hotels pausing should happen at either the ad group or
        // campaign level.
        Status = AdGroupAdStatus.Enabled
    };

    // Create an ad group ad operation.
    AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation()
    {
        Create = adGroupAd
    };

    // Issue a mutate request to add an ad group ad.
    MutateAdGroupAdsResponse response = service.MutateAdGroupAds(customerId.ToString(),
        new AdGroupAdOperation[] { adGroupAdOperation });

    MutateAdGroupAdResult addedAdGroupAd = response.Results[0];
    Console.WriteLine($"Added a hotel ad group ad with resource name " +
        $"{addedAdGroupAd.ResourceName}.");
}
      

PHP

private static function addHotelAdGroupAd(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    string $adGroupResourceName
) {
    // Creates a new hotel ad.
    $ad = new Ad([
        'hotel_ad' => new HotelAdInfo(),
    ]);

    // Creates a new ad group ad and sets the hotel ad to it.
    $adGroupAd = new AdGroupAd([
        'ad' => $ad,
        // Set the ad group ad to enabled.  Setting this to paused will cause an error
        // for hotel campaigns.  For hotels 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 a hotel ad group ad with resource name '%s'.%s",
        $addedAdGroupAd->getResourceName(),
        PHP_EOL
    );
}