Rozpocznij
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Aby uruchomić pierwszy skrypt, wykonaj te czynności.
konta Google Ads,
- Zaloguj się na konto Google Ads.
- W menu Narzędzia w panelu nawigacyjnym po lewej stronie wybierz Działania zbiorcze, a następnie Skrypty. Możesz też przejść na tę stronę, wyszukując „Skrypty” na pasku wyszukiwania Google Ads.
- Kliknij ikonę +
aby dodać skrypt. Szablony skryptów możesz przeglądać w menu, ale na potrzeby tego ćwiczenia wybierz „Nowy skrypt”.
- Opcjonalnie możesz podać nazwę skryptu w polu tekstowym „Nazwa skryptu”. Pomoże Ci to zachować porządek i pamiętać, co robi skrypt.
Skopiuj ten kod i wklej go w obszarze edytora, zastępując funkcję main:
function main() {
// Get the campaign names from all the campaigns
const rows = AdsApp.search('SELECT campaign.name FROM campaign');
console.log('My campaigns:');
// Iterate through the campaigns and print the campaign names
for (const row of rows) {
console.log(row.campaign.name);
}
}
Gdy pojawi się odpowiedni komunikat, kliknij Autoryzuj, aby skrypt mógł uzyskać dostęp do konta w Twoim imieniu. Trzeba to zrobić raz dla każdego skryptu.
Aby uruchomić skrypt w trybie podglądu, kliknij Podgląd.
Wyniki pojawią się w panelu Zmiany / Logi. W tym przykładzie nazwy kampanii powinny być widoczne w logach.
Jeśli wyniki podglądu są zadowalające, kliknij Uruchom, aby uruchomić skrypt i otworzyć stronę Historia skryptów. Na tej stronie wyświetlają się ostatnio uruchomione skrypty wraz z informacjami o ich stanie i wynikach.
Aby wyświetlić szczegółowy widok zmian i dzienników, kliknij link w kolumnie Zmiany, który odpowiada właśnie uruchomionemu skryptowi. Powinny pojawić się te same dane wyjściowe logu, które były wyświetlane wcześniej.
Konta menedżera
Aby uruchamiać skrypty Menedżera reklam, musisz najpierw mieć konto menedżera Google Ads.
- Zaloguj się na konto menedżera Google Ads.
- W menu Narzędzia w panelu nawigacyjnym po lewej stronie wybierz Działania zbiorcze, a następnie Skrypty. Możesz też przejść na tę stronę, wyszukując „Skrypty” na pasku wyszukiwania Google Ads.
- Kliknij ikonę +
, aby dodać skrypt. Szablony skryptów możesz przeglądać w menu, ale na potrzeby tego ćwiczenia wybierz „Nowy skrypt”.
- Opcjonalnie możesz podać nazwę skryptu w polu tekstowym „Nazwa skryptu”. Pomoże Ci to zachować porządek i pamiętać, co robi skrypt.
Skopiuj ten kod i wklej go w obszarze edytora, zastępując funkcję main:
function main() {
// Retrieve all children accounts.
const accountIterator = AdsManagerApp.accounts().get();
// Iterate through the account list.
for (const account of accountIterator) {
// Get stats for the child account.
const stats = account.getStatsFor("THIS_MONTH");
// And log it.
console.log(`${account.getCustomerId()},${stats.getClicks()},` +
`${stats.getImpressions()},${stats.getCost()}`);
}
}
Gdy pojawi się odpowiedni komunikat, kliknij Autoryzuj, aby skrypt mógł uzyskać dostęp do konta w Twoim imieniu. Trzeba to zrobić raz dla każdego skryptu.
Aby uruchomić skrypt w trybie podglądu, kliknij Podgląd.
Wyniki pojawią się w panelu Zmiany / Logi. W tym przykładzie w sekcji Dzienniki powinny być widoczne konta dzieci i ich dane.
Jeśli wyniki podglądu są zadowalające, kliknij Uruchom, aby uruchomić skrypt i otworzyć stronę Historia skryptów. Na tej stronie wyświetlają się ostatnio uruchomione skrypty wraz z informacjami o ich stanie i wynikach.
Aby wyświetlić szczegółowy widok zmian i dzienników, kliknij link w kolumnie Zmiany, który odpowiada właśnie uruchomionemu skryptowi. Powinny pojawić się te same dane wyjściowe logu, które były wyświetlane wcześniej.
Więcej przykładowych fragmentów skryptów znajdziesz na naszej stronie z przykładami.
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-09-10 UTC.
[null,null,["Ostatnia aktualizacja: 2025-09-10 UTC."],[[["\u003cp\u003eLaunching your first Google Ads script involves signing in, navigating to the Scripts section, and adding a new script.\u003c/p\u003e\n"],["\u003cp\u003eYou need to copy and paste provided code snippets into the script editor to define its functionality, such as analyzing keywords or account statistics.\u003c/p\u003e\n"],["\u003cp\u003eAuthorization is necessary for the script to access your account data, and preview mode allows for testing before full execution.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Ads manager accounts are required to run Ads Manager scripts, which can access and process data from multiple child accounts.\u003c/p\u003e\n"],["\u003cp\u003eMore script examples and resources are available on the Google Ads Scripts examples page for further exploration and customization.\u003c/p\u003e\n"]]],[],null,["Follow these steps to launch your first script. \n\nGoogle Ads accounts\n\n1. [Sign in](//ads.google.com/) to your Google Ads account.\n2. From the Tools menu in the left navigation, select **Bulk actions** , then **Scripts**. You can also navigate to this page by searching for \"Scripts\" in the Google Ads search bar.\n3. Press the + icon to add a script. You can browse script templates from the drop-down menu, but for the sake of this exercise, select \"New script\".\n4. You can optionally provide a name for your script in the \"Script name\" text field. This can help you stay organized and remember what the script does.\n5. Copy and paste the following code into the editor area, replacing the main\n function:\n\n function main() {\n // Get the campaign names from all the campaigns\n const rows = AdsApp.search('SELECT campaign.name FROM campaign');\n\n console.log('My campaigns:');\n // Iterate through the campaigns and print the campaign names\n for (const row of rows) {\n console.log(row.campaign.name);\n }\n }\n\n6. When prompted, click **Authorize** so the script can access the account on\n your behalf. This has to be done once for each script.\n\n7. Click **Preview** to run the script in [preview mode](/google-ads/scripts/docs/concepts/preview).\n Results will appear in the **Changes** / **Logs** panel. For this example,\n you should see your campaign names displayed in the Logs.\n\n8. When you're happy with the preview results, click **Run** to run your\n script and open the **Script history** page. This page displays the\n most recently run scripts, with information on their status and results.\n\n9. To get a detailed view of changes and logs, click the link in the\n **Changes** column that corresponds to the script you just ran. You should\n see the same log output that was previewed before.\n\nManager accounts\n\nYou must first have a\n[Google Ads manager account](//support.google.com/google-ads/answer/6139186)\nto run Ads Manager scripts.\n\n1. [Sign in](//ads.google.com/) to your Google Ads manager account.\n2. From the Tools menu in the left navigation, select **Bulk actions** , then **Scripts**. You can also navigate to this page by searching for \"Scripts\" in the Google Ads search bar.\n3. Press the + icon to add a script. You can browse script templates from the drop-down menu, but for the sake of this exercise, select \"New script\".\n4. You can optionally provide a name for your script in the \"Script name\" text field. This can help you stay organized and remember what the script does.\n5. Copy and paste the following code into the editor area, replacing the main\n function:\n\n function main() {\n // Retrieve all children accounts.\n const accountIterator = AdsManagerApp.accounts().get();\n\n // Iterate through the account list.\n for (const account of accountIterator) {\n // Get stats for the child account.\n const stats = account.getStatsFor(\"THIS_MONTH\");\n // And log it.\n console.log(`${account.getCustomerId()},${stats.getClicks()},` +\n `${stats.getImpressions()},${stats.getCost()}`);\n }\n }\n\n6. When prompted, click **Authorize** so the script can access the account on\n your behalf. This has to be done once for each script.\n\n7. Click **Preview** to run the script in [preview mode](/google-ads/scripts/docs/concepts/preview).\n Results will appear in the **Changes** / **Logs** panel. For this example,\n you should see your children accounts and their metrics displayed in the\n Logs.\n\n8. When you're happy with the preview results, click **Run** to run your\n script and open the **Script history** page. This page displays the\n most recently run scripts, with information on their status and results.\n\n9. To get a detailed view of changes and logs, click the link in the\n **Changes** column that corresponds to the script you just ran. You should\n see the same log output that was previewed before.\n\nFor more sample script snippets, check out our\n[examples page](/google-ads/scripts/docs/examples)."]]