The 2025 Ultimate Scripts & Formula's Guide

The 2025 Ultimate Scripts & Formula's Guide

A comprehensive guide to optimizing Google Ads and Facebook Ads using 50 scripts, and 50 formulas, and metrics tailored to e-commerce, retail, and service-based industries. It includes:

  1. Calculation Formulas: Essential metrics like ROAS (Return on Ad Spend), CTR (Click-Through Rate), CPA (Cost per Acquisition), and CVR (Conversion Rate) with explanations on how to use these formulas to analyze ad performance across different ad platforms.
  2. Google Ads Scripts: Automated scripts tailored to real-world scenarios that help advertisers improve efficiency, manage budgets, optimize bids, schedule ads, and track specific performance indicators. Examples include scripts for adjusting bids based on weather, pausing low-performing ads, and optimizing budgets for seasonal trends.
  3. Application and Use Cases: Each script and formula is paired with specific use cases for industries like e-commerce (e.g., bidding adjustments for high-profit products), local services (e.g., weather-based ad scheduling for plumbing services), and retail (e.g., pausing high-cost, low-conversion keywords).
  4. Campaign Management Tips: Includes practical recommendations for building out ad campaigns, from scheduling strategies to automated alerts for budget oversight.

This guide is designed to help advertisers automate campaign management, monitor engagement, and optimize ad spend using a data-driven approach that combines advanced scripts and key performance calculations. The goal is to provide a toolkit of 50+ scripts and formulas to address varied advertising challenges and streamline the campaign. Goodluck on your journey; if there is something not listed and your curious put it in a comment and lets see if we can write up for use.

Maximizing ad performance means knowing which metrics drive impact. Here are 50 Excel-friendly formulas to quickly calculate critical insights in Google and Facebook Ads.

1-6: Basic Metrics

  • Return on Investment (ROI): =(Revenue - Cost) / Cost * 100
  • Return on Ad Spend (ROAS): =Revenue / Ad_Spend
  • Impression Share: =Impressions / Eligible_Impressions
  • Ad Rank: =Max_CPC * Quality_Score
  • Click-Through Rate (CTR): =(Clicks / Impressions) * 100
  • Cost per Acquisition (CPA): =Total_Spend / Conversions


7-20: Engagement, Cost, & Revenue Calculations

  • Average Order Value (AOV): =Total_Revenue / Total_Orders
  • Cost per Click (CPC): =Total_Cost / Clicks
  • Customer Acquisition Cost (CAC): =Total_Spend / New_Customers
  • Lifetime Value (LTV): =Average_Purchase_Value * Purchase_Frequency * Customer_Lifespan
  • Profit per Click: =Profit / Clicks
  • Click Share: =Total_Clicks / Eligible_Clicks
  • Engagement Rate: =((Comments + Shares + Likes) / Total_Impressions) * 100
  • Effective CPM (eCPM): =Total_Revenue / Impressions * 1000
  • Bounce Rate: =(Single_Page_Visits / Total_Visits) * 100
  • Cost per Thousand Impressions (CPM): =(Total_Spend / Impressions) * 1000
  • Revenue per Click (RPC): =Revenue / Clicks


21-30: Attribution & Customer Journey Metrics

  • First-Click Attribution:
  • Last-Click Attribution:
  • Linear Attribution: =1 / Total_Clicks_in_Path * 100
  • Position-Based Attribution: Commonly 40% to first/last clicks, with 20% for middle clicks.
  • Churn Rate: =(Lost_Customers / Total_Customers_at_Start) * 100
  • Frequency Cap Rate: =Total_Impressions / Unique_Impressions
  • Reach Rate: =(Unique_Reach / Total_Audience) * 100
  • Average Frequency: =Total_Impressions / Unique_Reach


31-40: Efficiency Ratios & Retargeting Insights

  • Efficiency Ratio: =Revenue / Total_Cost
  • Budget Attainment Rate: =(Actual_Spend / Planned_Spend) * 100
  • Customer Retention Rate: =(Retained_Customers / Total_Customers) * 100
  • Upsell Success Rate: =(Upsell_Conversions / Total_Transactions) * 100
  • Abandoned Cart Rate: =(Cart_Abandonments / Carts_Created) * 100


41-50: Audience Insights & Channel Analysis

  • Engagement per Cost: =Total_Engagements / Total_Ad_Spend
  • Average Session Duration: Observed via Google Analytics.
  • Recency-Frequency-Monetary (RFM) Score: Scores users on recency, frequency, and purchase value.
  • Page Depth per Visit: =Total_Pages_Viewed / Total_Visits
  • Cost per Acquisition by Channel: =Spend_on_Channel / Conversions_from_Channel

For each formula, calculate, automate, and monitor performance across all campaigns. Save time and focus your ad budget on metrics that enhance ROI and streamline campaign management!


Here's an enhanced list of 50 sample scripts you can implement directly in Google Ads for various campaign management tasks.


1. 404 Error Checker Script

function main() {
  var urlIterator = AdsApp.ads().withCondition("Status = ENABLED").get();
  while (urlIterator.hasNext()) {
    var ad = urlIterator.next();
    var url = ad.urls().getFinalUrl();
    if (url) {
      var responseCode = UrlFetchApp.fetch(url).getResponseCode();
      if (responseCode === 404) {
        ad.pause();
        Logger.log("Paused ad with 404 URL: " + url);
      }
    }
  }
}
        

Purpose: Checks ads’ final URLs for any that lead to 404 errors and pauses them to avoid wasted spend.


2. Over-Budget Alert Script

function main() {
  var campaigns = AdsApp.campaigns().get();
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    var budget = campaign.getBudget();
    var spend = campaign.getStatsFor("TODAY").getCost();
    
    if (spend >= budget.getAmount()) {
      Logger.log("Campaign over budget: " + campaign.getName());
      MailApp.sendEmail("[email protected]", "Campaign Over Budget", "Campaign over budget: " + campaign.getName());
    }
  }
}
        

Purpose: Sends an alert if any campaign reaches or exceeds its daily budget.


3. Dayparting Script

function main() {
  var hour = (new Date()).getHours();
  var campaigns = AdsApp.campaigns().withCondition("Status = ENABLED").get();
  
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    if (hour >= 8 && hour <= 20) {  // Only run ads from 8am to 8pm
      campaign.enable();
    } else {
      campaign.pause();
    }
  }
}
        

Purpose: Enables or pauses campaigns based on specified hours (e.g., 8 am to 8 pm).


4. Keyword Quality Score Tracker

function main() {
  var keywords = AdsApp.keywords().get();
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    var qualityScore = keyword.getQualityScore();
    Logger.log("Keyword: " + keyword.getText() + ", Quality Score: " + qualityScore);
  }
}
        

Purpose: Logs each keyword’s Quality Score daily for monitoring purposes.


5. Low-Performing Ad Pauser

function main() {
  var ads = AdsApp.ads()
    .withCondition("Clicks > 100")
    .withCondition("Conversions < 1")
    .get();
    
  while (ads.hasNext()) {
    var ad = ads.next();
    ad.pause();
    Logger.log("Paused low-performing ad: " + ad.getHeadline());
  }
}
        

Purpose: Pauses ads with over 100 clicks but no conversions to optimize ad quality.


6. Negative Keyword Finder Script

function main() {
  var searchTerms = AdsApp.report(
    "SELECT SearchTerm, Cost, Conversions FROM SEARCH_QUERY_PERFORMANCE_REPORT " +
    "WHERE Conversions < 1 AND Cost > 10").rows();
  
  while (searchTerms.hasNext()) {
    var searchTerm = searchTerms.next();
    Logger.log("Adding negative keyword: " + searchTerm["SearchTerm"]);
    AdsApp.negativeKeywords().create(searchTerm["SearchTerm"]);
  }
}
        

Purpose: Identifies high-cost search terms without conversions and adds them as negatives.


7. Device-Based Bid Adjuster

function main() {
  var campaigns = AdsApp.campaigns().get();
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    campaign.targeting().platforms().desktop().setBidModifier(1.2);  // Increase desktop bids by 20%
    campaign.targeting().platforms().mobile().setBidModifier(0.9);   // Decrease mobile bids by 10%
  }
}
        

Purpose: Adjusts bids based on device performance, such as increasing bids on desktop.


8. Quality Score Drop Alert

function main() {
  var keywords = AdsApp.keywords().get();
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    if (keyword.getQualityScore() < 5) {
      MailApp.sendEmail("[email protected]", "Quality Score Alert", "Keyword: " + keyword.getText() + " has Quality Score below 5.");
    }
  }
}
        

Purpose: Sends an email alert if any keyword’s Quality Score falls below 5.


9. Holiday Bid Adjuster Script

function main() {
  var today = new Date();
  var isHolidaySeason = (today.getMonth() == 11); // December
  var campaigns = AdsApp.campaigns().get();
  
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    if (isHolidaySeason) {
      campaign.bidding().setCpc( campaign.bidding().getCpc() * 1.3 );  // Increase bids by 30%
    }
  }
}
        

Purpose: Temporarily increases bids during December holiday season to capture higher demand.


10. Call-Only Ad Performance Tracker

function main() {
  var callOnlyAds = AdsApp.ads().withCondition("Type = 'CALL_ONLY'").get();
  while (callOnlyAds.hasNext()) {
    var ad = callOnlyAds.next();
    Logger.log("Call-Only Ad: " + ad.getHeadline() + " | Conversions: " + ad.getStatsFor("LAST_7_DAYS").getConversions());
  }
}
        

Purpose: Tracks performance metrics for Call-Only ads specifically.


11. Retargeting Ad Schedule Script

function main() {
  var adGroups = AdsApp.adGroups().withCondition("LabelNames CONTAINS 'Remarketing'").get();
  while (adGroups.hasNext()) {
    var adGroup = adGroups.next();
    if (new Date().getDay() === 0) {  // Run remarketing ads only on Sundays
      adGroup.enable();
    } else {
      adGroup.pause();
    }
  }
}
        

Purpose: Schedules remarketing ads to run only on weekends or other custom schedules.


12. Seasonal Pause and Resume Script

function main() {
  var campaigns = AdsApp.campaigns().withCondition("Name CONTAINS 'Winter'").get();
  var today = new Date();
  var month = today.getMonth();
  
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    if (month >= 11 || month <= 1) {  // Active in December, January
      campaign.enable();
    } else {
      campaign.pause();
    }
  }
}
        

Purpose: Pauses campaigns outside of the seasonal window (e.g., winter).


13. Sales and Promotion Script

function main() {
  var ads = AdsApp.ads().get();
  while (ads.hasNext()) {
    var ad = ads.next();
    ad.setHeadline("25% Off All Orders | Today Only!");
  }
}
        

Purpose: Temporarily updates ad headlines for sales promotions.


14. Automated Performance Snapshot

function main() {
  var campaigns = AdsApp.campaigns().get();
  var report = "Campaign Performance:\n\n";
  
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    report += "Campaign: " + campaign.getName() + " | Clicks: " + campaign.getStatsFor("LAST_7_DAYS").getClicks() + "\n";
  }
  
  MailApp.sendEmail("[email protected]", "Weekly Ad Performance", report);
}
        

Purpose: Sends a weekly snapshot of key performance indicators (e.g., clicks).

15. Inventory-Based Bid Adjuster

function main() {
  var productInventory = {
    "Product1": 10,
    "Product2": 0,
    "Product3": 5
  };
  
  var keywords = AdsApp.keywords().get();
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    var productName = keyword.getText();
    
    if (productInventory[productName] === 0) {
      keyword.pause();
      Logger.log("Paused keyword: " + productName + " due to zero stock.");
    }
  }
}
        

Purpose: Pauses keywords based on real-time inventory levels.

Example: A retailer pauses bids for out-of-stock products, avoiding wasted spend on unavailable items.


16. Bid Adjuster for Location Performance

function main() {
  var locations = AdsApp.report(
    "SELECT Location, Cost, Conversions " +
    "FROM GEO_PERFORMANCE_REPORT " +
    "WHERE Conversions > 1"
  ).rows();

  while (locations.hasNext()) {
    var location = locations.next();
    var locationName = location["Location"];
    var conversions = parseFloat(location["Conversions"]);
    
    if (conversions > 5) {
      AdsApp.campaignTargeting()
        .location(locationName)
        .setBidModifier(1.3);  // Increase bid by 30%
      Logger.log("Increased bid in location: " + locationName);
    }
  }
}
        

Purpose: Adjusts bids for high-performing locations.

Example: A restaurant chain increases bids for areas with higher conversion rates, like urban centers.


17. Bid Adjuster for Device-Specific Performance

function main() {
  var campaigns = AdsApp.campaigns().get();
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    campaign.targeting().platforms().mobile().setBidModifier(1.2); // Boost mobile bids
  }
}
        

Purpose: Modifies bids specifically for device performance.

Example: An e-commerce store increases mobile bids due to high mobile traffic.


18. Auto-Generate Sitelinks for New Campaigns

function main() {
  var campaignIterator = AdsApp.campaigns().withCondition("LabelNames CONTAINS 'New Campaign'").get();
  while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var sitelinkBuilder = campaign.extensions().newSitelinkBuilder();
    sitelinkBuilder
      .withLinkText("Shop Now")
      .withFinalUrl("https://www.example.com/shop")
      .build();
  }
}
        

Purpose: Automatically creates sitelinks for newly labeled campaigns.

Example: An e-commerce store sets up “Shop Now” links for all new promotions.


19. Conversion-Based Bid Adjuster

function main() {
  var adGroups = AdsApp.adGroups().get();
  while (adGroups.hasNext()) {
    var adGroup = adGroups.next();
    if (adGroup.getStatsFor("LAST_30_DAYS").getConversions() > 5) {
      adGroup.bidding().setCpc(adGroup.bidding().getCpc() * 1.2);
      Logger.log("Increased bid for ad group: " + adGroup.getName());
    }
  }
}
        

Purpose: Increases bids for high-converting ad groups.

Example: A travel agency boosts bids on top-performing ad groups related to high-demand destinations.


20. Auto-Generate Keyword List Based on Site Content

function main() {
  var siteContent = ["Plumbing Services", "Water Heater Repair", "Drain Cleaning"];
  for (var i = 0; i < siteContent.length; i++) {
    var keywordText = siteContent[i];
    AdsApp.createKeyword(keywordText);
    Logger.log("Created keyword: " + keywordText);
  }
}
        

Purpose: Automatically generates keywords from specific site content.

Example: A plumbing company creates keywords based on their website services.


21. Target CPA Bidding Script

function main() {
  var campaigns = AdsApp.campaigns().get();
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    campaign.bidding().setTargetCpa(50);  // Set CPA target to $50
  }
}
        

Purpose: Sets a CPA target for cost-efficient ad spending.

Example: An online course provider sets CPA targets for specific campaigns to maintain profitability.


22. Automated Report Delivery Script

function main() {
  var report = AdsApp.report(
    "SELECT CampaignName, Clicks, Conversions, Cost " +
    "FROM CAMPAIGN_PERFORMANCE_REPORT " +
    "DURING LAST_7_DAYS"
  );

  MailApp.sendEmail("[email protected]", "Weekly Ad Report", report.asCsv());
}
        

Purpose: Sends an automated weekly performance report.

Example: A marketing manager receives weekly performance updates directly to their inbox.


23. Geo-Based Ad Schedule Adjuster

function main() {
  var locations = ["New York", "California"];
  var campaigns = AdsApp.campaigns().get();

  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    for (var i = 0; i < locations.length; i++) {
      var location = locations[i];
      campaign.targeting().location(location).setBidModifier(1.1);  // Boost by 10%
    }
  }
}
        

Purpose: Schedules ads based on geographical location.

Example: A retail store chain boosts bids in high-conversion locations like New York.


24. Low-CPC Keyword Optimizer

function main() {
  var keywords = AdsApp.keywords().withCondition("Cpc < 0.5").get();
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    keyword.bidding().setCpc(keyword.getCpc() * 1.5);  // Increase low CPC by 50%
    Logger.log("Increased CPC for low-bid keyword: " + keyword.getText());
  }
}
        

Purpose: Increases CPC for keywords with very low bids.

Example: A SaaS provider increases CPCs for low-cost keywords to gain more impressions.


25. Keyword Bidding Script for High-ROAS Keywords

function main() {
  var keywords = AdsApp.keywords().withCondition("ConversionValue / Cost > 3").get();
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    keyword.bidding().setCpc(keyword.getCpc() * 1.3); // Increase by 30%
  }
}
        

Purpose: Boosts bids for keywords with a high ROAS.

Example: An online retailer increases bids on profitable keywords to capture more traffic.


26. Auto-Pause Low Conversion Keywords

function main() {
  var keywords = AdsApp.keywords().withCondition("Conversions < 1").get();
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    keyword.pause();
    Logger.log("Paused keyword with no conversions: " + keyword.getText());
  }
}
        

Purpose: Pauses keywords that haven’t converted.

Example: A digital agency pauses low-conversion keywords to optimize spend.


27. Location-Based Conversion Analysis Script

function main() {
  var report = AdsApp.report(
    "SELECT CityName, Conversions, Cost FROM GEO_PERFORMANCE_REPORT DURING LAST_30_DAYS"
  );

  var cityStats = report.rows();
  while (cityStats.hasNext()) {
    var city = cityStats.next();
    Logger.log("City: " + city.CityName + " - Conversions: " + city.Conversions + " - Cost: " + city.Cost);
  }
}
        

Purpose: Provides a city-level breakdown of conversions.

Example: An HVAC service analyzes conversion rates by city to optimize location targeting.


28. Automated Weather-Based Bid Adjuster

function main() {
  var cityWeather = {
    "Phoenix": "sunny",
    "Seattle": "rainy"
  };

  for (var city in cityWeather) {
    if (cityWeather[city] === "rainy") {
      var campaigns = AdsApp.campaigns().withCondition("Name CONTAINS '" + city + "'").get();
      while (campaigns.hasNext()) {
        var campaign = campaigns.next();
        campaign.bidding().setCpc(campaign.bidding().getCpc() * 1.2); // Increase by 20%
      }
      Logger.log("Increased bids for rainy weather in: " + city);
    }
  }
}
        

Purpose: Adjusts bids based on weather conditions to increase relevance for weather-dependent services or products.

Example: A plumbing service increases bids during rainy weather in Seattle to capture emergency calls.


29. Underperforming Ad Group Pauser

function main() {
  var adGroups = AdsApp.adGroups().withCondition("Conversions < 1").get();
  while (adGroups.hasNext()) {
    var adGroup = adGroups.next();
    adGroup.pause();
    Logger.log("Paused underperforming ad group: " + adGroup.getName());
  }
}
        

Purpose: Pauses ad groups with no conversions to reduce waste.

Example: A law firm minimizes costs by pausing ad groups with no leads after a month.


30. Impression Share Report Script

function main() {
  var campaigns = AdsApp.campaigns().get();
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    var impressionShare = campaign.getStatsFor("LAST_7_DAYS").getImpressionShare();
    Logger.log("Campaign: " + campaign.getName() + ", Impression Share: " + impressionShare);
  }
}
        

Purpose: Provides impression share data to help identify opportunities for increasing visibility.

Example: An e-commerce business identifies low impression share on high-ROI campaigns and increases bids accordingly.


31. Ad Extension Checker

function main() {
  var campaigns = AdsApp.campaigns().get();
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    var extensions = campaign.extensions().sitelinks().get();
    if (!extensions.hasNext()) {
      Logger.log("Campaign missing sitelinks: " + campaign.getName());
    }
  }
}
        

Purpose: Flags campaigns missing ad extensions to maximize SERP presence.

Example: A local retailer ensures all active campaigns use sitelinks for optimal engagement.


32. Pause Underperforming Keywords by ROAS

function main() {
  var keywords = AdsApp.keywords().withCondition("ConversionValue / Cost < 1").get();
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    keyword.pause();
    Logger.log("Paused low ROAS keyword: " + keyword.getText());
  }
}
        

Purpose: Pauses keywords that don’t meet a target ROAS.

Example: A fitness brand pauses keywords with poor ROAS to focus on higher-profit terms.


33. High-CTR Bid Adjuster

function main() {
  var keywords = AdsApp.keywords().withCondition("Ctr > 0.05").get(); // CTR > 5%
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    keyword.bidding().setCpc(keyword.getCpc() * 1.2); // Increase by 20%
  }
}
        

Purpose: Increases bids for high-CTR keywords to improve ad visibility.

Example: An e-commerce brand boosts bids on keywords with a high CTR for more exposure.


34. Cost-Per-Conversion Adjuster

function main() {
  var adGroups = AdsApp.adGroups().get();
  while (adGroups.hasNext()) {
    var adGroup = adGroups.next();
    var cpc = adGroup.getStatsFor("LAST_30_DAYS").getCost() / adGroup.getStatsFor("LAST_30_DAYS").getConversions();
    if (cpc > 50) {
      adGroup.bidding().setCpc(adGroup.bidding().getCpc() * 0.8); // Decrease by 20%
      Logger.log("Reduced bid for high CPC ad group: " + adGroup.getName());
    }
  }
}
        

Purpose: Reduces bids for ad groups with high costs per conversion to increase profitability.

Example: A luxury retailer manages ad group costs by reducing bids for those with high CPC.


35. Underperforming Ad Pauser by CPA

function main() {
  var ads = AdsApp.ads().withCondition("CostPerConversion > 10").get();
  while (ads.hasNext()) {
    var ad = ads.next();
    ad.pause();
    Logger.log("Paused high CPA ad: " + ad.getHeadline());
  }
}
        

Purpose: Pauses ads that exceed a specific cost per acquisition.

Example: A subscription service pauses ads with CPAs exceeding their target to optimize budgets.


36. Keyword Bid Reduction Script for High-Cost, Low-Conversion Terms

function main() {
  var keywords = AdsApp.keywords().withCondition("Cost > 20").withCondition("Conversions < 1").get();
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    keyword.bidding().setCpc(keyword.getCpc() * 0.7); // Reduce by 30%
    Logger.log("Reduced bid for high-cost, low-conversion keyword: " + keyword.getText());
  }
}
        

Purpose: Reduces bids for keywords that are high-cost but yield few conversions.

Example: A digital marketing agency lowers bids on low-converting keywords to improve ROI.


37. Audience-Based Ad Schedule Optimizer

function main() {
  var audiences = AdsApp.userLists().get();
  while (audiences.hasNext()) {
    var audience = audiences.next();
    var campaigns = AdsApp.campaigns().withCondition("AudienceListNames CONTAINS '" + audience.getName() + "'").get();
    
    while (campaigns.hasNext()) {
      var campaign = campaigns.next();
      campaign.setAdSchedule({dayOfWeek: "SATURDAY", startHour: 8, endHour: 20});
      Logger.log("Optimized ad schedule for audience: " + audience.getName());
    }
  }
}
        

Purpose: Schedules ads based on audience insights, allowing different ads for different audiences on specific days/times.

Example: A travel agency runs ads on weekends when users are most likely to search for vacation plans.


38. Keyword Conversion Rate Report Script

function main() {
  var keywords = AdsApp.keywords().get();
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    var conversions = keyword.getStatsFor("LAST_30_DAYS").getConversions();
    var clicks = keyword.getStatsFor("LAST_30_DAYS").getClicks();
    var conversionRate = (conversions / clicks) * 100;
    Logger.log("Keyword: " + keyword.getText() + ", Conversion Rate: " + conversionRate + "%");
  }
}
        

Purpose: Calculates and logs conversion rates for keywords to help prioritize optimizations.

Example: An insurance company tracks conversion rates to identify keywords with high intent.


39. High-Impression, Low-CTR Keyword Pauser

function main() {
  var keywords = AdsApp.keywords().withCondition("Impressions > 1000").withCondition("Ctr < 0.01").get();
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    keyword.pause();
    Logger.log("Paused high-impression, low-CTR keyword: " + keyword.getText());
  }
}
        

Purpose: Pauses keywords with high impressions but low CTR to reduce wasted impressions.

Example: A clothing retailer eliminates unproductive keywords that aren’t driving engagement.


40. Budget Reallocation Script

function main() {
  var campaigns = AdsApp.campaigns().withCondition("Cost < 50").get();
  var reallocationAmount = 100;

  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    campaign.getBudget().setAmount(campaign.getBudget().getAmount() + reallocationAmount);
    Logger.log("Reallocated budget to campaign: " + campaign.getName());
  }
}
        

Purpose: Reallocates budget from low-spend to high-performing campaigns.

Example: An automotive dealer reallocates budget to best-selling car model campaigns.


41. Dynamic Seasonal Adjustment Script

function main() {
  var campaigns = AdsApp.campaigns().withCondition("Name CONTAINS 'Seasonal'").get();
  var today = new Date();
  var month = today.getMonth();

  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    if (month >= 10 || month <= 2) { // Active in peak shopping months: Nov-Feb
      campaign.enable();
    } else {
      campaign.pause();
    }
  }
}
        

Purpose: Pauses or activates campaigns based on seasonal timing.

Example: A retail store activates campaigns during high-demand holiday months for seasonal promotions.


42. Age-Based Bid Adjustment Script

function main() {
  var adGroups = AdsApp.adGroups().get();
  while (adGroups.hasNext()) {
    var adGroup = adGroups.next();
    adGroup.targeting().ages().withCondition("AgeRange = '18-24'").setBidModifier(1.1);  // Increase bids by 10% for young adults
  }
}
        

Purpose: Adjusts bids based on age demographic targeting.

Example: A fashion brand increases bids for the 18-24 demographic for targeted campaigns aimed at Gen Z consumers.


43. Conversion-Based Negative Keyword Generator

function main() {
  var searchTerms = AdsApp.report(
    "SELECT SearchTerm, Cost, Conversions FROM SEARCH_QUERY_PERFORMANCE_REPORT " +
    "WHERE Conversions = 0 AND Cost > 10"
  ).rows();

  while (searchTerms.hasNext()) {
    var searchTerm = searchTerms.next();
    AdsApp.negativeKeywords().create(searchTerm["SearchTerm"]);
    Logger.log("Added negative keyword: " + searchTerm["SearchTerm"]);
  }
}
        

Purpose: Adds high-cost, non-converting search terms as negative keywords.

Example: A home services business blocks terms that don’t lead to conversions, optimizing ad spend.


44. Custom Labels for Product Bidding Script

function main() {
  var products = AdsApp.shoppingProductGroups().withCondition("CustomLabel0 CONTAINS 'HighProfit'").get();
  while (products.hasNext()) {
    var product = products.next();
    product.bidding().setCpc(product.bidding().getCpc() * 1.2);  // Increase by 20% for high-profit items
  }
}
        

Purpose: Increases bids on high-profit products identified by custom labels.

Example: An e-commerce store optimizes bids on profitable items, like premium electronics.


45. Automated Budget Cap Adjustment Script

function main() {
  var campaigns = AdsApp.campaigns().get();
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    var dailyBudget = campaign.getBudget().getAmount();
    if (campaign.getStatsFor("LAST_30_DAYS").getCost() > dailyBudget * 30) {
      campaign.getBudget().setAmount(dailyBudget * 0.8);  // Reduce by 20%
      Logger.log("Adjusted budget for campaign: " + campaign.getName());
    }
  }
}
        

Purpose: Reduces budgets for campaigns that exceed monthly limits.

Example: A SaaS provider limits spending on high-cost campaigns to manage ROI.


46. Day-of-Week Conversion Tracking Script

function main() {
  var dayOfWeek = new Date().getDay();
  var campaigns = AdsApp.campaigns().get();
  
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    var conversions = campaign.getStatsFor("LAST_7_DAYS").getConversions();
    Logger.log("Campaign: " + campaign.getName() + ", Conversions on day " + dayOfWeek + ": " + conversions);
  }
}
        

Purpose: Tracks conversions by day of the week to optimize schedules.

Example: An e-commerce business identifies high-converting days and increases bids on those days.


47. Auto-Label Low-Conversion Ads

function main() {
  var ads = AdsApp.ads().withCondition("Conversions < 1").get();
  while (ads.hasNext()) {
    var ad = ads.next();
    ad.applyLabel("Low Conversion");
    Logger.log("Labeled low-conversion ad: " + ad.getHeadline());
  }
}
        

Purpose: Automatically labels ads with low conversions for easier filtering.

Example: A digital agency labels underperforming ads to quickly identify and review them.


48. Auto-Update Campaign Name with Budget Info

function main() {
  var campaigns = AdsApp.campaigns().get();
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    var budget = campaign.getBudget().getAmount();
    var updatedName = campaign.getName() + " | Budget: $" + budget;
    campaign.setName(updatedName);
    Logger.log("Updated campaign name to include budget: " + updatedName);
  }
}
        

Purpose: Adds budget information directly into campaign names for tracking.

Example: A manager can view budget levels at a glance when analyzing campaign names.


49. Dynamic Keyword Insertion Ad Checker

function main() {
  var ads = AdsApp.ads().withCondition("Description1 CONTAINS '{keyword}'").get();
  while (ads.hasNext()) {
    var ad = ads.next();
    if (!ad.isEnabled()) {
      ad.enable();
      Logger.log("Enabled ad with DKI: " + ad.getHeadline());
    }
  }
}
        

Purpose: Ensures that all ads with dynamic keyword insertion are enabled.

Example: A local service provider ensures all dynamically optimized ads are live for maximum relevance.


50. Performance Degradation Alert Script

function main() {
  var campaigns = AdsApp.campaigns().get();
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    var thisMonthCPA = campaign.getStatsFor("THIS_MONTH").getCost() / campaign.getStatsFor("THIS_MONTH").getConversions();
    var lastMonthCPA = campaign.getStatsFor("LAST_MONTH").getCost() / campaign.getStatsFor("LAST_MONTH").getConversions();
    
    if (thisMonthCPA > lastMonthCPA * 1.2) {  // CPA increased by more than 20%
      MailApp.sendEmail("[email protected]", "CPA Alert", "CPA for " + campaign.getName() + " increased significantly.");
      Logger.log("CPA increased for campaign: " + campaign.getName());
    }
  }
}
        

Purpose: Sends an alert when CPA rises significantly from the previous month.

Example: An e-commerce company monitors cost-per-acquisition increases and adjusts campaigns accordingly.



要查看或添加评论,请登录

John W.的更多文章

社区洞察

其他会员也浏览了