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.


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();

    // 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];
        "Added a hotel ad group ad with resource name '%s'.%s",