This script will send to you an alert each time a daily budget goes depleted in any campaign of your Google Adwords account. This is a very powerful tool, since it will allow you to act inmediately by increasing the daily budget and/or reducing your CPCs. To create this alert, follow these steps:
1. Go into your Google Adwords account, and then go to Campaigns > Bulk operations > Scripts > + Script
2. Copy and paste this code:
function main() {var text_email = "";
var campaignsIterator = AdWordsApp.campaigns().forDateRange("TODAY").get();
while (campaignsIterator.hasNext()) {
var campaign = campaignsIterator.next();
var stats = campaign.getStatsFor("TODAY");
var name = campaign.getName();
var cost = stats.getCost();
var budget = campaign.getBudget();
if (cost >= budget) {
var text_email = text_email+"<tr><td style='text-align:right;'>"+name+"</td>
<td style='font-weight:strong'>Gasto: "+cost+"</td></tr>";
}
}
var table = "<table>"+text_email+"</table>";
if (text_email!="") {
MailApp.sendEmail({
to: 'youremail@gmail.com',
subject: 'Depleted Budget Alert',
htmlBody: text_email,
})
Logger.log(text_email);
}
}
3. Program the script to be run each hour. When a daily budget goes depleted, an email will arrive to you with the subject "Depleted Budget Alert", with all the details of that campaign.
Me aparece \"Unterminated string literal. (línea 11)\"
¿Has modificado el código? ¿Me lo envías completo?
Hi, I had the same issue as Gabriel, and you have to remove the blank space thare is bewteen the ending and the opening
You need to put line 12 in the same line as 11. It will parse correctly then.
htmlBody should be set to the table variable inside the MailApp.sendEmail() function