AdWords
3.8K members online now
3.8K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

Run Script Quarterly

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I want the actions in my script to only be applied once per quarter.

Can anyone suggest something I might put in there such that if I set it to run once a month automatically via Adwords, the actions I want to happen (for example send an email) will only happen on the first day of the quarter?

1 Expert replyverified_user
Marked as Best Answer.
Solution
Accepted by topic author SEO A
December 2016

Re: Run Script Quarterly

[ Edited ]
Top Contributor
# 2
Top Contributor

Hi @SEO A the easiest way is probably to check the month number against an array and then only run if it matches one of the quarters you want to run.  For example:

 

function main() {
  var runMonths = [0,3,6,9];
  var d = new Date(Utilities.formatDate(new Date(), AdWordsApp.currentAccount().getTimeZone(), "MMM dd,yyyy HH:mm:ss"));
  var thisMonth = d.getMonth();
  if(runMonths.indexOf(thisMonth) != -1) {
    subProcess();
  }
else {
Logger.log("Not a run month.");
} } function subProcess() { //the main script to run }

Run this once a month and if the month matches one of the numbers in the runMonths array, main will call the subProcess and your script will run, if it doesn't main will just end and nothing will happen.  Note that the getMonth() method in AdWords scripts returns a month number starting with 0, so the year runs from 0 for January to 11 for December.


Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits