Để thảo luận và đưa ra ý kiến phản hồi về các sản phẩm của chúng tôi, hãy tham gia kênh Discord chính thức của Google Ads trong máy chủ Cộng đồng quảng cáo và đo lường của Google.
Tập lệnh không hoạt động với lỗi "Không tìm thấy hàm: FUNCTION_NAME"
Điều này thường xảy ra do tên hàm bị viết sai trong tập lệnh.
Kiểm tra để đảm bảo tên hàm được viết đúng chính tả và có trường hợp chính tả chính xác; ví dụ: AdsApp.keywordz() sẽ dẫn đến lỗi này, vì keywordz không phải là một hàm hợp lệ trong lớp AdsApp.
AdsApp.Keywords() cũng sẽ không hoạt động do trường hợp chính tả không chính xác cho hàm keywords().
Kiểm tra để đảm bảo hàm này tồn tại; ví dụ: AdsApp.keywords().next() sẽ không thành công vì AdsApp.keywords() trả về KeywordSelector trong khi next() là phương thức cho đối tượng KeywordIterator.
Mã chính xác sẽ là AdsApp.keywords().get().next().
Tập lệnh của tôi chạy nhưng không làm gì cả
Nguyên nhân phổ biến nhất dẫn đến vấn đề này là do bạn có một hàm thực hiện một thao tác, nhưng bạn không gọi hàm đó từ phương thức main(). Điều này thường xảy ra khi bạn sao chép và dán đoạn mã từ tài liệu của chúng tôi.
Phương pháp lập trình
Đoạn mã
Phiên bản 1 (không hoạt động)
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());
}
}
Phiên bản 2 (không hoạt động)
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());
}
}
}
Phiên bản 3 (hoạt động)
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());
}
}
Tôi gặp lỗi "Không tìm thấy hàm getFinalUrl" khi nâng cấp tập lệnh
Bạn có thể gặp phải lỗi này khi thay đổi tập lệnh để hoạt động với URL được nâng cấp. Lỗi này xảy ra khi bạn thay thế các lệnh gọi đến ad.getDestinationUrl() bằng ad.getFinalUrl().
getFinalUrl() là một phần của lớp AdUrls, vì vậy, bạn cần thay đổi mã của mình thành ad.urls().getFinalUrl():
functionmain(){// Incorrect snippet. getFinalUrl is not a member of the Ad class.letad=AdsApp.ads().get().next();leturl=ad.getFinalUrl();// Correct snippet.letad=AdsApp.ads().get().next();leturl=ad.urls().getFinalUrl();}
Tôi không thấy số liệu thống kê cho X
Việc không có dữ liệu cho một thực thể hoặc phạm vi ngày cụ thể là một lỗi thường gặp mà bạn có thể gặp phải khi chạy báo cáo hoặc thực hiện lệnh gọi số liệu thống kê. Bạn có thể thử một số cách sau:
Kiểm tra phạm vi ngày mà bạn đang truy xuất số liệu thống kê hoặc chạy báo cáo.
Nếu truy xuất số liệu thống kê ở cấp tài khoản cho một tập lệnh Ads Manager quản lý các tài khoản có đơn vị tiền tệ khác nhau, bạn sẽ nhận được chi phí bằng đơn vị tiền tệ của tài khoản người quản lý.
Hãy xem đoạn mã và giải pháp của chúng tôi để biết ví dụ về cách sử dụng một tính năng cụ thể. Nếu không tìm thấy đoạn mã phù hợp, bạn có thể yêu cầu trên diễn đàn.
Bạn vẫn cần được hỗ trợ?
Nếu bạn cần được trợ giúp trong một lĩnh vực mà chúng tôi có thể hỗ trợ, hãy truy cập vào trang Yêu cầu trợ giúp.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-27 UTC."],[[["\u003cp\u003eThis page addresses common Google Ads script errors and questions, focusing on general JavaScript issues and not solution-specific ones.\u003c/p\u003e\n"],["\u003cp\u003eCommon errors include misspelled function names, scripts that run but don't execute actions, and issues related to Upgraded URLs.\u003c/p\u003e\n"],["\u003cp\u003eScripts may fail to retrieve stats due to incorrect date ranges, currency mismatches in Ads Manager accounts, or Google Ads data processing delays.\u003c/p\u003e\n"],["\u003cp\u003eFor specific feature usage, refer to the provided code snippets and solutions, or request help in the forum.\u003c/p\u003e\n"],["\u003cp\u003eFor further assistance, consult the designated "Get Help" page for support resources.\u003c/p\u003e\n"]]],[],null,["# Common Issues\n\nThis is a compilation of the most common issues raised in the\n[Google Ads scripts forum](//groups.google.com/forum/#!forum/adwords-scripts).\n| **Note:** This page only lists general questions related to Scripts. If your question is specific to a [solution](/google-ads/scripts/docs/solutions), refer to the corresponding solutions page.\n\nCommon JavaScript errors\n------------------------\n\n### Script is failing with \"Cannot find function: FUNCTION_NAME\"\n\nThis is usually the result of a misspelled function name in the script.\n\n1. Check that the function name is spelled correctly and has the correct\n spelling case; e.g., `AdsApp.keywordz()` will result in this error, because\n `keywordz` is not a valid function in the\n [AdsApp](/google-ads/scripts/docs/reference/adsapp/adsapp) class.\n `AdsApp.Keywords()` will also fail due to incorrect spelling case for the\n `keywords()` function.\n\n2. Check that the function exists; e.g., `AdsApp.keywords().next()` will fail\n because\n [`AdsApp.keywords()`](/google-ads/scripts/docs/reference/adsapp/adsapp#keywords)\n returns a\n [`KeywordSelector`](/google-ads/scripts/docs/reference/adsapp/adsapp_keywordselector)\n while `next()` is a method for a [`KeywordIterator` object](/google-ads/scripts/docs/reference/adsapp/adsapp_keyworditerator).\n The correct code would be `AdsApp.keywords().get().next()`.\n\n### My script runs, but doesn't do anything\n\nThe most common reason for this issue is that you have a function that performs\nan operation, but you are not calling it from the `main()` method. This\ncommonly happens when you copy-paste\n[code snippets](/google-ads/scripts/docs/examples) from our documentation.\n\n| Coding approach | Code snippet |\n|------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **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()); } } ``` |\n| **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()); } } } ``` |\n| **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()); } } ``` |\n\n### I get a \"Cannot find function getFinalUrl\" error when upgrading my scripts\n\nYou may run into this error when changing your script to work with [Upgraded\nURLs](//support.google.com/google-ads/answer/6049217). This happens when you\nreplace calls to `ad.getDestinationUrl()` with `ad.getFinalUrl()`.\n`getFinalUrl()` is part of the\n[AdUrls](/google-ads/scripts/docs/reference/adsapp/adsapp_adurls) class,\nso you'd need to change your code to `ad.urls().getFinalUrl()`: \n\n function main() {\n // Incorrect snippet. getFinalUrl is not a member of the Ad class.\n let ad = AdsApp.ads().get().next();\n let url = ad.getFinalUrl();\n\n // Correct snippet.\n let ad = AdsApp.ads().get().next();\n let url = ad.urls().getFinalUrl();\n }\n\n### I get no stats for X\n\nUnavailability of data for a particular entity or date range is a common error\nyou may encounter when running reports or making stats calls. There are several\nthings that you can try:\n\n1. Check the date range for which you are retrieving stats or running reports.\n\n2. If you retrieve account-level stats for an Ads Manager script that manages\n accounts of different currencies, you get back the cost in the currency of\n the manager account.\n\n3. Google Ads may not have the data you are looking for yet. See our\n [data freshness guide](//support.google.com/google-ads/answer/2544985) for\n details.\n\n### How do I use feature X?\n\nSee our [code snippets](/google-ads/scripts/docs/examples) and\n[solutions](/google-ads/scripts/docs/solutions) for examples of how to\nuse a particular feature. If you don't find a suitable code snippet, feel free\nto make a request in the forum.\n\n### Still need support?\n\nIf you need assistance with an area where we can help, visit the\n[Get Help](/google-ads/scripts/docs/support/get-help) page."]]