Google Ads API is returning to beta status. Please read our blog post for more details.

创建酒店广告组

要为您的酒店广告系列投放广告,您必须创建一个 AdGroup,且该广告组中至少包含一个广告。如下所示,酒店广告系列仅支持 HOTEL_ADS 类型的广告组,您可以在 type 中对此进行设置。由于广告系列的出价策略为 PercentCpc,该代码示例还设置了“百分比形式的每次点击费用”出价。

PHP
private static function addHotelAdGroup(
    GoogleAdsClient $googleAdsClient,
    $customerId,
    $campaignResourceName
) {
    // Creates an ad group.
    $adGroup = new AdGroup([
        'name' => new StringValue(['value' => 'Earth to Mars Cruise #' . uniqid()]),
        // Sets the campaign.
        'campaign' => new StringValue(['value' => $campaignResourceName]),
        // Sets the ad group type to HOTEL_ADS.
        // This cannot be set to other types.
        'type' => AdGroupType::HOTEL_ADS,
        'cpc_bid_micros' => new Int64Value(['value' => 10000000]),
        'status' => 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();
}