2 Similar Scripts, But 1 Script is Always Time Out

21 views
Skip to first unread message

Hangga Nuarta

unread,
Aug 14, 2019, 3:44:32 AM8/14/19
to Google Ads Scripts Forum
Hi All,

Kindly need your help. I've copied a script from the internet, and make a modification from that. But when 1 run the scripts, 1 script always time out while the other one always run successfully, even though both scripts are similar and the one running successfully has more variable to export.

Time out script:

function main() {
  // Only CONTAINS and DOES_NOT_CONTAIN operators are supported.
  var accountIterator = AdsManagerApp.accounts()
      .withCondition("LabelNames CONTAINS 'Controlled by Script - SEM VP'")
      .get();
  
  var MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
  var now = new Date();
  var from = new Date(now.getTime() - 31 * MILLIS_PER_DAY);
  var to = new Date(now.getTime() - 1 * MILLIS_PER_DAY);
  var timeZone = AdsApp.currentAccount().getTimeZone();

  // Name of the specific sheet in the spreadsheet.
  var SHEET_NAME = 'Raw - SEM VP';
  var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var sheet = ss.getSheetByName(SHEET_NAME);
  sheet.clearContents();
  sheet.appendRow(['Date', 'Campaign Name', 'Cost']);

  while (accountIterator.hasNext()) {
    var account = accountIterator.next();
    var accountName = account.getName() ? account.getName() : '--';
    Logger.log('%s',accountName);
    
    MccApp.select(account);
    
    var report = AdsApp.report(
    "SELECT Date, CampaignName, Cost " +
    "FROM   CAMPAIGN_PERFORMANCE_REPORT " +
    "WHERE Cost > 0 " +
    "DURING " + Utilities.formatDate(from, timeZone, 'yyyyMMdd') + ','
              + Utilities.formatDate(to, timeZone, 'yyyyMMdd'));
    
    //report.exportToSheet(sheet);
    //Logger.log('%s %s',Utilities.formatDate(from, timeZone, 'yyyyMMdd'),Utilities.formatDate(to, timeZone, 'yyyyMMdd'));
    var rowsIterator = report.rows();
    while (rowsIterator.hasNext()) {
      var row = rowsIterator.next();
      var dt = row['Date'];
      var cnm = row['CampaignName'];
      var cs = row['Cost'];
      //Logger.log('%s %s %s',dt,cnm,cs);
      sheet.appendRow([dt, cnm, cs]);
    }
    
  }
      
}


Successful script:

function main() {
  // Only CONTAINS and DOES_NOT_CONTAIN operators are supported.
  var accountIterator = AdsManagerApp.accounts()
      .withCondition("LabelNames CONTAINS 'Controlled by Script - SEM VP'")
      .get();
  
  var MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
  var now = new Date();
  var from = new Date(now.getTime() - 46 * MILLIS_PER_DAY);
  var to = new Date(now.getTime() - 1 * MILLIS_PER_DAY);
  var timeZone = AdsApp.currentAccount().getTimeZone();

  // Name of the specific sheet in the spreadsheet.
  var SHEET_NAME = 'Raw SEM VP';
  var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var sheet = ss.getSheetByName(SHEET_NAME);
  sheet.clearContents();
  sheet.appendRow(['Date', 'Account Name', 'CampaignName', 'Cost', 'Channel Type', 'Conversion Value', 'Conversions']);

  while (accountIterator.hasNext()) {
    var account = accountIterator.next();
    var accountName = account.getName() ? account.getName() : '--';
    Logger.log('%s',accountName);
    
    MccApp.select(account);
    
    var report = AdsApp.report(
    "SELECT Date, AccountDescriptiveName, CampaignName, Cost, ConversionValue, Conversions " +
    "FROM   CAMPAIGN_PERFORMANCE_REPORT " +
    "WHERE Cost > 0 " +
    "DURING " + Utilities.formatDate(from, timeZone, 'yyyyMMdd') + ','
              + Utilities.formatDate(to, timeZone, 'yyyyMMdd'));
    
    //report.exportToSheet(sheet);
    //Logger.log('%s %s',Utilities.formatDate(from, timeZone, 'yyyyMMdd'),Utilities.formatDate(to, timeZone, 'yyyyMMdd'));
    var rowsIterator = report.rows();
    while (rowsIterator.hasNext()) {
      var row = rowsIterator.next();
      var dt = row['Date'];
      var anm = row['AccountDescriptiveName'];
      var cnm = row['CampaignName'];
      var cs = row['Cost'];
      var ct = row['CampaignName'].substring(0, 12);
      var cv = row['ConversionValue'];
      var co = row['Conversions'];
      //Logger.log('%s %s %s %s %s',dt,anm,cnm,cs,ct,cv,co);
      sheet.appendRow([dt, anm, cnm, cs, ct, cv, co]);
    }
    
  }
      
}


Thank you in advance!

Google Ads Scripts Forum Advisor Prod

unread,
Aug 14, 2019, 6:12:19 AM8/14/19
to adwords...@googlegroups.com
Hi,

Thanks for raising your concern.

To further investigate the issue, would you mind providing the customer ID and the name of the script where you've implemented the 2 scripts via Reply privately to author option? Also, please provide access to the Google spreadsheets that these scripts are using so I can inspect it as well.

Regards,
Ejay
Google Ads Scripts Team

ref:_00D1U1174p._5001UEJ0Ts:ref
Reply all
Reply to author
Forward
0 new messages