Automate

RSS   Contact

MIT licensed

Automate your advertising with scripts

Automate helps you scale your digital advertising with Google and Facebook Ads scripts. Code snippets were created to optimize real-world campaigns, powered by real results. Below is a collection of scripts ready for deployment. Adjust the code for your specific campaigns and you're good to go!

















Bidding

Penny Under Script

Use this Google Ads script to lower Search campaign keyword bids by $0.01 less than their last 30-day avg. CPC. Credit to Jason Ibarra for inventing this simple yet effective Google Ads optimization technique.

decBidBy:
Decrease bid by $0.01
minReqClicks:
Minimum clicks
maxAvgPos:
Minimum Avg. Pos
minAvgCpc:
Minimum Avg. CPC
minCpcBid:
Minimum currently set CPC
timePeriod:
Time period
function main() {
  var decBidBy        = '0.01';
  var minReqClicks    = '10';
  var maxAvgPos       = '3.5';
  var minAvgCpc       = '0.30';
  var minCpcBid       = '0.30';
  var timePeriod      = 'LAST_30_DAYS';
  var searchCampaigns  = Google AdsApp.report("SELECT CampaignName FROM CAMPAIGN_PERFORMANCE_REPORT WHERE AdvertisingChannelType='SEARCH' AND CampaignName DOES_NOT_CONTAIN 'Brand'").rows();
  while(searchCampaigns.hasNext()){
    var searchCampaign = searchCampaigns.next(); 
    var keywordsIterator = Google AdsApp.keywords().withCondition('CampaignName="'+searchCampaign['CampaignName']+'"').withCondition('Clicks>='+minReqClicks).withCondition('AveragePosition<'+maxAvgPos).withCondition('AverageCpc>'+minAvgCpc).forDateRange(timePeriod).get();
    while(keywordsIterator.hasNext()){
      var keyword = keywordsIterator.next();
      if(keyword.bidding().getStrategyType() == 'MANUAL_CPC' && keyword.bidding().getCpc()>minCpcBid){
        var avgCPC = keyword.getStatsFor(timePeriod).getAverageCpc();
        var newCPC = (avgCPC-decBidBy)*100/100;
        keyword.bidding().setCpc(newCPC);
        Logger.log('Keyword: '+keyword.getText()+', OldCPC: '+keyword.bidding().getCpc()+', NewCPC: '+newCPC+', AvgCPC: '+keyword.getStatsFor(timePeriod).getAverageCpc());
      }
    }
  }
}


// Coming soon. Subscribe to our email list to get latest updates.

Reports

Spammy Placements Report

Pull unusual and spammy Display campaign placements into a Google Sheet where you can quickly add to a negative placement list. Replicate Google Sheet template here.

sheetUrl:
Replace 'URL' with your Google Sheet URL
function main() {
  var sheetUrl  = 'URL';
  var sheet     = SpreadsheetApp.openByUrl(sheetUrl);
  var getSheet  = sheet.getActiveSheet();
  var DisplayCampaigns = Google AdsApp.report("SELECT CampaignId,CampaignName FROM CAMPAIGN_PERFORMANCE_REPORT WHERE AdvertisingChannelType='DISPLAY' DURING LAST_30_DAYS").rows();
  while(DisplayCampaigns.hasNext()){
    var DisplayCampaign = DisplayCampaigns.next();
    var placements = Google AdsApp.report("SELECT Criteria,Clicks,Ctr,Impressions FROM PLACEMENT_PERFORMANCE_REPORT WHERE CampaignId='"+DisplayCampaign['CampaignId']+"' AND Clicks>=10 AND Ctr>'0.25' DURING_LAST_30_DAYS").rows();
    while(placements.hasNext()){
      var placement = placements.next();
      getSheet.appendRow([placement['Criteria'],placement['Impressions'],placement['Clicks'],placement['Ctr'],DisplayCampaign['CampaignName']]);
    }
  }
}
// Coming soon. Subscribe to our email list to get latest updates.



Budgets

Steady Monthly Budget Increase

Increase your campaign budgets gradually over the month, resetting back to a set percentage throttle on the first of each month.

scampaignName
Campaign names
maxBudgetLimit
Maximum monthly campaign budget
numDays
Day of month to increase budget to 100% throttle
function main() {
  var campaignName    = "Name IN ['CAMPAIGN_NAME_1','CAMPAIGN_NAME_2']";
  var maxBudgetLimit  = 3000; // Maximum campaign budget
  var numDays         = 25; // Day of month to increase budget to 100% throttle
  var dateToday       = new Date();
  function GetBudgetForTheDay(Date,Amount){
    var SumDays = (numDays/2)*numDays;
    var Budget  = Date*Amount/SumDays;
    Budget      = Math.round(Budget*100)/100;
    Logger.log('Budget increment for day'+Date+' is :'+Budget);
    return Budget;
  }
  var CampaignIterator = Google AdsApp.campaigns().withCondition(campaignName).get();
  while(CampaignIterator.hasNext()){
    var campaign = CampaignIterator.next();
    if(dateToday.getDate() == 1){
      var ResetBudget = maxBudgetLimit*30/100;
      ResetBudget     = Math.round(ResetBudget*100)/100;
      campaign.getBudget().setAmount(ResetBudget);
      Logger.log(campaign.getName()+' Budget have been reset to '+ResetBudget);
    }
    else{
      var GetBudgetForTheDay = GetBudgetForTheDay(dateToday.getDate(),maxBudgetLimit);
      var GetCurrentBudget   = campaign.getBudget().getAmount();
      var FinalUpdatedBudget = GetCurrentBudget+GetBudgetForTheDay;
      if(FinalUpdatedBudget < maxBudgetLimit){
        campaign.getBudget().setAmount(FinalUpdatedBudget);
        Logger.log(campaign.getName()+' have curren budget: '+GetCurrentBudget+', Budget Increment: '+GetBudgetForTheDay+', Final Budget: '+FinalUpdatedBudget);
      }
      else{
        Logger.log(campaign.getName()+" already using its maximum allowed budget."); 
      }
    }
  }
}
// Coming soon. Subscribe to our email list to get latest updates.


Alerts

High Mobile Clicks Email Alert

Get an email alert when your mobile device clicks are great than 50% of total clicks.

accountID
Enter your account number
emails
Enter email addresses
function main() {
  var accountID = '';
  var emails    = ''; // Email Addresses
  var message   = ''; // Leave blank
  var accountIterator = MccApp.accounts().withCondition("ManagerCustomerId='"+accountID+"'").get();
  while (accountIterator.hasNext()) {
    var account = accountIterator.next();
    MccApp.select(account);
    var TotalClickQuery        = Google AdsApp.report("SELECT Clicks FROM ACCOUNT_PERFORMANCE_REPORT DURING LAST_30_DAYS").rows();
    var MobileClickQuery       = Google AdsApp.report("SELECT Clicks FROM ACCOUNT_PERFORMANCE_REPORT WHERE Device='HIGH_END_MOBILE' DURING LAST_30_DAYS").rows();
    var TotalClicks            = '0';
    var MobileClicks           = '0';
    if(TotalClickQuery.hasNext()){
      var TotalClick = TotalClickQuery.next();
      TotalClicks    = TotalClick['Clicks'];
    }
     if(MobileClickQuery.hasNext()){
      var MobileClick = MobileClickQuery.next();
      MobileClicks    = MobileClick['Clicks'];
    }
    Logger.log(account.getName()+" has "+MobileClicks+"/"+TotalClicks+" mobile clicks");
    if((MobileClicks*100/TotalClicks)>50){
      message += "# "+account.getName()+" have mobile clicks "+MobileClicks+"/"+TotalClicks+" total clicks which exceeds 50%";
    }
  }
  if(message!=''){
    MailApp.sendEmail(emails, "Mobile Click Report", message)
  }
}// Coming soon. Subscribe to our email list to get latest updates.