AdsApp.​Snippet

  • A snippet represents a part of a snippet extension in Google Ads.

  • Several methods are available to manage snippet properties like dates, headers, and values.

  • You can retrieve statistics for a snippet for predefined or custom date ranges.

  • Some methods for managing snippet dates, scheduling, and mobile preference are deprecated.

  • Snippet values and headers can be set programmatically.

Represents a snippet that can be part of a snippet extension. See About structured snippet extensions for more information.

Methods:

Member Type Description
void Clears the snippet's end date.
void Clears the snippet's start date.
AdsApp.GoogleAdsDate Returns the end date of the snippet, or null if no end date is set.
String Returns the type of this entity as a String , in this case, "Snippet" .
String Returns the header of the snippet.
String Returns the ID of the snippet.
String Returns the resource name of the snippet.
AdsApp.ExtensionSchedule[] Returns the scheduling of the snippet.
AdsApp.GoogleAdsDate Returns the start date of the snippet, or null if no start date is set.
AdsApp.Stats Returns stats for the specified date range.
AdsApp.Stats Returns stats for the specified custom date range.
String[] Returns the values of the snippet.
boolean Returns true if the snippet specifies mobile device preference.
void Sets the snippet's end date from either an object containing year, month, and day fields, or an 8-digit string in YYYYMMDD format.
void Sets the header of the snippet.
void Sets the snippet's device preference.
void Sets the snippet scheduling.
void Sets the snippet's start date from either an object containing year, month, and day fields, or an 8-digit string in YYYYMMDD format.
void Sets the values of the snippet.

clearEndDate()

Clears the snippet's end date.

Returns nothing.

clearStartDate()

Clears the snippet's start date.

Returns nothing.

getEndDate()

Returns the end date of the snippet, or null if no end date is set.

For instance, if the end date of the snippet is May 3, 2013, this would return the following object: {year: 2013, month: 5, day: 3} .

Return values:

Type Description
AdsApp.GoogleAdsDate The snippet's end date, or null if there's no end date.

getEntityType()

Returns the type of this entity as a String , in this case, "Snippet" .

Return values:

Type Description
String Type of this entity: "Snippet" .

getHeader()

Returns the header of the snippet.

Return values:

Type Description
String The header of the snippet.

getId()

Returns the ID of the snippet.

Return values:

Type Description
String The ID of the snippet.

getResourceName()

Returns the resource name of the snippet.

Return values:

Type Description
String The resource name of the snippet.

getSchedules()

Returns the scheduling of the snippet.

Return values:

Type Description
AdsApp.ExtensionSchedule[] The scheduling of the snippet.

getStartDate()

Returns the start date of the snippet, or null if no start date is set.

For instance, if the start date of the snippet is May 3, 2013, this would return the following object: {year: 2013, month: 5, day: 3} .

Return values:

Type Description
AdsApp.GoogleAdsDate The snippet's start date, or null if there's no start date.

getStatsFor(dateRange)

Returns stats for the specified date range. Supported values:

TODAY, YESTERDAY, LAST_7_DAYS, THIS_WEEK_SUN_TODAY, LAST_WEEK, LAST_14_DAYS, LAST_30_DAYS, LAST_BUSINESS_WEEK, LAST_WEEK_SUN_SAT, THIS_MONTH, LAST_MONTH, ALL_TIME .

Example:

 var 
  
 stats 
  
 = 
  
 snippet 
 . 
 getStatsFor 
 ( 
 "THIS_MONTH" 
 ); 

Arguments:

Name Type Description
dateRange
String Date range for which the stats are requested.

Return values:

Type Description
AdsApp.Stats The stats for the specified date range.

getStatsFor(dateFrom, dateTo)

Returns stats for the specified custom date range. Both parameters can be either an object containing year, month, and day fields, or an 8-digit string in YYYYMMDD form. For instance, March 24th, 2013 is represented as either {year: 2013, month: 3, day: 24} or "20130324" . The date range is inclusive on both ends, so forDateRange("20130324", "20130324") defines a range of a single day.

Arguments:

Name Type Description
dateFrom
Object Start date of the date range. Must be either a string in YYYYMMDD form, or an object with year , month and day properties.
dateTo
Object End date of the date range. Must be either a string in YYYYMMDD form, or an object with year , month and day properties.

Return values:

Type Description
AdsApp.Stats The stats for the specified date range.

getValues()

Returns the values of the snippet.

Return values:

Type Description
String[] The values of the snippet.

isMobilePreferred()

Returns true if the snippet specifies mobile device preference.

Return values:

Type Description
boolean true if the snippet specifies mobile device preference.

setEndDate(date)

Sets the snippet's end date from either an object containing year, month, and day fields, or an 8-digit string in YYYYMMDD format.

For instance, snippet.setEndDate("20130503"); is equivalent to snippet.setEndDate({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.

Returns nothing.

Arguments:

Name Type Description
date
Object The new snippet end date.

setHeader(header)

Sets the header of the snippet.

See the structured snippets header translations page for supported localized headers.

Returns nothing.

Arguments:

Name Type Description
header
String The header of the snippet.

setMobilePreferred(isMobilePreferred)

Sets the snippet's device preference.

Returns nothing.

Arguments:

Name Type Description
isMobilePreferred
boolean true sets the device preference to mobile. false clears the device preference.

setSchedules(schedules)

Sets the snippet scheduling. Scheduling of a snippet allows you to control the days of week and times of day during which the 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 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 
 }; 
 snippet 
 . 
 setSchedules 
 ([ 
 mondayMorning 
 , 
  
 tuesdayMorning 
 ]); 

Returns nothing.

Arguments:

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

setStartDate(date)

Sets the snippet's start date from either an object containing year, month, and day fields, or an 8-digit string in YYYYMMDD format.

For instance, snippet.setStartDate("20130503"); is equivalent to snippet.setStartDate({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.

Returns nothing.

Arguments:

Name Type Description
date
Object The new snippet start date.

setValues(values)

Sets the values of the snippet. At least three values, and at most ten values should be added.

Returns nothing.

Arguments:

Name Type Description
values
String[] The values of the snippet.
Create a Mobile Website
View Site in Mobile | Classic
Share by: