Builder for
Snippet objects.
Example usage:
//Createasnippetbuilder.varsnippetBuilder=AdsApp.extensions().newSnippetBuilder();//Createasnippetoperation.varsnippetOperation=snippetBuilder.withHeader("Business")//required.withValues(["foo","bar","baz"])//required.build();//Optional:examinetheoutcome.ThecalltoisSuccessful()//willblockuntiltheoperationcompletes.if(snippetOperation.isSuccessful()){//Gettheresult.varsnippet=snippetOperation.getResult();}else{//Handletheerrors.varerrors=snippetOperation.getErrors();}
Methods:
build(buildLegacy)
Creates a
Snippet.Returns a
SnippetOperationthat can be used to get the new snippet (or access anyassociated errors if creation failed).
Defaults to building the type of snippet that is currentlyserving. If there are upgraded snippets, then an upgradedsnippet will be built by default. If there are only legacysnippets, then a legacy snippet will be builtby default. If there are neither, then an upgraded snippet willbe built by default.
Arguments:
Name | Type | Description |
---|
buildLegacy | boolean | Iftrue , builds a legacy snippet. Iffalse , builds an upgraded snippet. If unspecified, defaults to building whichever type is currently serving. |
Return values:
withEndDate(date)
Sets the snippet's end date from either an object containingyear, month, and day fields, or an 8-digit string in
YYYYMMDD
format. This field is optional.
For instance,snippetBuilder.withEndDate("20130503");
is equivalent tosnippetBuilder.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
Deprecated.Arguments:
Name | Type | Description |
---|
date | Object | The new snippet end date. |
Return values:
withHeader(header)
Sets the header of the snippet. This field is required.
See thestructuredsnippets header translations page for supported localized headers.
Arguments:
Name | Type | Description |
---|
header | String | The header of the snippet. |
Return values:
withMobilePreferred(isMobilePreferred)
Sets the snippet's device preference to mobile or clears it.This field is optional and defaults to
false
.
Deprecated.Arguments:
Name | Type | Description |
---|
isMobilePreferred | boolean | Whether or not this snippet should be mobile preferred. Iftrue is passed in, device preference will be set to mobile. Iffalse is passed in, device preference will be set to none. |
Return values:
withSchedules(schedules)
Sets the snippet scheduling. Scheduling of a snippet allows you to control the days of week and times of day during whichthe snippet will show alongside your ads.
Passing in an empty array clears the scheduling field, causing the snippet to run at all times.
The following example sets the snippet to run on Mondays andTuesday from 8:00 to 11:00.
varmondayMorning={dayOfWeek:"MONDAY",startHour:8,startMinute:0,endHour:11,endMinute:0};vartuesdayMorning={dayOfWeek:"TUESDAY",startHour:8,startMinute:0,endHour:11,endMinute:0};snippetBuilder.withSchedules([mondayMorning,tuesdayMorning]);
Deprecated.Arguments:
Return values:
withStartDate(date)
Sets the snippet's start date from either an object containingyear, month, and day fields, or an 8-digit string in
YYYYMMDD
format. This field is optional.
For instance,snippetBuilder.withStartDate("20130503");
is equivalent tosnippetBuilder.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 snippet's end date,
Deprecated.Arguments:
Name | Type | Description |
---|
date | Object | The new snippet start date. |
Return values:
withValues(values)
Sets the values of the snippet. At least three values, and at most tenvalues should be added. This field is required.
Arguments:
Name | Type | Description |
---|
values | String[] | The values of the snippet. |
Return values: