Google Ads Scripts for B2B: Automating Reports, Alerts and Bid Adjustments

Google Ads icon representing script automation for B2B campaigns

Google Ads scripts give B2B advertisers the ability to automate reporting, create custom alerts and adjust bids based on real performance data, all without needing to build a full application through the API. They run directly inside the Google Ads interface using JavaScript, which makes them accessible to marketing teams and PPC managers who wouldn’t normally write production code. Priority Pixels offers Google Ads management for B2B organisations where scripts and automation are used to reduce manual workload and catch problems before they affect campaign performance.

For B2B accounts, where budgets tend to be tightly controlled and every lead has a measurable cost against it, scripts solve a specific set of problems. They can email a report every Monday morning with last week’s spend and conversion data. They can flag when a campaign’s cost per lead rises above a threshold you’ve defined. They can pause keywords that are draining budget without producing results. These are all tasks that a PPC manager would do manually, but doing them through scripts means they happen consistently, on schedule, without anyone needing to remember to log in and check.

What Google Ads Scripts Are and Why B2B Accounts Need Them

Google Ads scripts are snippets of JavaScript that interact with your Google Ads account through a built-in scripting environment. You write a script (or adapt one from a shared library), paste it into the Scripts section of your Google Ads account, authorise it and set a schedule. The script runs at whatever frequency you choose, from every hour to once a month. It can read data from your campaigns, make changes to bids or ad status, send emails, write data to Google Sheets and pull in external data from URLs.

The Google Ads Scripts documentation provides a full reference for every object and method available. The scripting environment is based on a subset of JavaScript with Google’s own API layer on top, giving access to campaigns, ad groups, keywords, ads, labels, reports and more. You don’t need to manage authentication tokens or set up a development environment. Everything runs within the Google Ads platform itself.

B2B accounts benefit from scripts more than many consumer-facing campaigns because of how B2B paid search typically operates. Budgets are often smaller relative to enterprise B2C spend, which means waste is felt more acutely. Conversion volumes tend to be lower, so each conversion carries more weight in reporting. Sales cycles are longer, which means tracking whether a click eventually turned into revenue requires discipline in how data is captured and reviewed. Scripts can’t shorten a sales cycle, but they can make sure the data you need for decision-making is always current, always formatted the way you want it and always delivered without you having to pull it together manually.

Getting Started with Your First Script

Setting up a Google Ads script takes less time than most people expect. Inside your Google Ads account, navigate to Tools and Settings, then select Scripts under Bulk Actions. You’ll see an editor where you can write or paste JavaScript code. Every script needs a main() function as its entry point. When the script runs, Google calls that function and executes whatever you’ve written inside it.

The simplest starting point is a script that reads data from your account and logs it. From there, you can extend it to send that data via email, write it to a spreadsheet or take action based on what it finds. The learning curve is gentle if you approach it incrementally. Start with reading data, move to writing data to Google Sheets, then progress to making changes within the account like pausing keywords or adjusting bids.

Google’s scripting environment includes a preview mode that lets you run a script without it making any actual changes. The preview shows you what the script would do, logging the output so you can verify the logic before switching it live. This is particularly useful for scripts that modify bids or pause campaigns, where an error in the logic could have immediate budget implications. Always run in preview mode first, check the logs and only schedule the script once you’re confident the output matches your expectations.

Automating Reports with Google Ads Scripts

Reporting is where most B2B teams start with scripts. There’s good reason for that. Pulling weekly or monthly performance data from Google Ads, formatting it and sharing it with stakeholders is repetitive work that follows the same pattern every time. A script can do this automatically, writing the results to a Google Sheet that everyone on the team can access or sending a summary email at a set time each week.

The following example script pulls campaign-level performance data for the previous seven days and writes it to a Google Sheet. You’d replace the spreadsheet URL with your own and adjust the date range or metrics to match your reporting needs.

function main() {
  var spreadsheet = SpreadsheetApp.openByUrl(
    'https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit'
  );
  var sheet = spreadsheet.getActiveSheet();
  sheet.clear();
  sheet.appendRow(['Campaign', 'Clicks', 'Impressions', 'Cost', 'Conversions', 'Cost/Conv']);

  var report = AdsApp.report(
    'SELECT CampaignName, Clicks, Impressions, Cost, Conversions, CostPerConversion ' +
    'FROM CAMPAIGN_PERFORMANCE_REPORT ' +
    'WHERE Impressions > 0 ' +
    'DURING LAST_7_DAYS'
  );

  var rows = report.rows();
  while (rows.hasNext()) {
    var row = rows.next();
    sheet.appendRow([
      row['CampaignName'],
      row['Clicks'],
      row['Impressions'],
      row['Cost'],
      row['Conversions'],
      row['CostPerConversion']
    ]);
  }

  Logger.log('Report written to spreadsheet.');
}

Once this script is scheduled to run weekly, it overwrites the sheet with fresh data every time. You can extend it by adding multiple tabs for different date ranges, including ad group or keyword-level data or calculating week-on-week changes within the script itself. For B2B accounts, a common addition is filtering by campaign label so that brand campaigns, competitor campaigns and generic campaigns each get their own section in the report.

The Search Engine Land overview of Google Ads scripts covers reporting as one of the most popular use cases. It’s easy to see why. A script that takes 20 minutes to set up can save an hour or more each week in manual data pulling and formatting.

Setting Up Alerts for Budget and Performance Changes

Desktop advertising icon representing Google Ads alert monitoring

B2B campaigns often run on budgets where a day or two of overspend can have a noticeable impact on monthly targets. The same applies to a sudden drop in conversion rate. Scripts can monitor these metrics and send an email alert the moment something moves outside an acceptable range. This is more responsive than logging into the account daily. It’s also more specific than the default notifications Google Ads provides.

An alert script typically checks one or more metrics against thresholds you define. If the metric crosses that threshold, the script sends an email. You can set up alerts for cost exceeding a daily limit, conversion rate dropping below a target, click-through rate falling by a certain percentage compared to the previous period, or impression share declining to a point where your ads are losing visibility.

The script below checks whether any campaign has spent more than a defined daily budget threshold and emails you if it has. This is a straightforward starting point that can be adapted for other metrics.

function main() {
  var DAILY_SPEND_LIMIT = 150;
  var EMAIL_ADDRESS = 'your.email@company.co.uk';
  var alertMessages = [];

  var campaigns = AdsApp.campaigns()
    .withCondition('Status = ENABLED')
    .get();

  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
    var stats = campaign.getStatsFor('TODAY');
    var spend = stats.getCost();

    if (spend > DAILY_SPEND_LIMIT) {
      alertMessages.push(
        campaign.getName() + ' has spent £' + spend.toFixed(2) + ' today'
      );
    }
  }

  if (alertMessages.length > 0) {
    MailApp.sendEmail(
      EMAIL_ADDRESS,
      'Google Ads Budget Alert',
      'The following campaigns have exceeded the daily spend limit of £' +
        DAILY_SPEND_LIMIT + ':nn' + alertMessages.join('n')
    );
  }
}

You’d schedule this to run hourly so it catches overspend during the day rather than after the budget has already been exhausted. For B2B accounts targeting specific working hours, you might also build in time-of-day checks so the script only monitors during the periods your ads are actively running. The alert approach works well alongside paid search management because it gives the advertiser as well as any agency managing the account an early warning system that operates independently of anyone’s daily schedule.

Bid Adjustments Based on Performance Data

Automated bid adjustments are where scripts start having a direct impact on campaign performance rather than just reporting on it. The principle is straightforward. You define rules for how bids should change based on performance metrics. The script then applies those rules across your keywords at whatever frequency you set. This sits between manual bidding (where a person reviews and adjusts bids periodically) and fully automated bidding strategies (where Google’s algorithms control everything).

For B2B accounts, script-based bid adjustments are useful when you want more control than automated strategies provide but more consistency than manual reviews allow. A common approach is to increase bids on keywords that are converting at an acceptable cost per lead and decrease bids on keywords where the cost per conversion exceeds your target. The script below applies this logic across all keywords in a campaign, using a 30-day lookback window.

function main() {
  var TARGET_CPA = 80;
  var BID_INCREASE = 1.15;
  var BID_DECREASE = 0.85;
  var MIN_CONVERSIONS = 2;

  var keywords = AdsApp.keywords()
    .withCondition('Status = ENABLED')
    .withCondition('CampaignStatus = ENABLED')
    .withCondition('AdGroupStatus = ENABLED')
    .get();

  while (keywords.hasNext()) {
    var keyword = keywords.next();
    var stats = keyword.getStatsFor('LAST_30_DAYS');
    var conversions = stats.getConversions();
    var cost = stats.getCost();

    if (conversions >= MIN_CONVERSIONS) {
      var cpa = cost / conversions;
      var currentBid = keyword.bidding().getCpc();

      if (cpa  TARGET_CPA * 1.2) {
        keyword.bidding().setCpc(currentBid * BID_DECREASE);
        Logger.log('Decreased bid for: ' + keyword.getText());
      }
    }
  }
}

The MIN_CONVERSIONS threshold is worth paying attention to. In B2B, where conversion volumes are often low, making bid decisions based on one or two conversions introduces too much variance. Setting a minimum conversion count before the script acts prevents it from overreacting to small data sets. You might also add a maximum bid cap to prevent bids from escalating beyond what makes commercial sense. A bid floor serves the opposite purpose, stopping bids from dropping so low that the keyword loses all impression share.

The WordStream guide to Google Ads scripts recommends starting with conservative adjustment percentages and reviewing the results weekly before increasing the script’s authority. That’s sound advice for B2B campaigns, where the consequences of a bidding error are felt more directly given the typically higher cost per click in B2B verticals.

Scripts vs Automated Rules vs the Google Ads API

Google Ads offers three approaches to automation. Understanding where scripts fit relative to the other two helps you choose the right tool for each task. Automated rules are the simplest option. You set them up through the Google Ads interface without writing any code. They can pause or enable campaigns based on simple conditions, send email alerts when a metric crosses a threshold. They can adjust bids by a fixed percentage. They’re limited to one condition at a time and can’t perform calculations, combine data from multiple sources or write to external systems.

The Google Ads API sits at the other end of the spectrum. It provides full programmatic access to every feature in Google Ads, but requires a proper development environment, authentication setup, a developer token and ongoing maintenance of external code. It’s the right choice for large-scale automation across many accounts, custom bidding algorithms or deep integration with CRM and analytics platforms.

Feature Automated Rules Google Ads Scripts Google Ads API
Technical skill required None Basic JavaScript Full development capability
Setup time Minutes 30 minutes to a few hours Days to weeks
External data integration No Yes, via URL fetch and Google Sheets Yes, with full flexibility
Multi-account management Per account only MCC-level scripts available Full multi-account support
Custom reporting No Yes, to Sheets or email Yes, to any data warehouse
Complex logic and calculations Single condition only Full JavaScript capabilities Any programming language
Maintenance overhead Minimal Low to moderate Significant

Scripts occupy the middle ground. For most B2B accounts, that middle ground is exactly where the most practical value sits. You get enough flexibility to build custom reporting, multi-condition alerts and calculated bid adjustments without the overhead of maintaining an external application. The Google Ads product blog frequently highlights scripts as a tool that bridges the gap between manual management and full API integration. That framing reflects how most agencies and in-house teams use them in practice.

Common Pitfalls and How to Avoid Them

Scripts are forgiving to work with compared to full API development, but there are mistakes that B2B advertisers commonly make when first adopting them. Understanding these before you start saves time and prevents the kind of automated errors that can affect campaign performance before anyone notices.

The most frequent problems fall into a few categories, all of which are avoidable with some upfront planning.

  • Running scripts without testing in preview mode first. A script that pauses keywords based on flawed logic can take high-performing terms offline. Always preview, check the logs and verify the output before scheduling.
  • Setting bid adjustment scripts to run too frequently. A script that adjusts bids every hour based on the same day’s data will overreact to normal fluctuations. Daily or weekly schedules are usually more appropriate for B2B campaigns with lower conversion volumes.
  • Forgetting to add error handling. If a script encounters an unexpected value, like a division by zero when a keyword has zero conversions, it will fail silently or throw an error that stops execution. Wrapping calculations in try-catch blocks and validating data before using it prevents cascading failures.
  • Not accounting for Google Ads script execution time limits. Scripts have a 30-minute execution limit for single accounts and 60 minutes for MCC scripts. Large accounts with thousands of keywords may need scripts that process data in batches or use more efficient queries.
  • Hardcoding values that should be configurable. Putting your target CPA, email addresses and spreadsheet URLs at the top of the script as named variables makes them easy to update. Burying them inside the logic means anyone modifying the script later has to read through all the code to find what needs changing.

Good script hygiene also includes documenting what each script does, when it runs and who set it up. In a B2B organisation where the person who created a script might move roles or leave the company, having clear documentation prevents automation from becoming a black box that nobody understands or wants to touch. The PPC Hero blog has published several guides on maintaining and documenting Google Ads scripts over time. The underlying message is consistent. Treat scripts as something the whole team needs to understand, not just the person who wrote them.

It’s also worth connecting your paid search automation with insights from conversion rate optimisation work. Scripts can tell you which keywords are converting, but understanding why visitors convert (or don’t) after they click requires looking at the landing page experience alongside the ad data. The two disciplines feed into each other. The best B2B campaigns use both.

Working with an Agency on Google Ads Automation

Continuous optimisation icon representing ongoing Google Ads campaign management

Many B2B organisations run Google Ads alongside Microsoft Ads campaigns, sometimes managing them in-house, sometimes through an agency, sometimes a mix of the two. Scripts can support any of these arrangements, but the approach to building and managing them changes depending on who’s responsible for the account day to day.

When working with an agency, scripts are often one of the first things established during onboarding. Automated reporting scripts give both sides visibility into performance without relying on manual report builds. Alert scripts ensure that the agency and the client are both notified when something needs attention. Bid management scripts document the logic being applied to the account in a way that’s transparent and auditable. The code is right there in the account. The client can see exactly what rules are being followed.

For in-house teams, scripts are a way to reduce the operational burden on people who are often managing paid search alongside other marketing responsibilities. A marketing manager who also handles email campaigns, content planning and event coordination doesn’t have time to log into Google Ads every morning and check each campaign’s performance. A well-configured set of scripts handles the monitoring and flags only the things that need human attention, freeing up time for the strategic decisions that scripts can’t make.

Priority Pixels builds scripts into B2B campaign management as standard rather than treating them as an add-on service. The scripts are documented, shared with the client and designed to continue working if the client ever brings management in-house. That approach reflects a broader principle. Automation should make accounts more transparent and easier to manage, not more opaque or dependent on any single person or agency.







FAQs

What programming language do Google Ads scripts use?

Google Ads scripts use JavaScript as their programming language. They run inside Google’s own scripting environment within the Google Ads platform, so you don’t need to set up an external development environment or manage authentication separately. Basic JavaScript knowledge is enough to get started. Many scripts are available as templates that you can adapt to your own account without writing code from scratch.

Can Google Ads scripts work across multiple accounts?

Yes. If you manage multiple Google Ads accounts through a Manager (MCC) account, you can write MCC-level scripts that run across all linked accounts. These are useful for agencies and B2B organisations managing separate accounts for different brands, regions or business units. MCC scripts have a longer execution time limit of 60 minutes compared to the 30-minute limit for single-account scripts.

How often should Google Ads scripts run for B2B campaigns?

It depends on what the script does. Reporting scripts typically run daily or weekly. Alert scripts for budget overspend or performance drops are most useful when scheduled hourly during working hours. Bid adjustment scripts usually work best on a daily or weekly schedule for B2B accounts, as lower conversion volumes mean that more frequent adjustments can overreact to normal fluctuations in performance data.

Are Google Ads scripts safe to use on live campaigns?

Google Ads scripts include a preview mode that lets you run a script without it making any real changes to your account. This shows you exactly what the script would do, so you can verify the logic before scheduling it. Starting with read-only scripts that report data or send alerts carries no risk at all. For scripts that modify bids or pause keywords, preview mode and careful testing are strongly recommended before scheduling them to run automatically.

Do Google Ads scripts replace automated bidding strategies?

Not necessarily. Automated bidding strategies like Target CPA and Maximise Conversions use Google’s machine learning to adjust bids in real time across every auction. Scripts operate on a schedule and apply rules you define. Many B2B advertisers use automated bidding strategies for their main campaigns and use scripts for supplementary tasks like monitoring, reporting, alerting and making adjustments to areas that automated bidding doesn’t cover, such as pausing underperforming ad groups or managing budget allocation between campaigns.

Avatar for Nathan Yendle Nathan Yendle
Co-Founder & PPC Specialist at Priority Pixels

Nathan Yendle is Co-Founder of Priority Pixels and a Google Partner specialising in PPC strategy and campaign optimisation. With years of experience managing high-performance Google Ads accounts, Nathan focuses on data-driven decisions that deliver measurable results for B2B businesses and public sector organisations. His expertise spans paid search, display, and remarketing, helping clients maximise ROI through strategic planning and continuous improvement.

Related Google Ads Insights

Insights on Google Ads strategy, from campaign structure and bidding to Performance Max and conversion tracking.

Google Ads Remarketing for B2B: How It Drives Conversions
B2B Marketing Agency
Have a project in mind?

Every project starts with a conversation. Ready to have yours?

Start your project
Web Design Agency