Common Issues

This is a compilation of the most common issues raised in the Google Ads scripts forum.

Common JavaScript errors

Script is failing with "Cannot find function: FUNCTION_NAME"

This is usually the result of a misspelled function name in the script.

  1. Check that the function name is spelled correctly and has the correct spelling case; e.g., AdsApp.keywordz() will result in this error, because keywordz is not a valid function in the AdsApp class. AdsApp.Keywords() will also fail due to incorrect spelling case for the keywords() function.

  2. Check that the function exists; e.g., AdsApp.keywords().next() will fail because AdsApp.keywords() returns a KeywordSelector while next() is a method for a KeywordIterator object. The correct code would be AdsApp.keywords().get().next().

My script runs, but doesn't do anything

The most common reason for this issue is that you have a function that performs an operation, but you are not calling it from the main() method. This commonly happens when you copy-paste code snippets from our documentation.

Coding approach Code snippet
Version 1 (doesn't work)
function main() {
  // Call to getAllCampaigns is missing, so this script does nothing.
}

function getAllCampaigns() {
  // AdsApp.campaigns() will return all campaigns that are not
  // removed by default.
  let campaignIterator = AdsApp.campaigns().get();
  console.log('Total campaigns found : ' +
      campaignIterator.totalNumEntities());
  while (campaignIterator.hasNext()) {
    let campaign = campaignIterator.next();
    console.log(campaign.getName());
  }
}
Version 2 (doesn't work)
function main() {
  // Call to getAllCampaigns is missing, so this script does nothing.

  function getAllCampaigns() {
    // AdsApp.campaigns() will return all campaigns that are not
    // removed by default.
    let campaignIterator = AdsApp.campaigns().get();
    console.log('Total campaigns found : ' +
        campaignIterator.totalNumEntities());
    while (campaignIterator.hasNext()) {
      let campaign = campaignIterator.next();
      console.log(campaign.getName());
    }
  }
}
Version 3 (works)
function main() {
  getAllCampaigns();
}

function getAllCampaigns() {
  // AdsApp.campaigns() will return all campaigns that are not removed
  // by default.
  let campaignIterator = AdsApp.campaigns().get();
  console.log('Total campaigns found : ' +
      campaignIterator.totalNumEntities());
  while (campaignIterator.hasNext()) {
    let campaign = campaignIterator.next();
    Logger.log(campaign.getName());
  }
}

I get a "Cannot find function getFinalUrl" error when upgrading my scripts

You may run into this error when changing your script to work with Upgraded URLs. This happens when you replace calls to ad.getDestinationUrl() with ad.getFinalUrl(). getFinalUrl() is part of the AdUrls class, so you'd need to change your code to ad.urls().getFinalUrl():

function main() {
  // Incorrect snippet. getFinalUrl is not a member of the Ad class.
  let ad = AdsApp.ads().get().next();
  let url = ad.getFinalUrl();

  // Correct snippet.
  let ad = AdsApp.ads().get().next();
  let url = ad.urls().getFinalUrl();
}

I get no stats for X

Unavailability of data for a particular entity or date range is a common error you may encounter when running reports or making stats calls. There are several things that you can try:

  1. Check the date range for which you are retrieving stats or running reports.

  2. If you retrieve account-level stats for an Ads Manager script that manages accounts of different currencies, you get back the cost in the currency of the manager account.

  3. Google Ads may not have the data you are looking for yet. See our data freshness guide for details.

How do I use feature X?

See our code snippets and solutions for examples of how to use a particular feature. If you don't find a suitable code snippet, feel free to make a request in the forum.

Still need support?

If you need assistance with an area where we can help, visit the Get Help page.