This code is a Google Ads script designed to manage...
August 26, 2025 at 08:50 PM
This code is a Google Ads script designed to manage negative keyword lists (NKLs) for advertising campaigns. Here's what it does in a high-level, step-by-step manner:
1. Setup and Initialization
- The script defines constants like
propertyId
,apiKey
, and names for two negative keyword lists (nklName
andnklPennyName
). - It initializes iterators for campaign lists:
nklCampaignIterator
: Filters to campaigns that are enabled and do not contain a specific marker string ("_adai") in their names.nklPennyCampaignIterator
: Retrieves enabled campaigns whose names include the "pennyString" marker (indicating penny campaigns).
2. Retrieve or Create Negative Keyword Lists (NKLs)
- Using
GetNegativeKeywordList
, the script fetches existing negative keyword lists by name or prepares new ones (nkl
andnklPenny
).
3. API Request to Fetch Data
GetQueries()
sends an API request with the providedpropertyId
andapiKey
to fetch campaign data and configuration info (e.g., keywords).- If the API responds with an HTTP 200 status:
- It parses the JSON response.
- If the response indicates
doUpdate
istrue
:- Clear existing keywords from the negative keyword lists (
ClearNKLs
). - Add new negative and positive keywords (
ProcessNegativeKeywords
).
- Clear existing keywords from the negative keyword lists (
- If the JSON response is malformed or does not have the expected format, the script clears the negative keyword lists.
4. Campaign-Level Negative Keyword Management
- The script attaches negative keyword lists to campaigns based on their names:
nklCampaignIterator
: Attaches the standard negative keyword list (nkl
) to campaigns not classified as penny campaigns.nklPennyCampaignIterator
: Attaches the "penny" negative keyword list (nklPenny
) to campaigns classified as penny campaigns.
5. Clean Campaign Associations
- Removes associations between campaigns and irrelevant negative keyword lists:
CleanNKLCampaigns()
: Ensures campaigns not targeted for the standard NKL or classified as penny campaigns are disassociated from thenkl
.CleanPennyNKLCampaigns()
: Ensures only penny campaigns remain linked tonklPenny
.
6. Removing Existing Keywords
RemoveNegativeKeywords()
removes all negative keywords from a given list.
7. Processing Queries
ProcessAllQueries()
iterates through query results from the API response.- For each query, it generates a Google Ads report, converts the data to JSON, and uploads it to the specified endpoint using signed URLs (
PutToS3()
).
- For each query, it generates a Google Ads report, converts the data to JSON, and uploads it to the specified endpoint using signed URLs (
8. Helper Functions
PutToS3()
: Compresses and uploads JSON reports to an S3-compatible storage endpoint using pre-signed AWS URLs.GetAdsReport()
: Runs custom Google Ads reports based on API-returned queries, extracting specific columns into an object format.GetNegativeKeywordList()
: Fetches a negative keyword list from Google Ads by name, returning the first match.ClearNKLs()
: Deletes all negative keywords from specified negative keyword lists.
Key Functionalities Provided by the Script
- Negative Keyword Automation: Handles the creation, removal, and association of negative keyword lists to campaigns based on conditions.
- API Integration: Retrieves campaign-specific configurations (e.g., keywords, queries) from an external system via an API.
- Campaign Segmentation: Differentiates campaign types (e.g., "penny" campaigns and standard campaigns) using their names.
- Data Cleaning: Ensures consistent keyword list associations by clearing or enforcing rules for which campaigns should be linked to which NKLs.
- Report Upload: Sends summarized campaign or query data to an S3-compatible endpoint for further analysis or usage.
Purpose
This script appears to be part of a workflow for managing Google Ads campaigns and ensuring compliance with automated keyword rules. It uses external data (via an API) to dynamically update campaign configurations and sends logs or reports to a backend system (likely for auditing or monitoring purposes).
Generate your own explanations
Download our vscode extension
Read other generated explanations
Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node