Builder for
Price objects.
Example usage:
// Create a price builder.
var priceBuilder = AdsApp.extensions().newPriceBuilder();
// Create a price operation.
var priceOperation = priceBuilder
.withPriceType("BRANDS") // required
.withPriceQualifier("AVERAGE") // required
.withLanguage("en") // required
.addPriceItem(priceItem) // between 3-8 price items required
.build();
// Optional: examine the outcome. The call to isSuccessful()
// will block until the operation completes.
if (priceOperation.isSuccessful()) {
// Get the result.
var price = priceOperation.getResult();
} else {
// Handle the errors.
var errors = priceOperation.getErrors();
}
Methods:
addPriceItem(priceItem)
Adds a price item to the price. The minimum number of items allowed is 3 and the maximum number
is 8. Before calling
build()
the price should contain the right amount of price items.
Arguments:
Name | Type | Description |
priceItem |
AdsApp.PriceItem |
The price item to add to the price. |
Return values:
build()
Creates a
Price. Returns a
PriceOperation that can be used to get the new
price (or access any associated errors if creation failed).
Return values:
withEndDate(date)
Sets the price's end date from either an object containing year, month, and
day fields, or an 8-digit string in
YYYYMMDD
format. This field is optional.
For instance, priceBuilder.withEndDate("20130503");
is equivalent
to priceBuilder.withEndDate({year: 2013, month: 5, day: 3});
.
The change will fail and report an error if:
- the given date is invalid (e.g.,
{year: 2013, month: 5, day: 55}
),
- the start date now comes after the end date, or
- it's a date in the past
Arguments:
Name | Type | Description |
date |
Object |
The new price end date. |
Return values:
withLanguage(language)
Sets the language of the price. This field is required. Supported language codes are:
- de
- en
- es
- es-419
- fr
- it
- ja
- nl
- pl
- pt-BR
- pt-PT
- ru
- sv
Arguments:
Name | Type | Description |
language |
String |
The code for the language of the price. |
Return values:
withMobilePreferred(isMobilePreferred)
Sets the price's device preference to mobile or clears it. This field is
optional and defaults to
false
.
Arguments:
Name | Type | Description |
isMobilePreferred |
boolean |
Whether or not this price should be mobile
preferred. If true is passed in, device preference will be set to mobile. If false is passed in, device preference will be set to none. |
Return values:
withPriceQualifier(priceQualifier)
Sets the price qualifier of the price. This field is required and must be one of
['FROM', 'UP_TO', 'AVERAGE', 'NONE']
Arguments:
Name | Type | Description |
priceQualifier |
String |
The qualifier of the price. |
Return values:
withPriceType(priceType)
Sets the price type of the price. This field is required and must be one of
['BRANDS',
'EVENTS', 'LOCATIONS', 'NEIGHBORHOODS', 'PRODUCT_CATEGORIES', 'PRODUCT_TIERS', 'SERVICES',
'SERVICE_CATEGORIES', 'SERVICE_TIERS']
Arguments:
Name | Type | Description |
priceType |
String |
The type of the price. |
Return values:
withSchedules(schedules)
Sets the price scheduling. Scheduling of a price allows
you to control the days of week and times of day during which the price will
show alongside your ads.
Passing in an empty array clears the scheduling field, causing the price
to run at all times.
The following example sets the price to run on Mondays and Tuesday from
8:00 to 11:00.
var mondayMorning = {
dayOfWeek: "MONDAY",
startHour: 8,
startMinute: 0,
endHour: 11,
endMinute: 0
};
var tuesdayMorning = {
dayOfWeek: "TUESDAY",
startHour: 8,
startMinute: 0,
endHour: 11,
endMinute: 0
};
priceBuilder.withSchedules([mondayMorning, tuesdayMorning]);
Arguments:
Return values:
withStartDate(date)
Sets the price's start date from either an object containing year, month,
and day fields, or an 8-digit string in
YYYYMMDD
format. This field is optional.
For instance, priceBuilder.withStartDate("20130503");
is
equivalent to priceBuilder.withStartDate({year: 2013, month: 5, day:
3});
.
The change will fail and report an error if:
- the given date is invalid (e.g.,
{year: 2013, month: 5, day: 55}
),
- the given date is after the price's end date,
Arguments:
Name | Type | Description |
date |
Object |
The new price start date. |
Return values:
withTrackingTemplate(trackingTemplate)
Sets the tracking template of the price. To clear this field, set its value to an empty string.
Arguments:
Name | Type | Description |
trackingTemplate |
String |
The tracking template of the price. |
Return values: