Cannot read property "impressions" in Account Anomaly Detector

275 views
Skip to first unread message

Johann Colombano

unread,
May 20, 2015, 7:36:30 AM5/20/15
to adwords...@googlegroups.com
Hi,

I'm getting the following error when I try to use this script https://developers.google.com/adwords/scripts/docs/solutions/account-anomaly-detector#adwordsapp either on single account level or on MCC level.
Any idea what causes it ? Thanks for your help !

TypeError: Cannot read property "impressions" from undefined.


Anthony Madrigal

unread,
May 20, 2015, 10:08:23 AM5/20/15
to adwords...@googlegroups.com
Hi,

Did you copy and paste the code exactly as it was in the document? The code should run fine even if there aren't any keywords that get selected. 

I can look into your code and see why it is causing that error. Could you please Reply privately to author your CID and the script name?

Thanks,
Anthony
AdWords Scripts Team

Johann Colombano

unread,
May 22, 2015, 8:42:31 AM5/22/15
to adwords...@googlegroups.com

Hi,

Yep, I did just that, copied it without modification (except for the urls of the google doc of course).
Sending you the info in private.

Thanks for your help
Johann.

Nicole Mennicke

unread,
May 26, 2015, 1:53:57 PM5/26/15
to adwords...@googlegroups.com
I am also seeing the same issue, with further review it appears the warning only happens after the script attempts to review and account with 0 impressions that day. Can you confirm that is happening to you and my assessment is correct? (in the log i see the last account it called, was also an account that had 0 impressions). I just posted a question about adding something to the script, like a "if 0, skip". 

If you find a solution can you share? 

Thanks

Nicole

Naman Jindal

unread,
May 26, 2015, 3:36:39 PM5/26/15
to adwords...@googlegroups.com

Yes, your observation is correct Nicole. The script breaks when there are no impressions.

You can solve the problem by including Zero Impression Rows:

Replace line 68.69:
var today = AdWordsApp.report(SheetUtil.getTodayQuery());
  var past = AdWordsApp.report(SheetUtil.getPastQuery());

With 

var options = { includeZeroImpressions: true }
  var today = AdWordsApp.report(SheetUtil.getTodayQuery(), options);
  var past = AdWordsApp.report(SheetUtil.getPastQuery(), options); 

Regards,
Naman Jindal

fb0

unread,
May 27, 2015, 6:57:27 AM5/27/15
to adwords...@googlegroups.com
Many thanks for posting that solution Naman, however I'm still getting the same error:
"TypeError: Cannot read property "impressions" from undefined. (line 104)", In my case it's caused by an old innactive account (with no ads running), is there a nice way to address this or will I need to manually unlink any old account from the master MCC?
Cheers

Imke

unread,
Jun 16, 2015, 5:36:47 AM6/16/15
to adwords...@googlegroups.com
Hi, I have the same problem. It´s also caused of inactive Account in my MCC. Any suggestions what I can do?
Thanks a lot!

Anthony Madrigal

unread,
Jun 16, 2015, 9:49:06 AM6/16/15
to adwords...@googlegroups.com
Hello,

Could you please Reply privately to author your CID and the script name you are working on?

drjwilson

unread,
Jun 23, 2015, 6:04:23 AM6/23/15
to adwords...@googlegroups.com
You may be able to resolve this by adding labels to your accounts 'Active' / 'Inactive' or whatever works for you and then use the config setting on line 5 to filter just the ad groups you have labelled (uncommenting this line if you haven't done so already).

Thomas Müller

unread,
Jul 2, 2015, 6:35:05 AM7/2/15
to adwords...@googlegroups.com
Hi everybody, mine is exactly the same problem and I changed the lines in the code as Naman Jindal told. Then the error still appears as like fb0 said.

@drjwilson: could you please post the code to your suggestion? I am not really into programming...

Is there any other way to handle this problem?
Message has been deleted

drjwilson

unread,
Jul 3, 2015, 4:50:31 AM7/3/15
to adwords...@googlegroups.com
Thomas, there is no real coding involved in my suggestion. 

Set labels for the accounts that are still active. Do this through regular adwords MCC interface. So select the accounts that are active, click label, and choose something memorable 'ActiveAccount' fro example, apply the change and you should see the labels.

Then in the code, do what it says, uncomment line 5 and add your label to the filter, so line 5 will go from this

  // ACCOUNT_LABEL: 'High Spend Accounts',


to this

  ACCOUNT_LABEL: 'ActiveAccount',

Xavier Serra

unread,
Dec 16, 2015, 9:34:05 AM12/16/15
to AdWords Scripts Forum
I've been facing the same problems.
My diagnose is that whenever impressions are zero the script brakes. And that is a big problem because that's what I want the report for, to detect problems with impressions (among others).
For instance, yesterday I tweaked an account. As a result, enhanced CPC brought max CPC to 0.01 killing impressions (still don't understand why enhanced CPC does that sometimes).
This morning the script was not sending any emails, so all is fine, right? Nope! the script was breaking because that account had (almost) 0 impressions. And the worst thing is that when it brakes, it doesn't process the remaining accounts.

Right now I'm checking the code (hate doing that). If I find the solution, I'll share it here.

Thanks,

Xavier

Xavier Serra

unread,
Dec 16, 2015, 9:34:05 AM12/16/15
to AdWords Scripts Forum
Look at the following piece of code...
Changing the bold rows solves the problem.
I did both changes at the same time, so haven't checked which one solves the problem. Whenever the debugging gets better, I'll be less lazy, sorry.

As you can see, in the original code, there is a case mismatch in the result json object, which would only fail when no results.
The default for the includeZeroImpressions is true, so Namal shouldn't expect that to solve the problem (at least in the current version)

Best, 
Xavier

function accumulateRows(rows, hours, weeks) {
 
var row;
 
var result;


 
while (rows.hasNext()) {
   
var row = rows.next();
   
var hour = row['HourOfDay'];


   
if (hour < hours) {
      result
= addRow(row, result, 1 / weeks);
   
}
 
}
 
if (!result) {
   
return {clicks:0,impressions:0,cost:0}

 
}


 
return result;
}


function addRow(row, previous, coefficient) {
 
if (!coefficient) {
    coefficient
= 1;
 
}
 
if (row == null) {
    row = {clicks: 0, impressions: 0, cost: 0};
 
}
 
if (!previous) {
   
return {
      clicks
: parseInt(row['Clicks']) * coefficient,
      impressions
: parseInt(row['Impressions']) * coefficient,
      cost
: toFloat(row['Cost']) * coefficient
   
};
 
} else {
   
return {
      clicks
: parseInt(row['Clicks']) * coefficient + previous.clicks,
      impressions
: parseInt(row['Impressions']) * coefficient +
          previous
.impressions,
      cost
: toFloat(row['Cost']) * coefficient + previous.cost
   
};
 
}




On Wednesday, May 20, 2015 at 1:36:30 PM UTC+2, Johann Colombano wrote:

Tyler Sidell (AdWords Scripts Team)

unread,
Dec 16, 2015, 2:02:26 PM12/16/15
to AdWords Scripts Forum
Hi Xavier,

Glad that you were able to find a solution to the issue.  I'll speak to the rest of the team to see if there are any improvements that can be made in order to catch zero impressions.

Thanks,
Tyler Sidell
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages