Create Google Advertisements Scripts by way of GenAI


I’ve addressed the advantages of Google Advertisements scripts to automate features of account administration. Producing customized scripts is now a lot simpler with generative AI platforms.

Scripts can transcend automation to unravel issues. For instance, it’s not at all times evident when an account stops serving adverts. The cost technique might fail, or Google might reject them. The “Account Down” script runs hourly and sends an e-mail when an account hasn’t seen an impression in a delegated interval.

I’ve struggled with campaigns that set the next goal value per acquisition than the price range. It’s not at all times apparent. A price range could be $500, however the tCPA is $600. The tCPA must be not less than 3 times the price range in my expertise.

AI for Advert Scripts

Right here’s the place AI is available in. Instruments reminiscent of ChatGPT, Gemini, and Claude (my favourite) can generate scripts rapidly.

Sample prompt in Claude for the tCPA mismatch and Claude's response.

Generative AI platforms reminiscent of Claude can produce scripts rapidly.

Right here’s my immediate in Claude to create a script:

Please write a Google Advertisements script that evaluations all campaigns and sends an e-mail alert when the tCPA is larger than the marketing campaign price range.

Right here’s Claude’s response:

Google Advertisements tCPA Alert Script

This script:

1. Iterates by means of all enabled campaigns in your Google Advertisements account
2. Identifies campaigns utilizing Goal CPA bidding technique
3. Compares every marketing campaign’s tCPA worth in opposition to its day by day price range
4. Creates a listing of campaigns the place tCPA exceeds the price range
5. Sends you an e-mail alert with particulars if any campaigns meet this situation

I pasted the script into Google Advertisements and obtained an error.

3/5/2025 3:47:20 PM TypeError: marketing campaign.bidding(...).get isn't a perform
at major (Code:39:40)
at Object. (adsapp_compiled:20555:54)

I then prompted Claude to repair the error. Right here’s Claude’s response:

Google Advertisements tCPA Alert Script – Mounted

I’ve fastened the error by correcting how the script retrieves the goal CPA worth. The difficulty was with the road `var bidding = marketing campaign.bidding().get();` which was utilizing an incorrect technique name.

Key modifications made:

1. Changed the problematic technique chain with a direct name to `marketing campaign.bidding().getTargetCpa()`

2. Added error dealing with with strive/catch blocks to gracefully deal with completely different API variations and bidding technique configurations

3. Added assist for retrieving tCPA from shared bidding methods (which have a unique entry technique)

4. Added validation to make sure tCPA was efficiently retrieved earlier than evaluating it to the price range

The script — obtain it right here — now runs in Google. I solved an issue by means of a collection of prompts.

Not good

My subsequent AI activity was to acquire a script that recognized all energetic advert teams in dwell campaigns with no impressions in 21 days. The alert would set off me to analyze the trigger.

Claude’s script labored, nevertheless it had two errors:

  • It defaulted to any interval, not 21 days.
  • It included customized experiments that ended 21 or extra days beforehand. Experiments run just for a delegated interval, however the script included them as regular campaigns.

After sharing these errors and receiving substitute scripts, Claude produced new errors for invalid inputs. I ended the session with out securing the script I wished.

It’s a useful reminder that AI isn’t at all times as productive as people. A developer might seemingly arrange this script with out the prolonged back-and-forth.

Claude’s script for tCPA conflicts labored. The no-impressions script didn’t.

Monitor the sudden

The ultimate script I created addressed rejected adverts. Advertisers ought to monitor not simply the adverts however rejected key phrases and audiences, which happen sometimes.

Any script in Google Advertisements occasions out after 30 to 60 minutes. I first prompted Claude to determine disapproved advert property (sitelinks, callouts, and extra). Fearing a timeout, I opted for 2 separate scripts.

Dialog showing the prompt and Claude's response.

The follow-up script and response centered on “restricted” statuses.

Right here’s the immediate for the non-asset disapproval.

Please replace this script so it solely seems to be at disapproved adverts, key phrases, and audiences. Entities with “restricted” standing shouldn’t be included.

And Claude’s response:

I’ll replace the script to solely embrace objects with “DISAPPROVED” standing and exclude these with “LIMITED” or some other non-disapproved standing. Right here’s the modified model:

Google Advertisements Script for Disapproved Objects Solely. Click on to open code.

The important thing modifications I made to the script:

1. Modified the situation checks for adverts from:

```javascript
if (advert.getPolicyApprovalStatus() != 'APPROVED') {
```

to:

```javascript
if (advert.getPolicyApprovalStatus() == 'DISAPPROVED') {

Obtain the script.

No limits

My instance scripts above alert advertisers by way of e-mail, however I might have prompted Claude to output to a spreadsheet as an alternative. I might have included paused entities. The probabilities are seemingly limitless.

Leave a Reply

Your email address will not be published. Required fields are marked *