How to create Selectors and Iterators for Performance Max?
Unfortunately, only search and display campaigns are supported in the standard campaign selector.
Google Ads Scripts provides separate methods and classes for accessing Performance Max campaign data. Here’s how to define Selectors and Iterators for Performance Max campaigns using the latest version:
1. Define the Selector
Using the new methods provided by Google Ads Scripts we will define a selector that returns an iterator to retrieve Performance Max campaigns.
2. Create the Iterator
We will use the iterator to loop through the selected campaigns and perform actions or extract information.
Example: Retrieve Performance Max Campaigns
Step-by-Step Breakdown
-
- Define the Selector for Performance Max Campaigns:
- Use the
AdsApp.performanceMaxCampaigns()
method to get the campaign selector. - Apply the necessary filters to select only enabled Performance Max campaigns.
- Use the
- Create the Iterator:
- Use the
get()
method to fetch the iterator. - Loop through the results in the iterator using the
hasNext()
andnext()
methods.
- Use the
- Log the Campaign Details:
- Extract the campaign name and ID for each campaign and log them.
- Define the Selector for Performance Max Campaigns:
Here’s the complete script :
Explanation
-
- Selector Definition:
AdsApp.performanceMaxCampaigns()
initializes the Performance Max campaign selector..withCondition("Status = ENABLED")
ensures only enabled campaigns are selected..orderBy("Name ASC")
sorts the campaigns by name in ascending order..withLimit(50)
limits the number of campaigns retrieved to 50 (you can adjust this as needed).
- Iterator Creation:
campaignSelector.get()
fetches the campaigns based on the defined selector criteria, it returns the iterator.while (campaignIterator.hasNext())
loops through the campaigns.campaignIterator.next()
retrieves the next campaign in the list.
- Logging Campaign Details:
campaign.getName()
andcampaign.getId()
retrieve the name and ID of each campaign.Logger.log()
logs the campaign details to the console.
- Selector Definition: