Creating a Hotel Ad Group

In order to serve ads for your Hotel campaign, you must create an AdGroup with at least one ad in the ad group. As shown later, a Hotel campaign supports only an ad group of the HOTEL_ADS type, which you can set in type. The code example also sets a Percent CPC bid since the campaign's bidding strategy is PercentCpc.

PHP

private static function addHotelAdGroup(
    GoogleAdsClient $googleAdsClient,
    $customerId,
    $campaignResourceName
) {
    // Creates an ad group.
    $adGroup = new AdGroup();

    $wrappedName = new StringValue();
    $wrappedName->setValue('Earth to Mars Cruise #' . uniqid());
    $adGroup->setName($wrappedName);

    // Sets the campaign.
    $wrappedCampaignResourceName = new StringValue();
    $wrappedCampaignResourceName->setValue($campaignResourceName);
    $adGroup->setCampaign($wrappedCampaignResourceName);

    // Sets the ad group type to HOTEL_ADS.
    // This cannot be set to other types.
    $adGroup->setType(AdGroupTypeEnum_AdGroupType::HOTEL_ADS);

    $wrappedCpcBidMicros = new Int64Value();
    $wrappedCpcBidMicros->setValue(10000000);
    $adGroup->setCpcBidMicros($wrappedCpcBidMicros);

    $adGroup->setStatus(AdGroupStatusEnum_AdGroupStatus::ENABLED);

    // Creates an ad group operation.
    $adGroupOperation = new AdGroupOperation();
    $adGroupOperation->setCreate($adGroup);

    // Issues a mutate request to add an ad group.
    $adGroupServiceClient = $googleAdsClient->getAdGroupServiceClient();
    $response = $adGroupServiceClient->mutateAdGroups($customerId, [$adGroupOperation]);

    /** @var AdGroup $addedAdGroup */
    $addedAdGroup = $response->getResults()[0];
    printf(
        "Added a hotel ad group with resource name '%s'.%s",
        $addedAdGroup->getResourceName(),
        PHP_EOL
    );

    return $addedAdGroup->getResourceName();
}

Send feedback about...

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