AdsApp.​PriceBuilder

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:

MemberTypeDescription
addPriceItem AdsApp.PriceBuilder Adds a price item to the price.
build AdsApp.PriceOperation Creates a Price.
withEndDate AdsApp.PriceBuilder Sets the price's end date from either an object containing year, month, and day fields, or an 8-digit string in YYYYMMDD format.
withLanguage AdsApp.PriceBuilder Sets the language of the price.
withMobilePreferred AdsApp.PriceBuilder Sets the price's device preference to mobile or clears it.
withPriceQualifier AdsApp.PriceBuilder Sets the price qualifier of the price.
withPriceType AdsApp.PriceBuilder Sets the price type of the price.
withSchedules AdsApp.PriceBuilder Sets the price scheduling.
withStartDate AdsApp.PriceBuilder Sets the price's start date from either an object containing year, month, and day fields, or an 8-digit string in YYYYMMDD format.
withTrackingTemplate AdsApp.PriceBuilder Sets the tracking template of the price.

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:

NameTypeDescription
priceItem AdsApp.PriceItem The price item to add to the price.

Return values:

TypeDescription
AdsApp.PriceBuilder A price builder with the price item added.

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:

TypeDescription
AdsApp.PriceOperation The associated price operation.

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:

NameTypeDescription
date Object The new price end date.

Return values:

TypeDescription
AdsApp.PriceBuilder A price builder with the specified end date.

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:

NameTypeDescription
language String The code for the language of the price.

Return values:

TypeDescription
AdsApp.PriceBuilder A price builder with the specified language.

withMobilePreferred(isMobilePreferred)

Sets the price's device preference to mobile or clears it. This field is optional and defaults to false.

Arguments:

NameTypeDescription
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:

TypeDescription
AdsApp.PriceBuilder A price builder with the specified mobile preference.

withPriceQualifier(priceQualifier)

Sets the price qualifier of the price. This field is required and must be one of ['FROM', 'UP_TO', 'AVERAGE', 'NONE']

Arguments:

NameTypeDescription
priceQualifier String The qualifier of the price.

Return values:

TypeDescription
AdsApp.PriceBuilder A price builder with the specified qualifier.

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:

NameTypeDescription
priceType String The type of the price.

Return values:

TypeDescription
AdsApp.PriceBuilder A price builder with the specified type.

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:

NameTypeDescription
schedules AdsApp.ExtensionSchedule[] The new price schedules.

Return values:

TypeDescription
AdsApp.PriceBuilder A price builder with the specified schedules.

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:

NameTypeDescription
date Object The new price start date.

Return values:

TypeDescription
AdsApp.PriceBuilder A price builder with the specified start date.

withTrackingTemplate(trackingTemplate)

Sets the tracking template of the price. To clear this field, set its value to an empty string.

Arguments:

NameTypeDescription
trackingTemplate String The tracking template of the price.

Return values:

TypeDescription
AdsApp.PriceBuilder A price builder with the specified tracking template.

Send feedback about...

Google Ads scripts
Google Ads scripts
Need help? Visit our support page.