Join our virtual event and learn from industry experts what the future of ecommerce holds for you.
Join our virtual event and learn from industry experts what the future of ecommerce holds for you.

Text Ad Builder Script

Google Ads script to generate text ads from spreadsheet data

Text Ad Builder Script illustration

Looking for scripts to automate text ad generation?

Close the automation circle by building text ads. The “Text Ad Builder” script generates text ads based on external spreadsheet data. You can use this spreadsheet template but we strongly suggest using our “Shopping Explorer” script instead to identify successful Shopping queries which can then be added as keywords — a light version of our Keyword Sourcing module. Depending on their length, well performing search terms will also be pushed into headline 1, headline 2 and/or the description, while the price retrieved from the exploration script can be used as adParam.

Download script and start optimizing

No commitments & no hidden costs — just a great script.

Success image

Thank you!

You can get the script code below

Arrow down icon
 * Text Ad Builder Script        . * ・ 。゚☆━੧[ ✪ ᗜ ✪ ]⊃
 * Overview: Close the automation circle by building text ads from the hidden
 * gems in your Google Shopping account. This script generates text ads based on
 * an external spreadsheet. We suggest the prior use of our “Shopping Explorer”
 * script to identify successful Shopping queries which can then be used as
 * keywords and in the ad text.
 * Author: smec Team []
 * Version: 1.0
 * Changelog:
 * - version 1.0
 *  - Released initial version.
 * Updated: 9-05-2018
 * Twitter: @smec
 * Email: [email protected]
 * (c) Smarter Ecommerce GmbH. All rights reserved.
 * License: MIT

/* ============================== Configuration ============================= */

//adjust the textAds to your needs in the textAdBuilder-section marked below

// Campaign you want the Adgroups and TextAds to be created in
// Google-Spreadsheet where the exploration-script saved the item-data

// Fallback ad title in case the query from the source is too long.

// Sets the second part of the new ad's headline to the specified value.
var HEADLINE_PART_2 = "YOUR_HEADLINE_PART_2_HERE"; //(e.g. "Buy now at our store")

// Adds additional text to the new ad's description.
// Additionally to this text, the script appends AdParam with price at the end.
var DESCRIPTION_ADDITION = "YOUR_DESCRIPTION_ADDITION"; // (E.g. " by BrandName. Buy now for ")
// Example final ad description: <Search query> by BrandName. Buy now for 25€ !

// Sets the first path that appears with the new ad's displayed URL.
var PATH_1 = "YOUR_PATH_1"; //(E.g. Soccer)
var PATH_2 = "YOUR_PATH_2"; //(E.g. Store)

/* =============================== Execution ================================ */

function main() {
  var spreadsheet = SpreadsheetApp.openById(SPREADSHEET_ID);
  var data = spreadsheet.getDataRange().getValues();

  var campaignIterator = AdWordsApp.campaigns().withIds([CAMPAIGN_ID]).get();
  if (campaignIterator.totalNumEntities() > 1) {
    throw new Error("Provided an invalid number of Campaign Ids");

  while (campaignIterator.hasNext()) {
    var campaign =;
    for (var i = 1; i < data.length; i++) {
      var cpc = parseFloat(data[i][11]);
      if (cpc !== undefined && cpc > 0) {
        var query = data[i][3];
        var itemId = data[i][2];
        var adGroupName = itemId + " - " + query;

        var checkAdGroup = campaign.adGroups()
          .withCondition("Name = '" + adGroupName + "'").get();

        // Check if adGroup already exists.
        if (checkAdGroup.totalNumEntities() === 0) {
          var adGroupOperation = campaign.newAdGroupBuilder()
          var adGroup = adGroupOperation.getResult();
          var keywordOperation = adGroup.newKeywordBuilder()

          var keyword = keywordOperation.getResult();
          keyword.setAdParam(1, data[i][9] + CURRENCY_FOR_ADPARAM);

          // Build text ads
          if (query.length < 30) {
            // Default case (query is below 30 symbols).
            .withDescription(capitalizeString(query) + DESCRIPTION_ADDITION + "{param1:less money} !")
          } else {
            // Fallback case when the query is too long.
            .withDescription(capitalizeString(query) + DESCRIPTION_ADDITION + "{param1:less money} !")

function capitalizeString(string) {
  return string.replace(/\b\w/g, function(l){ return l.toUpperCase(); });

The code was successfully copied to your Clipboard.

Popular Google Ads Scripts

Martin Röttgerding

“Automation can take your PPC efforts to the next level – if you’re doing it right.”

Martin Röttgerding, Head of SEA – Bloofusion Germany

Book a personalized demo

Find out what the AdEngine can do for your business