Parsing Error in Script for Impression Drop

66 views
Skip to first unread message

tabitha hernandez

unread,
Jul 16, 2019, 4:55:42 PM7/16/19
to Google Ads Scripts Forum
Hello, 
I am attempting to run an MCC level script that monitors the Impression level and will generate an alert email if any Account Impressions drop below the set threshold however, I am receiving 
7/16/2019 3:46:37 PMParsing error. Please check your selector. (file Code.gs, line 78)
I have checked parenthesis and capitalization but nothing seems to help. Please take a moment to see the script below and let me know if you have any suggestions.
Thanks!
function main() {
  
  var dateRange =  getDateRangeYesterdayToToday();
  var currentDate = new Date();
  
  var accountIterator = MccApp.accounts().get();

while ( accountIterator.hasNext() )  {
    var account = accountIterator.next();
    MccApp.select(account);


  var queryText = 'SELECT ' + METRIC_TO_CHECK + 'FROM ACCOUNT_PERFORMANCE_REPORT DURING ' + dateRange;
  var result = AdWordsApp.report(queryText);
  var rows = result.rows();
  
  var daysMapping = [];
  daysMapping["Sunday"] = 0;
  daysMapping["Monday"] = 1;
  daysMapping["Tuesday"] = 2;
  daysMapping["Wednesday"] = 3;
  daysMapping["Thursday"] = 4;
  daysMapping["Friday"] = 5;
  daysMapping["Saturday"] = 6;

  var impressionsByHour = {};
  
  while(rows.hasNext()) {
    var currentRow = rows.next();
    var dayFactor = daysMapping[currentRow["DayOfWeek"]];
    var hourFactor = parseFloat(currentRow["HourOfDay"]);
    var actualHour = dayFactor * 24 + hourFactor;
    if(DEBUG) Logger.log(dayFactor +","+ hourFactor + " => " + currentRow["Impressions"]);
    impressionsByHour[actualHour] = currentRow["Impressions"];                            
  }
   
  // check if an entry exists for any of the last 6 hours
  var foundEntry = false;
  var numHoursToCheck = NUM_HOURS_TO_CHECK + 1;
  for(var i=1;i<numHoursToCheck;i++){
    var tempDate = new Date(currentDate.getTime());
    tempDate.setHours(tempDate.getHours() - i);
    var hourIndexToCheck = tempDate.getDay() * 24 + tempDate.getHours();
    if(impressionsByHour[hourIndexToCheck] != undefined && impressionsByHour[hourIndexToCheck] != 0){
      foundEntry = true;
      break;      
    }
  }
  
  if(foundEntry){
    Logger.log("ALL OK! The Account seems to be active in the last " + NUM_HOURS_TO_CHECK + " hours."); 
  }
  else {
    var subject = "AdWords Account getting no impressions"; 
    var body = "AdWords Account " + AdWordsApp.currentAccount().getName() + " ("  + AdWordsApp.currentAccount().getCustomerId() + ")  seems to be getting no impressions in the last 6 hours. You may want to check this out. This email was generated by an AdWords Script from Optmyzr.com.";
    sendEmailNotifications(EMAIL_ADDRESS_TO_NOTIFY, subject, body, "warning");
    Logger.log("WARNING: The Account seems to be inactive in the last " + NUM_HOURS_TO_CHECK + " hours.");
  }
    
}}

Google Ads Scripts Forum Advisor Prod

unread,
Jul 16, 2019, 5:10:10 PM7/16/19
to adwords-scripts+apn2wqev0_xdyc16...@googlegroups.com, adwords-scripts+apn2wqev0_xdyc16...@googlegroups.co, adwords...@googlegroups.com
Hi Tabitha,

Can you please point me to line 78 in the script you copied below? I copied what you pasted below into my editor, but it only contains 60 lines. Please provide the line of interest.

Regards,
Matt
Google Ads Scripts Team

ref:_00D1U1174p._5001U8LobL:ref

tabitha hernandez

unread,
Jul 17, 2019, 10:46:48 AM7/17/19
to Google Ads Scripts Forum
Hi Matt,

Thank you for helping with this line 78 is: 

var result = AdWordsApp.report(queryText);

This is roughly the third section. Please let me know if you are able to locate.

Thanks again,
Tabitha

Google Ads Scripts Forum Advisor Prod

unread,
Jul 17, 2019, 1:53:00 PM7/17/19
to adwords-scripts+apn2wqev0_xdyc16...@googlegroups.com, adwords-scripts+apn2wqev0_xdyc16...@googlegroups.co, adwords...@googlegroups.com
Hi Tabitha,

The variable, METRIC_TO_CHECK, is not defined in the script you provided, so I am not able to troubleshoot the issue. Can you please provide the full script? If preferred, you can reply privately.

tabitha hernandez

unread,
Jul 17, 2019, 4:02:21 PM7/17/19
to Google Ads Scripts Forum
Matt,

That was it! I needed to insert 'Impressions' in that space! Thank you for your help!
Reply all
Reply to author
Forward
0 new messages