TypeError: account.keywords is not a function at main (Code:3:33)

53 views
Skip to first unread message

kyle williams

unread,
Jan 23, 2023, 2:14:43 AM1/23/23
to Google Ads Scripts Forum
This is the code snippet I'm trying to use but it is not working properly. 

function main() {
  var account = AdsApp.currentAccount();
  var keywordIterator = account.keywords().withCondition('Impressions = 0').forDateRange('LAST_7_DAYS').get();
  var keywords = [];
 
  while (keywordIterator.hasNext()) {
    var keyword = keywordIterator.next();
    keywords.push(keyword.getText());
  }
 
  if (keywords.length > 0) {
    var email = "user_email";
    var subject = "Keywords with no impressions in the past 7 days";
    var body = "The following keywords have had no impressions in the past 7 days in Google ad account - 'ad_account' " + keywords.join(', ');
    MailApp.sendEmail(email, subject, body);
  }

Google Ads Scripts Forum Advisor

unread,
Jan 23, 2023, 4:42:38 AM1/23/23
to adwords...@googlegroups.com

Hello Kyle,

James here, a member of the Google Ads Scripts Team. Allow me to assist you.

It is expecting a “not a function” error message because keyword is not a method of account object. Instead, only the following methods listed on this guide are  the supported method of account object. Instead, what you can do is to access the keyword method directly from the AdsApp object.

I have updated the given code snippet below, can you please try it on your end then let me know how it goes in your end?

function main() {
  var account = AdsApp.currentAccount();
  var keywordIterator = AdsApp.keywords().forDateRange('LAST_7_DAYS').get();
  
  var keywords = [];

  while (keywordIterator.hasNext()) {
    var keyword = keywordIterator.next();
    keywords.push(keyword.getText());
  }

  console.log(keywords)
 
  if (keywords.length > 0) {
    var email = "user_email";
    var subject = "Keywords with no impressions in the past 7 days";
    var body = "The following keywords have had no impressions in the past 7 days in Google ad account - 'ad_account' " + keywords.join(', ');
    
    MailApp.sendEmail(email, subject, body);
  }
}

Also, take note that filtering with zero metrics(such as zero impressions) is no longer possible within Ads scripts new experience version. You may refer here for more information.

Let me know if you have any questions.

Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


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