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

(可选)创建酒店广告组出价系数

创建广告组出价系数属于可选步骤,旨在根据不同情况优化出价。Google Ads API 支持根据以下条件设置特定于酒店广告的出价系数:

要详细了解这些条件,请访问 Hotel Ads Center 帮助。以下示例代码介绍了如何为酒店广告创建广告组出价系数:

PHP
public static function runExample(
    GoogleAdsClient $googleAdsClient,
    $customerId,
    $adGroupId
) {
    $operations = [];

    // 1) Creates an ad group bid modifier based on the hotel check-in day.
    $checkInDayAdGroupBidModifier = new AdGroupBidModifier([
        // Sets the ad group.
        'ad_group' =>
            new StringValue(['value' => ResourceNames::forAdGroup($customerId, $adGroupId)]),
        'hotel_check_in_day' => new HotelCheckInDayInfo([
            'day_of_week' => DayOfWeek::MONDAY
        ]),
        // Sets the bid modifier value to 150%.
        'bid_modifier' => new DoubleValue(['value' => 1.5])
    ]);

    // Creates an ad group bid modifier operation.
    $checkInDayAdGroupBidModifierOperation = new AdGroupBidModifierOperation();
    $checkInDayAdGroupBidModifierOperation->setCreate($checkInDayAdGroupBidModifier);
    $operations[] = $checkInDayAdGroupBidModifierOperation;

    // 2) Creates an ad group bid modifier based on the hotel length of stay.
    $lengthOfStayAdGroupBidModifier = new AdGroupBidModifier([
        // Sets the ad group.
        'ad_group' =>
            new StringValue(['value' => ResourceNames::forAdGroup($customerId, $adGroupId)]),
        // Creates the hotel length of stay info.
        'hotel_length_of_stay' => new HotelLengthOfStayInfo([
            'min_nights' => new Int64Value(['value' => 3]),
            'max_nights' => new Int64Value(['value' => 7]),
        ]),
        // Sets the bid modifier value to 170%.
        'bid_modifier' => new DoubleValue(['value' => 1.7])
    ]);

    // Creates an ad group bid modifier operation.
    $lengthOfStayAdGroupBidModifierOperation = new AdGroupBidModifierOperation();
    $lengthOfStayAdGroupBidModifierOperation->setCreate(
        $lengthOfStayAdGroupBidModifier
    );
    $operations[] = $lengthOfStayAdGroupBidModifierOperation;

    // Issues a mutate request to add an ad group bid modifiers.
    $adGroupBidModifierServiceClient = $googleAdsClient->getAdGroupBidModifierServiceClient();
    $response = $adGroupBidModifierServiceClient->mutateAdGroupBidModifiers(
        $customerId,
        $operations
    );

    // Print out resource names of the added ad group bid modifiers.
    printf(
        "Added %d hotel ad group bid modifiers:%s",
        $response->getResults()->count(),
        PHP_EOL
    );
    foreach ($response->getResults() as $addedAdGroupBidModifier) {
        /** @var AdGroupBidModifier $addedAdGroupBidModifier */
        print $addedAdGroupBidModifier->getResourceName() . PHP_EOL;
    }
}

如代码示例所示,您需要先创建相关类的对象,例如 HotelAdvanceBookingWindowInfoHotelDateSelectionTypeInfo,然后将其字段设置为所需的值。例如,如果您想使用介于 30 到 60 天之间的提前预订期限创建广告组出价系数,则需要创建 HotelAdvanceBookingWindowInfo 对象,并将 min_days 设置为 30,将 max_days 设置为 60。

最后,将相关对象与 AdGroupBidModifier 对象相关联。此外,您还必须通过 ad_group 指定广告组出价系数所属的广告组的资源名称。