Ad Schedules

  • Ad schedules can be added to a campaign using the addAdSchedule method, either with individual parameters or as a JSON object.

  • The bid modifier for an ad schedule is optional.

  • Existing ad schedules for a campaign can be retrieved using the targeting().adSchedules().get() method.

  • The retrieved ad schedule information can be formatted for display.

Add ad schedules for a campaign

 function 
  
 addAdSchedule 
 ( 
 campaignName 
 ) 
  
 { 
  
 const 
  
 campaignIterator 
  
 = 
  
 AdsApp 
 . 
 campaigns 
 () 
  
 . 
 withCondition 
 ( 
 ` 
 campaign 
 . 
 name 
  
 = 
  
 "${campaignName}" 
 ` 
 ) 
  
 . 
 get 
 (); 
  
 if 
  
 ( 
 campaignIterator 
 . 
 hasNext 
 ()) 
  
 { 
  
 const 
  
 campaign 
  
 = 
  
 campaignIterator 
 . 
 next 
 (); 
  
 // 
  
 Add 
  
 a 
  
 schedule 
  
 for 
  
 Monday 
 , 
  
 9 
 AM 
  
 to 
  
 5 
 PM 
 , 
  
 bid 
  
 modifier 
  
 = 
  
 1.25 
 . 
  
 campaign 
 . 
 addAdSchedule 
 ( 
 'MONDAY' 
 , 
  
 9 
 , 
  
 0 
 , 
  
 17 
 , 
  
 0 
 , 
  
 1.25 
 ); 
  
 // 
  
 The 
  
 bid 
  
 modifier 
  
 is 
  
 optional 
 , 
  
 e 
 . 
 g 
 . 
  
 // 
  
 campaign 
 . 
 addAdSchedule 
 ( 
 'MONDAY' 
 , 
  
 9 
 , 
  
 0 
 , 
  
 17 
 , 
  
 0 
 ); 
  
 // 
  
 You 
  
 can 
  
 also 
  
 add 
  
 an 
  
 adSchedule 
  
 as 
  
 a 
  
 JSON 
  
 object 
 , 
  
 or 
  
 using 
  
 // 
  
 an 
  
 existing 
  
 AdSchedule 
  
 object 
 . 
  
 // 
  
 Add 
  
 a 
  
 schedule 
  
 for 
  
 Saturday 
 , 
  
 7 
 AM 
  
 to 
  
 11 
 AM 
 , 
  
 bid 
  
 modifier 
  
 = 
  
 1.1 
 . 
  
 campaign 
 . 
 addAdSchedule 
 ({ 
  
 dayOfWeek 
 : 
  
 'SATURDAY' 
 , 
  
 startHour 
 : 
  
 7 
 , 
  
 startMinute 
 : 
  
 0 
 , 
  
 endHour 
 : 
  
 11 
 , 
  
 endMinute 
 : 
  
 0 
 , 
  
 bidModifier 
 : 
  
 1.1 
  
 }); 
  
 } 
 } 

Get ad schedules for a campaign

 function 
 getAdSchedules 
( campaignName 
) { const 
 campaignIterator 
= AdsApp 
. campaigns 
()
      . withCondition 
(` campaign 
. name 
= "${campaignName}" 
`)
      . get 
(); if 
(! campaignIterator 
. hasNext 
()) { throw 
 new 
 Error 
(` No 
 campaign 
 with 
 name 
${ campaignName 
} found 
.`);
  } const 
 campaign 
= campaignIterator 
. next 
(); const 
 adScheduleIterator 
= campaign 
. targeting 
(). adSchedules 
(). get 
(); console 
. log 
(` Campaign 
 "${campaign.name}" 
 has 
${ adScheduleIterator 
. totalNumEntities 
()} ad 
 schedules 
`); return 
 adScheduleIterator 
;
} function 
 formatSchedule 
( schedule 
) { function 
 zeroPad 
( number 
) { return 
 Utilities 
. formatString 
( '%02d' 
, number 
); } return 
 schedule 
. getDayOfWeek 
() + ', ' 
+ schedule 
. getStartHour 
() + ':' 
+ zeroPad 
( schedule 
. getStartMinute 
()) + ' to ' 
+ schedule 
. getEndHour 
() + ':' 
+ zeroPad 
( schedule 
. getEndMinute 
());
}
Design a Mobile Site
View Site in Mobile | Classic
Share by: