//array with campaign names for which the data is fetched
var campaignList = ['Campaign Name 1', 'Campaign Name 2'];
//declare all variables needed below
//this variable will hold the information that is then sent via email
var resultText = '',
campaignCnt = campaignList.length,
campaignName,
currAdGroup,
currAdsIter,
currAdsCount,
adGroupIter;
for(var i=0; i < campaignCnt; i++) {
campaignName = campaignList[i];
//get all active adgroups
adGroupIter = AdWordsApp.adGroups()
.withCondition('Status = ENABLED')
.withCondition('CampaignName = "' + campaignName + '"')
.orderBy('Name')
.get();
while(adGroupIter.hasNext()) {
currAdGroup = adGroupIter.next(),
currAdsCount = 0;
//get all enabled and approved ads in the current adgroup
currAdsIter = currAdGroup.ads()
.withCondition('Status = ENABLED')
.withCondition('ApprovalStatus = APPROVED')
.get();
//count the ads
//once we have reached 4 ads, remember the adGroup name and stop counting
while(currAdsIter.hasNext()) {
currAdsIter.next();
currAdsCount++;
if(currAdsCount >= 4) {
//remember the adgroup by appending it to the result string
resultText += 'Campaign "' + campaignName + '", AdGroup "' + currAdGroup.getName() + '"' + "\n";
//no need to count more
break;
}
}
}
//Logger.log(resultText);
}
MailApp.sendEmail(recipient, 'Adwords Script - Text Ads Quantified', resultText);
}