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([
        'hotel_ad' => new HotelAdInfo(),
    ]);

    // Creates a new ad group ad and sets the hotel ad to it.
    $adGroupAd = new AdGroupAd([
        'ad' => $ad,
        'status' => AdGroupAdStatus::PAUSED,
        // Sets the ad group.
        'ad_group' => new StringValue(['value' => $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($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
    );
}

Envoyer des commentaires concernant…

Besoin d'aide ? Consultez notre page d'assistance.