Page Summary
-
Common Google Ads script errors include misspelled function names, functions not being called from the
main()method, and incorrect usage of methods likegetFinalUrl(). -
Scripts may run but not perform actions if operations are not called from the
main()method. -
Issues with retrieving stats or running reports can be due to the date range, currency differences in manager accounts, or data freshness.
-
For examples on how to use specific features, refer to code snippets and solutions provided in the documentation.
-
Additional support is available through the Get Help page and Discord community.
This is a compilation of common issues raised by Google Ads scripts developers.
Common JavaScript errors
Here are some common JavaScript errors.
Script fails with "Cannot find function: FUNCTION_NAME"
This is usually the result of a misspelled function name in the script.
-
Check that the function name is spelled correctly and has the correct spelling case; e.g.,
AdsApp.keywordz()will result in this error, becausekeywordzis not a valid function in the AdsApp class.AdsApp.Keywords()will also fail due to incorrect spelling case for thekeywords()function. -
Check that the function exists; e.g.,
AdsApp.keywords().next()will fail becauseAdsApp.keywords()returns aKeywordSelectorwhilenext()is a method for aKeywordIteratorobject . The correct code would beAdsApp.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 getCampaigns is missing, so this script does nothing.
}
function getCampaigns() {
// AdsApp.campaigns() will return all Search and Display 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 getCampaigns is missing, so this script does nothing.
function getCampaigns() {
// AdsApp.campaigns() will return all Search and Display 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() {
getCampaigns();
}
function getCampaigns() {
// AdsApp.campaigns() will return all Search and Display 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:
-
Check the date range for which you are retrieving stats or running reports.
-
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.
-
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 discord .
Still need support?
If you need assistance with an area where we can help, visit the Get Help page.

