AdsApp.​CalloutBuilder

Builder for Callout objects.

Example usage:

// Create a callout builder.
var calloutBuilder = AdsApp.extensions().newCalloutBuilder();

// Create a callout operation.
var calloutOperation = calloutBuilder
  .withText("Free Shipping")                // required
  .withMobilePreferred(true)                // optional
  .build();

// Optional: examine the outcome. The call to isSuccessful()
// will block until the operation completes.
if (calloutOperation.isSuccessful()) {
  // Get the result.
  var callout = calloutOperation.getResult();
} else {
  // Handle the errors.
  var errors = calloutOperation.getErrors();
}

Methods:

MemberTypeDescription
build AdsApp.CalloutOperation Creates a Callout.
withEndDate AdsApp.CalloutBuilder Sets the callout's end date from either an object containing year, month, and day fields, or an 8-digit string in YYYYMMDD format.
withMobilePreferred AdsApp.CalloutBuilder Sets the callout's device preference to mobile or clears it.
withSchedules AdsApp.CalloutBuilder Sets the callout scheduling.
withStartDate AdsApp.CalloutBuilder Sets the callout's start date from either an object containing year, month, and day fields, or an 8-digit string in YYYYMMDD format.
withText AdsApp.CalloutBuilder Sets the text of the new callout to the specified value.

build(buildLegacy)

Creates a Callout. Returns a CalloutOperation that can be used to get the new callout (or access any associated errors if creation failed).

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

Arguments:

NameTypeDescription
buildLegacy boolean If true, builds a legacy callout. If false, builds an upgraded callout. If unspecified, defaults to building whichever type is currently serving.

Return values:

TypeDescription
AdsApp.CalloutOperation The associated callout operation.

withEndDate(date)

Sets the callout'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, calloutBuilder.withEndDate("20130503"); is equivalent to calloutBuilder.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 callout end date.

Return values:

TypeDescription
AdsApp.CalloutBuilder A callout builder with the specified end date.

withMobilePreferred(isMobilePreferred)

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

Arguments:

NameTypeDescription
isMobilePreferred boolean Whether or not this callout 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.CalloutBuilder A callout builder with the specified mobile preference.

withSchedules(schedules)

Sets the callout scheduling. Scheduling of a callout allows you to control the days of week and times of day during which the callout will show alongside your ads.

Passing in an empty array clears the scheduling field, causing the callout to run at all times.

The following example sets the callout 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
 };

calloutBuilder.withSchedules([mondayMorning, tuesdayMorning]);

Arguments:

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

Return values:

TypeDescription
AdsApp.CalloutBuilder A callout builder with the specified schedules.

withStartDate(date)

Sets the callout'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, calloutBuilder.withStartDate("20130503"); is equivalent to calloutBuilder.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 callout's end date,

Arguments:

NameTypeDescription
date Object The new callout start date.

Return values:

TypeDescription
AdsApp.CalloutBuilder A callout builder with the specified start date.

withText(text)

Sets the text of the new callout to the specified value. This field is required.

Arguments:

NameTypeDescription
text String The text.

Return values:

TypeDescription
AdsApp.CalloutBuilder Callout builder with the specified text.