Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save siliconvallaeys/a42e247d7923a3181b0a9eb7332fdbad to your computer and use it in GitHub Desktop.
Save siliconvallaeys/a42e247d7923a3181b0a9eb7332fdbad to your computer and use it in GitHub Desktop.
/*
// AdWords Script: Check If Accounts Have Automatically Added Ads
// ---------------------------------------------------------------
// Copyright 2017 Optmyzr Inc., All Rights Reserved
//
// This MCC level AdWords Script reports which accounts have
// ads with the label "Added by AdWords", indicating that
// Google is automatically testing new ad variations.
// Users can then go to the impacted accounts and search for the
// label and decide whether or not to keep these new ads.
//
// For more PPC management tools, visit www.optmyzr.com
//
*/
var EMAIL = ""; // Update this with your email address if you wish to get an email notification if an account is using automatically added ads
function main() {
var accountSelector = MccApp.accounts()
.withLimit(50);
// Process the account in parallel. The callback method is optional.
accountSelector.executeInParallel("checkForAutomaticallyAddedAds");
}
function checkForAutomaticallyAddedAds() {
var adCount = 0;
var accountId = AdWordsApp.currentAccount().getCustomerId();
var labelIterator = AdWordsApp.labels().withCondition("Name CONTAINS_IGNORE_CASE 'Added by AdWords'").get();
if(labelIterator.hasNext()) {
var label = labelIterator.next();
var adIterator = label.ads().withCondition("Status = ENABLED").get();
while(adIterator.hasNext()) {
var ad = adIterator.next();
var campaignName = ad.getCampaign().getName();
var adGroupName = ad.getAdGroup().getName();
//Logger.log(campaignName + " - " + adGroupName);
adCount++;
}
}
if(adCount > 0) {
Logger.log("account with ID " + accountId + " has " + adCount + " active automatically added ads.");
if(EMAIL) MailApp.sendEmail(EMAIL, "Account " + accountId + " has automatic ads", "This account has " + adCount + " automatically added ads. Go to the account and use the Labels feature to find them.");
} else {
Logger.log("account with ID " + accountId + " has NO active automatically added ads.");
//if(EMAIL) MailApp.sendEmail(EMAIL, "All clear for account " + accountId, "This account is NOT using automatically added ads.");
}
}
@jafaircl
Copy link

jafaircl commented Jan 31, 2017

Thanks for this. You should be able to replace 34-42 with this as long as you're not logging campaign/ad group names:

var adCount = adIterator.totalNumEntities();

@richardscottclark
Copy link

Thanks!

@MicrowaveJak
Copy link

Just noticed that Google was actually using 'Added By AdWords' with a capital B for their label, so this label selector wouldn't be returning any of those. Can either update the label they're looking for or change

var labelIterator = AdWordsApp.labels().withCondition("Name = 'Added by AdWords'").get(); to var labelIterator = AdWordsApp.labels().withCondition("Name CONTAINS_IGNORE_CASE 'Added by AdWords'").get();

@nakitadog
Copy link

nakitadog commented Aug 17, 2018

I don't think this code will work anymore.

For starters, it's looking for a label with the name AdWords and that will at some point be changed to Google Ads.

Aside from that, there is a column within the AD_PERFORMANCE_REPORT named Automated.

Wouldn't this approach work more long-term?

function main() {
  var accountSelector = MccApp.accounts()
  .withLimit(2);  
  accountSelector.executeInParallel("processClientAccount");    
}

function processClientAccount() {  
  var accountName = AdWordsApp.currentAccount().getName();
  var accountId = AdWordsApp.currentAccount().getCustomerId();
  var report =  AdWordsApp.report(
    'SELECT CampaignName, Automated, Id ' +
    'FROM   AD_PERFORMANCE_REPORT ' +
    'WHERE  Automated = true ' +
    'AND CampaignStatus = ENABLED ' + 
    'AND AdGroupStatus = ENABLED ' + 
    'AND Status = ENABLED ' +
    'DURING LAST_7_DAYS');

    var rows = report.rows();
    var rowCount = 0;
    while (rows.hasNext()) {
      var row = rows.next();
      var campaignName = row['CampaignName'];
      var id = row['Id'];
      var automated = row['Automated'];
      rowCount++;
      Logger.log(accountName+" (" + accountId + ")" + " - campaignName = " + campaignName + " ID:" + id);
    }
  if (rowCount === 0){
    Logger.log(accountName+" (" + accountId + ")" + " - NO Automated ads within this account");    
  } else {
    Logger.log(accountName+" (" + accountId + ")" + " - YES there were " + rowCount + " Automated ads within this account");
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment