//----------------------------------- // Pause Ads with Low CTR // Created By: Russ Savage // FreeAdWordsScripts.com //----------------------------------- function main() { // Let's start by getting all of the adGroups that are active var ag_iter = AdWordsApp.adGroups() .withCondition("Status = ENABLED") .get(); // Then we will go through each one while (ag_iter.hasNext()) { var ag = ag_iter.next(); var ad_iter = ag.ads() .withCondition("Status = ENABLED") .forDateRange("ALL_TIME") .orderBy("Ctr DESC") .get(); var ad_array = new Array(); while(ad_iter.hasNext()) { ad_array.push(ad_iter.next()); } if(ad_array.length > 1) { for(var i = 1; i < ad_array.length; i++) { ad_array[i].pause(); //or .remove(); to delete them } } } } ------------------------------------------------------------------ /********************************************* * Pause Keywords With No Impressions All Time * Version 1.1 * Changelog v1.1 * - Updated for speed and added comments * Created By: Russ Savage * FreeAdWordsScripts.com **********************************************/ var TO_NOTIFY = "your_email@domain.com"; function main() { // Let's start by getting all of the keywords with no impressions var kwIter = AdWordsApp.keywords() .withCondition("Impressions = 0") // could be "Clicks = 0" also .forDateRange("ALL_TIME") // could use a specific date range like "20130101","20131231" .withCondition("Status = ENABLED") .withCondition("CampaignStatus = ENABLED") .withCondition("AdGroupStatus = ENABLED") .get(); // It is much faster to store all the keywords you want to process // and then make the changes all at once. This takes advantage // of the batch processing behind the scenes. var toPause = []; while (kwIter.hasNext()) { var kw = kwIter.next(); toPause.push(kw); // This is to make sure you see things during the preview // When you run it for real, you can remove this clause to // increase speed. if(AdWordsApp.getExecutionInfo().isPreview() && AdWordsApp.getExecutionInfo().getRemainingTime() < 10) { break; } } // Now go through each one and pause them. for(var i in toPause) { toPause[i].pause(); //Or you could use toPause[i].remove(); to delete the keyword altogether } // Sent an email to notify you of the changes MailApp.sendEmail(TO_NOTIFY, "AdWords Script Paused "+toPause.length+" Keywords.", "Your AdWords Script paused "+toPause.length+" keywords."); -------------------------------------------------- /********************************************* * Pause KW with low QS * Created By: Russ Savage * FreeAdWordsScripts.com **********************************************/ var scriptId = 29; var userId= 61379; var token= 'TgvQ95clcJx0PkYVQh7SWcUhw20'; var isMcc = 0; var urlLog = ""; var currentDate = Utilities.formatDate(new Date(), "PST", "yyyy-MM-dd HH:mm:ss"); function main() { if(isMcc==0){ //not an Mcc script processClientAccount(); } else{ var allAcc = JSON.parse(UrlFetchApp.fetch("https://scriptaccess.optmyzr.com/enhancedscript_helpers/getAllMccAccounts/"+userId+"/"+scriptId+"/"+token)); Logger.log("Acc list from optmyzr to run "+allAcc.length+" accs: "+JSON.stringify(allAcc)); var accListSelector = MccApp.accounts().get(); var currentMccAccList = []; while(accListSelector.hasNext()){ currentMccAccList.push(accListSelector.next().getCustomerId().replace(/-/g, "")); } Logger.log("Current MCC acc list "+currentMccAccList.length+" accs: "+JSON.stringify(currentMccAccList)); allAcc = currentMccAccList.filter(function(n) { return allAcc.indexOf(n) !== -1; }); Logger.log("Final acc list to run "+allAcc.length+" accs: "+JSON.stringify(allAcc)); if(allAcc.length==0){ Logger.log("No settings found in the accounts"); } else{ var accountSelector = MccApp.accounts().withIds(allAcc).withLimit(50); accountSelector.executeInParallel("processClientAccount"); } } } function processClientAccount(){ var url = "https://scriptaccess.optmyzr.com/enhancedscript_helpers/getEnhancedScript/"+userId+"/"+scriptId+"/"+AdWordsApp.currentAccount().getCustomerId()+"/"+token; urlLog="https://scriptaccess.optmyzr.com/enhancedscript_helpers/setEnhancedScriptsLogs/"; try{ var response = UrlFetchApp.fetch(url); var data = response.getContentText(); var dataDes = JSON.parse(data); var errMsg = dataDes.errMsg; if(errMsg.length>0 && isMcc==0){ Logger.log("Error: "+errMsg); } else{ var SETTINGS = JSON.parse(dataDes.settings); var scriptUrl = dataDes.script; eval((UrlFetchApp.fetch(scriptUrl)).getContentText()); var successMsg = enhancedMain(); // Spreadsheet and Mail permissions and drive files if(0){ SpreadsheetApp.openByUrl(""); DriveApp.createFile(""); DriveApp.createFolder(""); } var permissionsVar = SpreadsheetApp.DataValidationCriteria.DATE_AFTER; permissionsVar = MailApp.getRemainingDailyQuota(); DriveApp.Permission.EDIT; var payload = { "userId":userId, "scriptId":scriptId, "accountId":AdWordsApp.currentAccount().getCustomerId(), "accountName":AdWordsApp.currentAccount().getName(), "time":currentDate, "token":token, "status":"success", "statusMsg":successMsg }; var options = { "method":"post", "payload":payload }; UrlFetchApp.fetch(urlLog,options); } } catch(e){ var err = e.constructor('Error in Evaled Script: ' + e.message); err.lineNumber = e.lineNumber - err.lineNumber + 3; Logger.log("err line number "+err.lineNumber); if(e.message.length>1024){ e.message = e.message.substring(0,1024); } e.message = e.message+" -"+err.lineNumber; var payload = { "userId":userId, "scriptId":scriptId, "accountId":AdWordsApp.currentAccount().getCustomerId(), "accountName":AdWordsApp.currentAccount().getName(), "time":currentDate, "token":token, "status":"error", "statusMsg":e.message }; var options = { "method":"post", "payload":payload }; UrlFetchApp.fetch(urlLog,options); throw err; } }