Insights

An Ads Script Renaissance is Here - Join in with AI

How will this post help me?

If you've ever felt left out of the Google Ads scripting world due to a lack of coding experience, this post is for you.

We'll dive into how to use AI, specifically GPT-4, to create Google Ads scripts without coding skills.

By the end, you'll have the power to participate in the scripting renaissance and automate your Google Ads tasks with ease.


Table of Contents

What Sparked Using ChatGPT for Ad Scripts

How to Create a Google Ads Script with ChatGPT

Finalized Script

The Next Step

For the last few years, major innovations in Google Ads Scripts have lain dormant as advertisers leaned into new, automated functions for needs that Google Ads Scripts previously provided.

Frankly, we were able to measure & drive performance without scripts do to the improvements in: 

  • The Google Ads integration with Google Data Studio (now Looker Data Studio) for reporting
  • The efficacy of Smart Bidding - which improved significantly in 2020 leading into 2021
  • Strong performance from automated formats such as RSAs, Smart Shopping (R.I.P.), and Performance Max

But a few renegades recently stood out, thought differently, and re-kindled the fire for the once BURNING topic of Google Ads Scripts:

After testing these two, I found myself hungry for more…

But how could I, a lowly practitioner, participate in this scripts renaissance?

In Walks GPT4

Oh, hey GPT 4! What’s up?

“Hello! I'm just a bunch of algorithms and data, so I don't have feelings or consciousness, but I'm here and ready to help you. What can I assist you with today? 😊”

Phew. Good, it’s not sentient yet.

But, it does have some great new capabilities with coding! In fact, meeting with my co-worker Jordan as he was developing this process for categorizing keywords with ChatGPT, he showed me how I could have Chat GPT write JavaScript, python, and more for various needs.

I knew I could use this for Google Ad Scripts….BUT HOW?!

Bumping into an Old Friend

It was only a few weeks later that I was working on efforts to amplify our quality assurance process on the Seer Paid Media team when I was reminded of this old script for spell checking ad copy

It seemed odd that no one had ever updated it for Responsive Search Ads, or the various other ad types that include ad copy like Responsive Display Ads. 

And it was here that the dots connected:

Scripts renaissance… ChatGPT for coding…. A script that no one shared… EUREKA!!

This was my opportunity to use ChatGPT to participate in the scripts renaissance.

[Spoiler Alert:] We share our current script version (super basic) at the bottom of this post.

There will be one other version between here and there so you can see where ChatGPT makes mistakes. 

 

How to Create a Google Ads Script with ChatGPT

To show the process of how to create a Google Ads Script within ChatGPT, we’re going to use the example mentioned above: 

A Google Ads Script to fix spelling mistakes in Responsive Display Ads (RSAs)

Say goodbye to spelling mistakes in your Responsive Display Ads (RSAs) with Google Ads Script - streamlining the spell-checking process and eliminating errors in a snap. 

Step 0: Tools Needed

Tool

Cost

Google Ads Account

Whatever you’d like to spend on ads! Be careful out there 🙂

Google Sheets

Free

Microsoft Azure account with a Bing Search resource

There is a free tier with limited functionality


This experiment used a standard paid tier

  • $0.90 for 142 responsive search ads
  • $0.006 per ad, per run time
  • Can be pricey for large accounts
  • Working to optimize costs as we iterate

ChatGPT Plus (access to GPT-4)

$20 / month

Step 1: Use ChatGPT to generate your Google Ads Script

I opened up ChatGPT, cracked the ol’ knuckles like a pro, and typed out the following prompt:

In 2016, a Google Ads script was released that could spellcheck ad copy for expanded text ads.  This used the Bing Spellcheck API (https://www.microsoft.com/en-us/bing/apis/bing-spell-check-api) to reference expanded text ad copy and identify spelling errors. 

Since Google released responsive text ads, I haven't seen a refreshed version of this script. 

Could you help me write a script to spellcheck responsive text ads?

Chat GPT immediately responded with the first iteration of the script (note: do not use this script as more tweaking is required. Jump here to get the finalized version of this script):

function main() {

    var BING_SPELLCHECK_API_ENDPOINT = 'https://api.cognitive.microsoft.com/bing/v7.0/spellcheck?mode=proof';

    var BING_SPELLCHECK_API_KEY = 'YOUR_BING_API_KEY_HERE';  // Replace with your Bing Spellcheck API key

    // Fetch responsive text ads

    var iterator = AdsApp.ads()

        .withCondition('Type = "RESPONSIVE_SEARCH_AD"')

        .withCondition('Status = "ENABLED"')

        .get();

    while (iterator.hasNext()) {

        var ad = iterator.next();

        var adAttributes = ad.getAdAttributes();

        for (var attribute in adAttributes) {

            if (adAttributes.hasOwnProperty(attribute)) {

                var textToCheck = adAttributes[attribute].stringValues[0];  // Assuming there's only one string value for simplicity

                if (textToCheck) {

                    var result = spellcheckText(textToCheck, BING_SPELLCHECK_API_ENDPOINT, BING_SPELLCHECK_API_KEY);

                    if (result) {

                        Logger.log('Possible spelling mistake in Ad ID ' + ad.getId() + ': ' + result);

                    }

                }

            }

        }

    }

}

 

function spellcheckText(text, endpoint, apiKey) {

    var options = {

        method: 'post',

        headers: {

            'Content-Type': 'application/x-www-form-urlencoded',

            'Ocp-Apim-Subscription-Key': apiKey

        },

        payload: {

            'text': text

        }

    };

 

    var response = UrlFetchApp.fetch(endpoint, options);

    var jsonResponse = JSON.parse(response.getContentText());

 

    if (jsonResponse.flaggedTokens && jsonResponse.flaggedTokens.length > 0) {

        return jsonResponse.flaggedTokens.map(function (token) {

            return token.token;

        }).join(", ");

    }

 

    return null;

}

Like many before me, I wanted to export my results to a Gsheet, so I asked ChatGPT to take care of that part for me. 

It expanded the script with the line below, and had me add the following headers: Ad ID, Current Ad Text, and Spelling Suggestion.

var SPREADSHEET_URL = 'YOUR_SPREADSHEET_URL_HERE';  // Replace with your Google Sheet URL

After a few back-and-forths making tweaks to what I wanted as I read through the results, I was ready to put this to action. 

First, I would need my Bing Search resource in the Azure Portal. Bear with me folks - I promise it’s worth it.

Step 2: Setting Up Your Bing Search API Resource

Proceed with caution: this was the main area where GPT drove me the wrong way.

At first, ChatGPT drove me to the Microsoft Cognitive Search API to create a resource.

I created it, generated keys, and tested the script a few times but kept getting a “401” error, which meant I was using an invalid key or incorrect endpoint.

I did more searching online and found that Microsoft had recently moved the Spellcheck V7 endpoint to the Bing Search API, so I would need to modify the code. 

After rectifying that issue, here are the steps I took to create a Bing Search API resource:

  1. Create an account at portal.azure.com
    1. Must add a credit card. It won’t be charged unless you select a pay-as-you-go plan.
  2. On the homepage, click “Create a Resource”

    image6-1
  3. Search for “bing search” and select the latest version of Bing Search API (In this case, it was v7)

    image7-1
  4. Create a Bing Search Resource
      1. Start a brand new resource group name and instance name*
      2. Select your region
      3. Select your Pricing tier. 

*You can make the names whatever you want, but you can’t use spaces or special characters. See below for an example:

image1-Oct-03-2023-01-21-32-2092-AM

 

5. After you click “Next”, you’ll need to create Tags. This is another area where you have to add something, but it doesn’t matter what. Here are some examples:


image2-Oct-03-2023-01-21-32-2095-AM

 

[Tip:] Agree to the terms on the “basics” tab of the creation workflow. That’s here:


image5-1

6. Now, click Create 🙂

7. On the Overview page that follows, click “Go to resource”


image4-1

8. On the far right of the next screen, click “click here to manage keys” to get your key for the Bing Search API.


image3-2

9. It’s time to rock and roll!

Step 3: Deploy the Script

Young Jedi, you are ready. Now you have everything you need to deploy the script!

  1. Create a gsheet with the following column names: 
      1. Campaign
      2. Ad Group
      3. Ad ID
      4. Ad Type 
      5. Ad Text 
      6. Spelling Suggestion
  2. Add this script to your Google Ads account:

var BING_SPELLCHECK_API_ENDPOINT = 'https://api.bing.microsoft.com/v7.0/SpellCheck';

var BING_SPELLCHECK_API_KEY = 'INSERT_KEY';  // Replace with your Bing Spellcheck API key

var SPREADSHEET_URL = 'INSERT_SPREADSHEET_URL';  // Replace with your Google Sheet URL

 

function main() {

    var sheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL).getActiveSheet();

    

    checkAdType('RESPONSIVE_SEARCH_AD', sheet);

    checkAdType('RESPONSIVE_DISPLAY_AD', sheet);

}

 

function checkAdType(adType, sheet) {

    var iterator = AdsApp.ads()

        .withCondition('Type = "' + adType + '"')

        .withCondition('Status = "ENABLED"')

        .get();

 

    while (iterator.hasNext()) {

        var ad = iterator.next();

        var adAttributes = (adType === 'RESPONSIVE_SEARCH_AD') ? ad.getHeadlines() : [ad.getShortHeadline(), ad.getLongHeadline(), ad.getDescription()];

 

        adAttributes.forEach(function(attribute) {

            if (attribute) {

                var result = spellcheckText(attribute, BING_SPELLCHECK_API_ENDPOINT, BING_SPELLCHECK_API_KEY);

                if (result) {

                    sheet.appendRow([

                        ad.getCampaign().getName(),

                        ad.getAdGroup().getName(),

                        ad.getId(),

                        adType,

                        attribute,

                        result.join(", ")

                    ]);

                }

            }

        });

    }

}

 

function spellcheckText(text, endpoint, apiKey) {

    var options = {

        method: 'post',

        headers: {

            'Content-Type': 'application/x-www-form-urlencoded',

            'Ocp-Apim-Subscription-Key': apiKey

        },

        payload: {

            'text': text

        }

    };

 

    var response = UrlFetchApp.fetch(endpoint, options);

    var jsonResponse = JSON.parse(response.getContentText());

 

    if (jsonResponse.flaggedTokens && jsonResponse.flaggedTokens.length > 0) {

        return jsonResponse.flaggedTokens.map(function (token) {

            return token.token;

        });

    }

 

    return null;

}

AND scripter beware: DO NOT set for recurring unless A.) you’re on the free version or B.) you got the $$$$

 

Now it’s your turn.

You’ve seen how a coding know-nothing went from 0-60 on writing a Google Ads script. You can do the same and go Super Saiyan on scripts. Just be kind, and please share your journey 🙂

The force be with you.

We love helping marketers like you.

Sign up for our newsletter for forward-thinking digital marketers.

Chris Evans
Chris Evans
Sr. Lead, Paid Media