I have been working on a script that aims to achieve the following tasks:
- Go through all the accounts in an MCC and pick out the ones with 'SEM' in their name.
- Go through the campaigns in a selected account and choose those that meet specific conditions.
- Email a list of these selected campaigns to myself.
The issue I am facing pertains to connecting the account loop with the campaign loop.
Therefore, my question is; How can I specify an AdWords account when utilizing campaignSelector in AdWords scripts?
If I can specify the account for the campaign iteration (instead of the script defaulting to the current account), I can provide an array of my chosen accounts there.
Thank you.
Here is the script as it stands:
//This code is to be inserted in an MCC, it loops through accounts in the MCC based on certain criteria
//then for those selected accounts, it filters through the campaigns that meet specific criteria and adds
//these to a report (the report code has not been added yet)
//The challenge lies in getting the campaignSelector() function to look at the passed account from the accountIterator() function
function main() {
var mccAccount = AdWordsApp.currentAccount();
var childAccounts = MccApp.accounts();
function accountIterator()
{
var accountSelector = MccApp.accounts()
.withCondition("AccountDescriptiveName CONTAINS 'SEM'")
.withCondition("Status = ENABLED");
var accountIterator = accountSelector.get();
while (accountIterator.hasNext())
{
var account = accountIterator.next();
var accountName = account.getName();
Logger.log(accountName);
campaignSelector(accountName); //This might need adjustment
//We need to pass the account name to the campaignSelector function
//so that it looks at the campaigns in the specified account
}
}
function campaignSelector ()
{
//SELECT campaigns we're interested in
var account = AdWordsApp.currentAccount(); //Might need to use this?
var campaignSelector = AdWordsApp.campaigns()
.withCondition("CampaignName CONTAINS 'Shoop'")
.withCondition("SearchExactMatchImpressionShare < 95")
.forDateRange("LAST_7_DAYS")
.withCondition("Status = ENABLED");
//GET an iterator to list the selected campaigns
var campaignIterator = campaignSelector.get();
//ITERATE through all selected campaigns
while (campaignIterator.hasNext())
{
var campaign = campaignIterator.next();
//Include campaign and account info in a report – to be coded separately
}
}
}