(Optional) Creating a Hotel Ad Group Bid Modifier

Creating an ad group bid modifier is an optional step for fine-tuning bids based on different circumstances. Google Ads API supports setting Hotel Ads-specific bid modifiers based on the following criteria:

Visit the Hotel Ads Center Help for more details about these criteria. Here is a code example of creating ad group bid modifiers for Hotel Ads:

PHP

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

    // 1) Creates an ad group bid modifier based on the hotel check-in day.
    $checkInDayAdGroupBidModifier = new AdGroupBidModifier();

    // Sets the resource name for the criterion ID whose value corresponds to the desired
    // check-in day.
    $checkInDayResourceName = ResourceNames::forAdGroupBidModifier(
        $customerId,
        $adGroupId,
        $checkInDayCriterionId
    );
    $checkInDayAdGroupBidModifier->setResourceName($checkInDayResourceName);

    // Sets the bid modifier value to 150%.
    $wrappedBidModifierValue = new DoubleValue();
    $wrappedBidModifierValue->setValue(1.5);
    $checkInDayAdGroupBidModifier->setBidModifier($wrappedBidModifierValue);
    $checkInDayAdGroupBidModifier->setHotelCheckInDay(new HotelCheckInDayInfo());

    // 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.
    $wrappedAdGroupResourceName = new StringValue();
    $wrappedAdGroupResourceName->setValue(ResourceNames::forAdGroup($customerId, $adGroupId));
    $lengthOfStayAdGroupBidModifier->setAdGroup($wrappedAdGroupResourceName);

    // Creates the hotel length of stay info.
    $lengthOfStayInfo = new HotelLengthOfStayInfo();
    $wrappedMinNights = new Int64Value();
    $wrappedMinNights->setValue(3);
    $lengthOfStayInfo->setMinNights($wrappedMinNights);
    $wrappedMaxNights = new Int64Value();
    $wrappedMaxNights->setValue(7);
    $lengthOfStayInfo->setMaxNights($wrappedMaxNights);
    $lengthOfStayAdGroupBidModifier->setHotelLengthOfStay($lengthOfStayInfo);

    // Sets the bid modifier value to 170%.
    $wrappedBidModifierValue = new DoubleValue();
    $wrappedBidModifierValue->setValue(1.7);
    $lengthOfStayAdGroupBidModifier->setBidModifier($wrappedBidModifierValue);

    // 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;
    }
}

As the code example shows, you need to first create an object of the relevant class (for example, HotelAdvanceBookingWindowInfo or HotelDateSelectionTypeInfo) and then set its fields to your desired values. For instance, if you want to create an ad group bid modifier using advanced booking window between 30 and 60 days, you need to create HotelAdvanceBookingWindowInfo object and set min_days to 30 and max_days to 60.

Finally, associate the relevant object to an AdGroupBidModifier object. You also have to specify the resource name of an ad group to which the ad group bid modifier belongs via ad_group.

Send feedback about...

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