Google Ads Scripts 101 – What are Entities and Methods?

Now that you understand the concepts of a Selector and Iterator, the next important concept to learn about in Google Ads Scripts is “Entities and Methods”.

What are Entities?

In Google Ads Scripts, entities represent various components of your Google Ads account. Each entity corresponds to a part of your account, such as campaigns, ad groups, ads, keywords, and so on. These entities allow you to interact with and manipulate your account programmatically.

Key Entities in Google Ads Scripts:

    1. Campaigns: Represent advertising campaigns.
    2. Ad Groups: Contain ads and keywords for a campaign.
    3. Ads: Individual advertisements.
    4. Keywords: Keywords that trigger ads.
    5. Extensions/assets: Additional information or functionality for ads (e.g., sitelinks, call extensions).

What are Methods?

Methods are actions that you can perform on these entities. They allow you to retrieve data, modify settings, or perform operations related to the entities.

Some of the most common Methods :

    1. getName(): Retrieves the name of the entity.
    2. getStatsFor(): Gets performance statistics for the entity over a specified time period.
    3. pause(): Pauses the entity.
    4. enable(): Enables the entity.
    5. remove(): Removes the entity.

Example: Working with Entities and Methods

Let’s put these concepts into practice with a simple example. We’ll create a script that retrieves the names of all active campaigns, pauses them, and logs their names and current status.

Pseudo-code Explanation:

    1. Retrieve Active Campaigns: Use a selector to get all active campaigns.
    2. Pause Each Campaign: Use an iterator to go through each campaign and pause it.
    3. Log Campaign Details: Log the name and status of each paused campaign.

Complete Script Example:

Explanation:

    • AdsApp.campaigns(): Starts the process of creating a selector for campaigns.
    • .withCondition("Status = 'ENABLED'"): Filters only active campaigns.
    • .get(): Retrieves the iterator for the selected campaigns.
    • while (campaignSelector.hasNext()): Checks if there are more campaigns to process.
    • campaignSelector.next(): Retrieves the next campaign.
    • campaign.pause(): Pauses the campaign.
    • Logger.log('Campaign Name: ' + campaign.getName()): Logs the name of each campaign.
    • Logger.log('Status: ' + campaign.getStatus()): Logs the status of each campaign (which should be “PAUSED” after pausing).

Summary

Understanding entities and methods is crucial for effectively managing your Google Ads account programmatically. Entities represent various components of your account, while methods are actions you can perform on these entities. Together, they allow you to retrieve information, modify settings, and automate tasks within your Google Ads account.

Once you’re comfortable with entities and methods, the next steps could involve learning about reporting, automating repetitive tasks, and handling bulk operations.

I hope this helps, happy scripting!