Re: Email notification of current account balance is not working

22 views
Skip to first unread message
Message has been deleted

Dominique Rouillard

unread,
Jun 25, 2024, 4:48:55 AM (8 days ago) Jun 25
to Google Ads Scripts Forum
Hello,
Voici le script ajusté.


var CONFIG = {
  alertLimit: 500, // Limite d'alerte fixée à 500
  email: ['vasi...@gmail.com'],
  names: ['Nick', 'Nick2']
};

function main() {
  var accountName = AdWordsApp.currentAccount().getName();
  var customerId = AdWordsApp.currentAccount().getCustomerId();
 
  // Obtenir le solde actuel du compte
  var balance = getAccountBalance();

  var messageHeader = CONFIG.names.join(", ") + ' / Заканчивается бюджет на аккаунте: ' + accountName;
  var messageBody = 'Привет, ' + CONFIG.names.join(", ") + '!\n\n' +
      'Аккаунт ' + accountName + ' (' + customerId + '). Текущий остаток = ' + balance.toFixed(2) +
      ' USD.\n\n' +
      'В аккаунте заканчиваются средства. Необходимо предупредить PM.\n\n' +
      'С наилучшими пожеланиями,\nВаша система уведомлений';

  if (balance < CONFIG.alertLimit) {
    MailApp.sendEmail(CONFIG.email, messageHeader, messageBody);
    Logger.log('Alerte envoyée pour le compte: ' + accountName + ' avec un solde de: ' + balance.toFixed(2) + ' USD.');
  } else {
    Logger.log('Pas d\'alerte. Solde actuel: ' + balance.toFixed(2) + ' USD.');
  }
}

function getAccountBalance() {
  var stats = AdWordsApp.currentAccount().getStatsFor("ALL_TIME");
  var totalCost = stats.getCost();
  var budgetOrders = AdWordsApp.budgetOrders().get();
  var totalBudget = 0;

  while (budgetOrders.hasNext()) {
    var budgetOrder = budgetOrders.next();
    totalBudget += budgetOrder.getSpendingLimit();
  }

  var balance = totalBudget - totalCost;
  return balance;
}





Le lundi 24 juin 2024 à 10:50:48 UTC+2, Василий Александрович a écrit :
Hello, please help me with a problem.
The script for email notification of the current account balance does not work.
I need an email notification when the current account balance (not MCC) is less than 500. Can you please see what is wrong with the code?
  • Google Ads account     384-537-7276
  • Name of the affected script    Notification

Script Code:
var CONFIG = {
  days: 7,
  alertLimit: 30000,
  email: ['vasi...@gmail.com'],
  names: ['Nick', 'Nick2'],
  }
function main() {
  var accountName = AdWordsApp.currentAccount().getName();
  var budgetNow = AdWordsApp.budgetOrders().get();
  var messageHeader = CONFIG.names + ' / Заканчивается бюджет на аккаунте: ' + accountName;
  var messageBody = 'Аккаунт ' + accountName + ' . Текущий остаток = ' + budgetNow +
      'В аккаунте заканчиваются средства. Необходимо предупредить PM.';
  if (budgetNow < CONFIG.alertLimit) {
    MailApp.sendEmail(CONFIG.email, messageHeader, messageBody);
      Logger.log([accountName, budgetNow]);
    }
  }

Google Ads Scripts Forum Advisor

unread,
Jun 25, 2024, 7:25:25 AM (8 days ago) Jun 25
to adwords...@googlegroups.com

Hi,

Thank you for reaching out to the Google Ads Scripts support team.

I could see that you have already raised this concern on another thread with "Email notification does not work" and we have already responded there for this issue. To avoid multiple threads on the same issue, please take a look at that thread and continue the discussion on the same for further updates on the issue. 

This message is in relation to case "ref:!00D1U01174p.!5004Q02tJSfM:ref" (ADR-00243724)

Thanks,
 
Google Logo Google Ads Scripts Team


Dominique Rouillard

unread,
Jun 25, 2024, 12:04:22 PM (8 days ago) Jun 25
to Google Ads Scripts Forum
voir le script ajusté, merci 

var CONFIG = {
  alertLimit: 500, // Alert limit set to 500
  email: 'vasi...@gmail.com', // Correct email format

  names: ['Nick', 'Nick2']
};

function main() {
  var accountName = AdWordsApp.currentAccount().getName();
  var customerId = AdWordsApp.currentAccount().getCustomerId();
 
  // Get the current account balance
  var balance = getAccountBalance();

  var messageHeader = CONFIG.names.join(", ") + ' / Budget is running low on account: ' + accountName;
  var messageBody = 'Hello ' + CONFIG.names.join(", ") + ',\n\n' +
      'The account ' + accountName + ' (' + customerId + ') has a current balance of ' + balance.toFixed(2) +
      ' USD.\n\n' +
      'The account is running low on funds. Please notify the PM.\n\n' +
      'Best regards,\nYour notification system';


  if (balance < CONFIG.alertLimit) {
    MailApp.sendEmail(CONFIG.email, messageHeader, messageBody);
    Logger.log('Alert sent for account: ' + accountName + ' with a balance of: ' + balance.toFixed(2) + ' USD.');
  } else {
    Logger.log('No alert. Current balance: ' + balance.toFixed(2) + ' USD.');

  }
}

function getAccountBalance() {
  var stats = AdWordsApp.currentAccount().getStatsFor("ALL_TIME");
  var totalCost = stats.getCost();
  var budgetOrders = AdWordsApp.budgetOrders().get();
  var totalBudget = 0;

  while (budgetOrders.hasNext()) {
    var budgetOrder = budgetOrders.next();
    totalBudget += budgetOrder.getSpendingLimit();
  }

  var balance = totalBudget - totalCost;
  return balance;
}

Василий Александрович

unread,
Jun 28, 2024, 10:00:44 AM (5 days ago) Jun 28
to Google Ads Scripts Forum
Dominique Rouillard and Google Ads Scripts Forum Advisor, thanks a lot for your help :)

вторник, 25 июня 2024 г. в 19:04:22 UTC+3, Dominique Rouillard:
Reply all
Reply to author
Forward
0 new messages