Created
May 10, 2021 14:26
-
-
Save JJPell/0f8499c762e20f413a20dea1497e1975 to your computer and use it in GitHub Desktop.
AdsManagerApp example script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface TotalEntities { | |
campaigns: number; | |
adGroups: number; | |
ads: number; | |
keywords: number; | |
} | |
/** | |
* Logs the totals number of campaign, ad group, ads and keyword entities | |
*/ | |
function logTotalEntities(account: GoogleAdsScripts.AdsApp.Account, totalEntities: TotalEntities): void { | |
const accountName = account.getName(); | |
Logger.log(`${accountName}: Total Campaigns - ${totalEntities.campaigns}`); | |
Logger.log(`${accountName}: Total Ad Groups - ${totalEntities.adGroups}`); | |
Logger.log(`${accountName}: Total Ads - ${totalEntities.ads}`); | |
Logger.log(`${accountName}: Total Keywords - ${totalEntities.keywords}`); | |
} | |
/** | |
* Script entry point | |
*/ | |
function main(): void { | |
// Execute accountMain function for all accounts within MCC account | |
AdsManagerApp.accounts().executeInParallel('accountMain'); | |
} | |
/** | |
* Runs concurrently for each account under your MCC account | |
*/ | |
function accountMain(): void { | |
const account = AdsApp.currentAccount(); | |
const campaigns = AdsApp.campaigns().get().totalNumEntities(); | |
const adGroups = AdsApp.adGroups().get().totalNumEntities(); | |
const ads = AdsApp.ads().get().totalNumEntities(); | |
const keywords = AdsApp.keywords().get().totalNumEntities(); | |
const totalEntities: TotalEntities = { | |
campaigns, | |
adGroups, | |
ads, | |
keywords | |
}; | |
logTotalEntities(account, totalEntities); | |
} | |
// Assigning to global creates a global function within the Google Ads Scripts enviroment | |
global.main = main; | |
global.accountMain = accountMain; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment