AdsApp.​PriceBuilder

  • PriceBuilder is used to create Price objects.

  • Creating a Price involves using the newPriceBuilder method and setting required fields like price type and language.

  • You must add between 3 and 8 price items using the addPriceItem method before building the Price object.

  • The build method returns a PriceOperation object to get the result or handle errors.

  • Optional methods allow setting details such as end date, mobile preference, price qualifier, schedules, start date, and tracking template, although some are deprecated.

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" 
 ) 
  
 // 
  
 optional 
  
 . 
 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:

Member Type Description
AdsApp.PriceBuilder Adds a price item to the price.
AdsApp.PriceOperation Creates a Price .
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.
AdsApp.PriceBuilder Sets the language of the price.
AdsApp.PriceBuilder Sets the price's device preference to mobile or clears it.
AdsApp.PriceBuilder Sets the price qualifier of the price.
AdsApp.PriceBuilder Sets the price type of the price.
AdsApp.PriceBuilder Sets the price scheduling.
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.
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:

Name Type Description
priceItem
AdsApp.PriceItem The price item to add to the price.

Return values:

Type Description
AdsApp.PriceBuilder A price builder with the price item added.

build(buildLegacy)

Creates a Price . Returns a PriceOperation that can be used to get the new price (or access any associated errors if creation failed).

Defaults to building the type of price that is currently serving. If there are upgraded prices, then an upgraded price will be built by default. If there are only legacy prices, then a legacy price will be built by default. If there are neither, then an upgraded price will be built by default.

Arguments:

Name Type Description
buildLegacy
boolean If true , builds a legacy price. If false , builds an upgraded price. If unspecified, defaults to building whichever type is currently serving.

Return values:

Type Description
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:

Name Type Description
date
Object The new price end date.

Return values:

Type Description
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:

Name Type Description
language
String The code for the language of the price.

Return values:

Type Description
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:

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:

Type Description
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']

Arguments:

Name Type Description
priceQualifier
String The qualifier of the price.

Return values:

Type Description
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:

Name Type Description
priceType
String The type of the price.

Return values:

Type Description
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:

Name Type Description
schedules
AdsApp.ExtensionSchedule[] The new price schedules.

Return values:

Type Description
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:

Name Type Description
date
Object The new price start date.

Return values:

Type Description
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:

Name Type Description
trackingTemplate
String The tracking template of the price.

Return values:

Type Description
AdsApp.PriceBuilder A price builder with the specified tracking template.
Design a Mobile Site
View Site in Mobile | Classic
Share by: