Reg: Adwords Scripts for no impressions and payment failed method.

1,067 views
Skip to first unread message

Ravi Kanth

unread,
Aug 16, 2017, 4:49:21 AM8/16/17
to AdWords Scripts Forum
Hi team,

Could you please suggest on adwords script especially to automate below tasks

1)  Receiving an email alert when there is no impressions in last 24hours across the adwords account. ( I would like to apply script at MCC level. So that, all the accounts under MCC are reported.)
2)  Receiving an email alert when payment got failed. .

That will be a great help.

Thanks.

Anthony Madrigal

unread,
Aug 16, 2017, 9:25:17 AM8/16/17
to AdWords Scripts Forum
Hi Ravi,

Unfortunately, there is no way to get alerts based on payments via AdWords Scripts.

You can use our Account Anomaly Detector script to get alerts based on if your accounts are not meeting certain metrics.

Regards,
Anthony
AdWords Scripts Team

Ravi Kanth

unread,
Aug 16, 2017, 10:42:47 PM8/16/17
to AdWords Scripts Forum
Hi Anthony and team,

Thanks for your message.

Can you please suggest, on how to write adwords script for email notification when there is no impressions for any account for the last 24hours at MCC level.

Looking forward to hear from you.

Thanks.
Ravi

Anthony Madrigal

unread,
Aug 17, 2017, 10:00:27 AM8/17/17
to AdWords Scripts Forum
Hi Ravi,

If you don't want to set up the Account Anomaly Detector script to send you alerts when your impressions are low, you can set up a script as such:
function main() {  
 
var accounts = [];
 
var MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
 
var now = new Date();
 
var yesterday = new Date(now.getTime() - MILLIS_PER_DAY);
 
 
var accountIterator = MccApp.accounts().withLimit(50).get();
 
var mccAccount = AdWordsApp.currentAccount();

 
while (accountIterator.hasNext()) {
   
var account = accountIterator.next();
   
// Switch to the account you want to process.
   
MccApp.select(account);
   
var impressions = account.getStatsFor('YESTERDAY').getImpressions();
   
if(impressions == 0){
      accounts
.push(account.getCustomerId());
   
}  
 
}
 
 
if(accounts.length > 0)
   
MailApp.sendEmail('YOUR EMAIL', 'Accounts with no impressions on ' + yesterday, accounts);
}

Cheers,
Anthony
AdWords Scripts Team

Ravi Kanth

unread,
Aug 17, 2017, 5:20:25 PM8/17/17
to AdWords Scripts Forum
Hi Anthony,

Thanks for you script.

I am beginner to scripting.

I have few queries regarding script you shared with me.

1) Can you please suggest how this script executes.
2) In this script, where should I enter email address and also how can I enter list of email addresses to this script, So, that multiple people will be reported with zero impressions.
3) How should I test before being deployed on live MCC account.
4) Does this script makes any changes to live adwords acccount.

Thanks.
Ravi

Anthony Madrigal

unread,
Aug 18, 2017, 9:37:45 AM8/18/17
to AdWords Scripts Forum
Hi Ravi,

1) Can you please suggest how this script executes.
The script looks for accounts with no impressions. If there was at least one found, it will send you an email saying which ones.

2) In this script, where should I enter email address and also how can I enter list of email addresses to this script, So, that multiple people will be reported with zero impressions.
The area YOUR EMAIL is where you should set your email addresses. To include multiple ones, you can comma separate them as MailApp.sendEmail('ema...@example.com,ema...@example.com','Accounts with no impressions on ' + yesterday, accounts);

3) How should I test before being deployed on live MCC account.
There is a Preview option on the scripts interface so you can see how the script behaves.

4) Does this script makes any changes to live adwords acccount.
The script makes no changes to your account, only sends emails. It will send the email both when running and previewing.

I suggest going through our guides and watching the tutorial video to get a better understanding of AdWords Scripts.

Regards,
Anthony
AdWords Scripts Team

Ravi Kanth

unread,
Aug 21, 2017, 8:07:30 PM8/21/17
to AdWords Scripts Forum
Hi Anthony,

Thanks for your script.

I had added below script at MCC level.

and I did received email notification with list of client Id for all accounts with zero impression for yesterday.

Can you please suggest me, how can I add new line after each client id. So, that email can be more readable.

Thanks.
Ravi.

Thea Vega (AdWords Scripts Team)

unread,
Aug 21, 2017, 11:24:13 PM8/21/17
to AdWords Scripts Forum
Hi Ravi,

Below are the following changes you need to do on your script in order for you to achieve your requirements:

function main() {   
  
var accounts = [];
  
var MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
  
var now = new Date();
  
var yesterday = new Date(now.getTime() - MILLIS_PER_DAY);
  
  
var accountIterator = MccApp.accounts().withLimit(50).get(); 
  
var mccAccount = AdWordsApp.currentAccount();


  
while (accountIterator.hasNext()) {
    
var account = accountIterator.next();
    
// Switch to the account you want to process.
    
MccApp.select(account);
    
var impressions = account.getStatsFor('YESTERDAY').getImpressions();
    
if(impressions == 0){
      accounts.push(account.getCustomerId()+"\n"); // \n adds a new line
    
}  
  
} 
  var acts = accounts.join(''); //joins the array and removes the comma (,) delimiter
  
if(accounts.length > 0)
    
MailApp.sendEmail('YOUR EMAIL', 'Accounts with no impressions on ' + yesterday, acts);
}

Hope this helps!

Thanks,
Thea
AdWords Scripts Team

Ravi Kanth

unread,
Aug 23, 2017, 5:55:02 PM8/23/17
to AdWords Scripts Forum
Hi Thea and Anthony,

I have made little modification especially below code to make email more readable.

 if(impressions == 0){
      accounts
.push(account.getCustomerId()+" "+ "-" + " ")
      accounts
.push(account.getName()+"\n");  // \n adds a new line

Now it sends an email with client id and account name in below format
XXX-XXX-XXXX - CLIENT NAME
 
can you please suggest, how can add serial number(starting with 1 and goes on) for each account in the list.

Thanks.

Thea Vega (AdWords Scripts Team)

unread,
Aug 24, 2017, 12:00:28 AM8/24/17
to AdWords Scripts Forum
Hi Ravi,

Below are the changes you need to make in order to display your counter. 

function main() {  
 
var ctr= 0; //counter for accounts

 
var accounts = [];
 
var MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
 
var now = new Date();
 
var yesterday = new Date(now.getTime() - MILLIS_PER_DAY);
 
 
var accountIterator = MccApp.accounts().withLimit(50).get();
 
var mccAccount = AdWordsApp.currentAccount();

 
while (accountIterator.hasNext()) {
   
var account = accountIterator.next();
   
// Switch to the account you want to process.
   
MccApp.select(account);
   
var impressions = account.getStatsFor('YESTERDAY').getImpressions();
   
if(impressions == 0){

     
ctr++;
     
accounts.push(ctr+" "+account.getCustomerId()+" "+ "-" + " ")
      accounts
.push(account.getName()+"\n");  // \n adds a new line
   
}  
 
}
 
var acts = accounts.join(''); //joins the array and removes the comma (,) delimiter

 
if(accounts.length > 0)
   
MailApp.sendEmail('YOUR EMAIL', 'Accounts with no impressions on ' + yesterday, acts);
}

If you have any other questions, feel free to open up a new forum thread.

Ravi Kanth

unread,
Sep 1, 2017, 10:54:38 PM9/1/17
to AdWords Scripts Forum
Hi there,

I have been using this script in MCC for almost a week.

I notice few issues in using this script.

1) Is there any limit the number of accounts it can report for zero impressions.? (Mostly it is reporting few accounts and not all accounts)
2) I receive email alert with accounts for following statuses :"Campaigns Paused" and "Campaigns Ended".
    Especially, I don't want to report on accounts in which all campaigns are paused or ended manually.

3) Presently, we have certain number of accounts, but this script is not reporting on all accounts.

4) And also, I want to get client id with zero impressions for last day due "verify payment method", "updating billing info", "payment due", or for any other miscellaneous reason.

Thanks.

Thea Vega (AdWords Scripts Team)

unread,
Sep 4, 2017, 3:39:45 AM9/4/17
to AdWords Scripts Forum
Hi Ravi,

Below are the following answers to your inquiries.

1) Is there any limit the number of accounts it can report for zero impressions.? (Mostly it is reporting few accounts and not all accounts)
- For MCC scripts, 50 accounts can be processed. Each account that is handled by an MCC script do have different limits per iterator, selector, and script. Do read this for further information.
 
2) I receive email alert with accounts for following statuses :"Campaigns Paused" and "Campaigns Ended". Especially, I don't want to report on accounts in which all campaigns are paused or ended manually.
 Below is the updated version of your script. Do take note the emphasized parts of your current script as these are the changes made.

function main() {  
 
var ctr= 0; //counter for accounts
 
 
var accounts = [];
 
var MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
 
var now = new Date();
 
var yesterday = new Date(now.getTime() - MILLIS_PER_DAY);
 
 
var accountIterator = MccApp.accounts().withLimit(50).get();
 
var mccAccount = AdWordsApp.currentAccount();
 
 
while (accountIterator.hasNext()) {
   
var account = accountIterator.next();
   
// Switch to the account you want to process.
   
MccApp.select(account);

   
   
var campaignSelector = AdWordsApp
   
.campaigns().withCondition("Status=ENABLED");
   
   
var campaignIterator = campaignSelector.get();
   
// checks the number of enabled campaigns. If none, the next account will be processed.
   
if (campaignIterator.totalNumEntities()!=0){

     
var impressions = account.getStatsFor('YESTERDAY').getImpressions();
     
if(impressions == 0){
        ctr
++;
        accounts
.push(ctr+" "+account.getCustomerId()+" "+ "-" + " ")
        accounts
.push(account.getName()+"\n");  // \n adds a new line
     
}  
   
}
 
}
 
var acts = accounts.join(''); //joins the array and removes the comma (,) delimiter
 
 
if(accounts.length > 0)
   
MailApp.sendEmail('YOUR EMAIL', 'Accounts with no impressions on ' + yesterday, acts);
}
3) Presently, we have certain number of accounts, but this script is not reporting on all accounts.
- As what I answered above, an MCC script can process up to 50 accounts. If more than 50 accounts are iterated, either a warning will be logged, or the script will throw a runtime error. If you want more than 50 accounts to be processed, you could generate multiple versions of the script that each run a certain group of accounts at a time. 
 
4) And also, I want to get client id with zero impressions for last day due "verify payment method", "updating billing info", "payment due", or for any other miscellaneous reason.
- As per what my teammate said on his previous replies, there is no way to get alerts based on payments via AdWords Scripts.
 
Hope these help. If you have other concerns, feel free to open a new thread.

Ravi Kanth

unread,
Sep 10, 2017, 10:16:50 PM9/10/17
to AdWords Scripts Forum
Hi there,

Thanks for your reply,

For instance, if there are 269 adwords accounts in MCC.
As mentioned, MCC scripts can execute maximum of 50 Accounts at a time.

What changes I need to make for this script. So that, this particular script goes through all accounts (269 accounts) in 6 batches (each batch executes 50 accounts) in MCC .


Thanks.

Thea Vega (AdWords Scripts Team)

unread,
Sep 11, 2017, 2:22:36 AM9/11/17
to AdWords Scripts Forum
Hi Ravi,

You may create 6 separate scripts with the same script content and just change the .withIds after the account iterator as stated below.

  var accountIterator = MccApp.accounts().withLimit(50)
 
.withIds(['XXX-XXX-XXXX', 'XXX-XXX-XXXX', 'XXX-XXX-XXXX']) //insert 50 IDs here
 
.get();

Hope this helps. If you have other concerns, feel free to open up a new thread.

ANIL IQBAL

unread,
Aug 8, 2019, 11:06:43 PM8/8/19
to Google Ads Scripts Forum
Hey Anthony,

I was looking for almost the same script, however I would like to see which account has no impression for today instead of yesterday. Also, this scripts send an email with PDT time zone, can you edit this to EST, if possible? otherwise no need to show time/min/sec/date etc in the subject line of the email. If I can get an email that saying "X number of accounts with no impressions" in subject line works for me. 

Would you please modify this script? or let me know and I can open up the new thread if its convenient for you.

Thanks in advance.
Anil
Message has been deleted

Google Ads Scripts Forum Advisor Prod

unread,
Aug 9, 2019, 5:07:35 AM8/9/19
to adwords...@googlegroups.com
Hi Anil,

Thank you raising your concern. I am a colleague of Anthony and I will provide support to your concern.

For your proceeding concerns, I suggest to create a new thread in this forum so that our team can better track it.

But to get you started from modifying the script to meet your requirements, you need to update the value of getStatsFor() method from 'YESTERDAY' to 'TODAY' so that it will return today's data.

Moving forward, if timezone of your account is in on EST, you may try to implement the date/time specified on this guide so that the time that will be shown in your email is in EST format.

The script will be looked like this:
function main() {   
  var accounts = [];
  
  var now = new Date();  
  var timeZone = AdsApp.currentAccount().getTimeZone();
  var accountDefaultTime = Utilities.formatDate(now, timeZone, 'MMMM dd, yyyy HH:mm:ss Z');
  
  var accountIterator = MccApp.accounts().withLimit(50).get(); 
  Logger.log(accountIterator.totalNumEntities());

  while (accountIterator.hasNext()) {
    var account = accountIterator.next();
    
    // Switch to the account you want to process.
    MccApp.select(account);
    var impressions = account.getStatsFor('TODAY').getImpressions();
    if(impressions < 1){
      accounts.push(account.getCustomerId());
    }  
  } 
  if(accounts.length > 0)
    MailApp.sendEmail('EMAIL_ADDRESS_HERE', 'Accounts with no impressions on ' + accountDefaultTime, accounts);
}


Let me know if this help.

Regards,
Ejay
Google Ads Scripts Team

ref:_00D1U1174p._5001UEITWp:ref

posohov...@gmail.com

unread,
Nov 16, 2020, 7:18:47 AM11/16/20
to Google Ads Scripts Forum
Hello everyone,

Very useful script but I'd like to add a condition. I'd like to receive an email only if one of the selected accounts has impressions <1. If all of the selected MCC accounts have Impr > 0 I don't want to get an email. How can I do that? Say I have 5 MCC IDs and 4 of them have >0 impressions and 1 of them has 0 impressions. Is it possible to include text in the email only for the last account without any impressions?

Google Ads Scripts Forum Advisor

unread,
Nov 17, 2020, 3:13:08 AM11/17/20
to adwords...@googlegroups.com

Hi,

 

Thanks for reaching out. The MCC Account Selector only lets you retrieve metrics on client accounts. Thus, implementing your idea to check impressions on multiple MCC accounts is not possible on the Google Ads Scripts. If you would like, you can run the same script on each MCC account to check and get alerts on accounts without impressions in which your script would look like the following code:

 

var accountSelector = AdsManagerApp
    .accounts()
    .withCondition("Impressions < 1")
    .forDateRange("LAST_MONTH");
  
  var accountIterator = accountSelector.get();
  var emailBody = '';
  while (accountIterator.hasNext()) {
    var account = accountIterator.next();
    emailBody += account.getName() + '\n';
  }
  
  if(emailBody) {
    MailApp.sendEmail("reci...@example.com", "No Impressions on Accounts", emailBody);  
  }


 

Let me know if you have other questions.

 

Thanks,

Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


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