Creating a Hotel Ad Group Ad

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.

PHP

private static function addHotelAdGroupAd(
    GoogleAdsClient $googleAdsClient,
    $customerId,
    $adGroupResourceName
) {
    // Creates a new hotel ad.
    $ad = new Ad();
    $ad->setHotelAd(new HotelAdInfo());

    // Creates a new ad group ad and sets the hotel ad to it.
    $adGroupAd = new AdGroupAd();
    $adGroupAd->setAd($ad);
    $adGroupAd->setStatus(AdGroupAdStatusEnum_AdGroupAdStatus::PAUSED);

    // Sets the ad group.
    $wrappedAdGroupResourceName = new StringValue();
    $wrappedAdGroupResourceName->setValue($adGroupResourceName);
    $adGroupAd->setAdGroup($wrappedAdGroupResourceName);

    // 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($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
    );
}

Send feedback about...

Google Ads API Beta
Google Ads API Beta
Need help? Visit our support page.