Get More Local Leads with Google Local Services Ads — Plans Start at $600/Month
0 like 0 dislike
400 views
by Marketing Guru (7.5k points)

1 Answer

0 like 0 dislike
by Marketing Guru (8.0k points)

Yes, you can use this code to auto-pause at 5 PM and auto-enable at 9 AM.

  • What it does: Pauses selected campaigns at 17:00 and enables them at 09:00 (account time zone).

  • Safety: Only touches campaigns labeled AUTO_SCHEDULE. (Change or remove the label logic if you want it to affect all campaigns.)

  • Scheduling: Set the script to run Hourly.

/**
 * Auto-pause at 17:00 and auto-enable at 09:00 (account time zone).
 * Affects only campaigns with label "AUTO_SCHEDULE".
 * Schedule: Hourly
 */
function main() {
  var tz = AdsApp.currentAccount().getTimeZone();
  var hour = parseInt(Utilities.formatDate(new Date(), tz, 'H'), 10); // 0–23
  var labelName = 'AUTO_SCHEDULE';

  ensureLabel_(labelName);

  if (hour === 17) {
    // 5 PM — pause enabled campaigns
    var it = AdsApp.campaigns()
      .withCondition("Status = ENABLED")
      .withCondition("LabelNames CONTAINS_ANY ['" + labelName + "']")
      .get();
    var count = 0;
    while (it.hasNext()) { it.next().pause(); count++; }
    Logger.log('Paused ' + count + ' campaign(s) at 17:00.');
  } else if (hour === 9) {
    // 9 AM — enable paused campaigns
    var it2 = AdsApp.campaigns()
      .withCondition("Status = PAUSED")
      .withCondition("LabelNames CONTAINS_ANY ['" + labelName + "']")
      .get();
    var count2 = 0;
    while (it2.hasNext()) { it2.next().enable(); count2++; }
    Logger.log('Enabled ' + count2 + ' campaign(s) at 09:00.');
  } else {
    Logger.log('No action this hour (' + hour + ':00).');
  }
}

function ensureLabel_(name) {
  if (!AdsApp.labels().withCondition("Name = '" + name + "'").get().hasNext()) {
    AdsApp.createLabel(name);
  }
}

How to use

  1. In Google Ads: Tools & Settings → Bulk actions → Scripts → +

  2. Paste the code → AuthorizeSave.

  3. Add the label AUTO_SCHEDULE to any campaign you want the script to control.

  4. Schedule the script Hourly.

Join a specialized Q&A site for digital marketing experts focused on ad platforms like Google, Facebook, YouTube, LinkedIn, Bing, Quora, and more. Connect with peers to share strategies on client retention beyond acquisition. Discuss and solve technical, managerial, or general challenges to improve your ad campaigns and client relationships.

Register to unlock your digital marketing potential!
Get More Local Leads!
Google Local Services Ads
Starting at $600/Month

Most popular tags

google-ads facebook-ads meta-ads amazon-fba amazon-ads amazon-seller-help youtube-ads ad-campaigns x-ads amazon-2026 pinterest-ads performance-max paid-advertising glsa amazon-storefront ppc-strategy amazon-ppc amazon-seller-account twitter-ads local-service-ads server-side-tracking tiktok-ads conversion-tracking ppc-marketing google-analytics google-tag-manager server-side-tagging ppc ga4 dv-360 google-business-profile campaign-optimization facebook-pixel white-label-agency dynamic-keyword-insertion tools-to-find-keywords microsoft-advertisement feature-snippet-types meta-threads white-label-advertising convertion-tracking feature-snippet performance-marketing-agency pinterest-conversion-lift-study amazon-ungatedwholesale advantage-plus keyword-research shopify bing-ads-ppc video-ads ad-performance amazon-listing marchupdate2026 ppc-optimization metabusinessmanager landing-page mcc-google youtube-trueview-ads google-ads-calls-from-website-conversion pitch-digital-marketing-services pitch-deck-creation tiktok2026 sales-tax-exemptions audience-targeting ad-optimization ppc-landing-page learning-phase creative-testing google-merchant-listings google-local-service-ads disclosure-rule amazon-fbm ahrefs-keyword-difficulty display-ads demand-gen-campaigns dropshipping clickable-ads gtm amazon-product-listing budget-management creative-optimization looker-studio-report trend-genius-ai pinterest-carousel-ads bing-ads-management ppc-campaigns meta-carousel-ads pmax-campaigns campaign-structure microsoft-ads ad-creatives lead-generation landing-page-optimization advantage-campaigns microsoft-advertising-editor search-ads phased-campaign-strategy digital-marketing-tips digital-advertising negative-keywords
...