Hello Jash,
Based on my understanding, you want to create a script that will enable adGroups and keywords from a particular AdWords account and to pause the same adgroups and keywords from another account and vice versa. To get you started in creating this script, since you already have the list of adGroups that need to be paused in a particular account, I also suggest you to create a list for keywords. With this, you would need to fetch those keywords' and adGroups' objects in the account and pause them first. Then switch to the account which you want to enable the AdGroups and keyowords, fetch those objects and enable them. You may refer to the sample code snippet below on how to switch account and pause / enable adGroups and keywords but feel free to modify this based on your preference.
function main() {
// Include your code here to pull Data from Spreadsheet. You may refer to these examples.
// https://developers.google.com/adwords/scripts/docs/examples/spreadsheetapp
// Pause AdGroups and Keywords (Account 1)
var accountToPause = MccApp.accounts().withIds(['INSERT_YOUR_ACCOUNT_ID']).get().next();
MccApp.select(accountToPause);
// Fetch AdGroups
var adGroupIteratorToPause = AdWordsApp.adGroups().withIds([Insert_ADGROUP_ID_HERE]).get();
while (adGroupIteratorToPause.hasNext()) {
var adGroup = adGroupIteratorToPause.next();
adGroup.pause();
Logger.log(
'Account ID: '
AdWordsApp.currentAccount().getCustomerId() +
',Account Name: '
AdWordsApp.currentAccount().getName() +
',adGroup ID: '
adGroup.getId() +
',adGroup Name: ' + adGroup.getName() +
' Paused')
}
// Fetch Keywords
var keywordIteratorToPause = AdWordsApp.keywords().withIds([Insert_KEYWORD_ID_HERE]).get();
while (keywordIteratorToPause.hasNext()) {
var keyword = keywordIteratorToPause.next();
keyword.pause();
Logger.log(
'Account ID: '
AdWordsApp.currentAccount().getCustomerId() +
',Account Name: '
AdWordsApp.currentAccount().getName() +
',keyword ID: '
keyword.getId() +
',keyword Text: ' + keyword.getText() +
' Paused')
}
// Enable AdGroup (Account 2)
var accountToEnable = MccApp.accounts().withIds(['INSERT_YOUR_ACCOUNT_ID']).get().next();
MccApp.select(accountToEnable);
// Fetch AdGroups
var adGroupIteratorToEnable = AdWordsApp.adGroups().withIds([Insert_ADGROUP_ID_HERE]).get();
while (adGroupIteratorToEnable.hasNext()) {
var adGroup = adGroupIteratorToEnable.next();
adGroup.enable()();
Logger.log(
'Account ID: '
AdWordsApp.currentAccount().getCustomerId() +
',Account Name: '
AdWordsApp.currentAccount().getName() +
',adGroup ID: '
adGroup.getId() +
',adGroup Name: ' + adGroup.getName() +
' Enabled')
}
// Fetch Keywords
var keywordIteratorToEnable = AdWordsApp.keywords().withIds([Insert_KEYWORD_ID_HERE]).get();
while (keywordIteratorToEnable.hasNext()) {
var keyword = keywordIteratorToEnable.next();
keyword.enable();
Logger.log(
'Account ID: '
AdWordsApp.currentAccount().getCustomerId() +
',Account Name: '
AdWordsApp.currentAccount().getName() +
',keyword ID: '
keyword.getId() +
',keyword Text: ' + keyword.getText() +
' Enabled')
}
}
In the sample script above, I used withIds to fetch adGroups' and keywords' iterator. However, you would need to edit those lines depending on how you get the data from your spreadsheet. If you want to fetch using labels, you may edit the lines with withCondition("LabelNames CONTAINS_ANY ['INSERT_YOUR_LABEL_NAME']").
Please let me know how it goes after trying the suggestion.
Please make sure to use the Preview button first to check on possible results.
Regards,
Hiroyuki
AdWords Scripts Team