Is it possible to use a script to pause AGs in an acocunt and enable the same AGs in another account

115 views
Skip to first unread message

Jash

unread,
Aug 30, 2018, 5:04:50 PM8/30/18
to AdWords Scripts Forum
Hi, 

Ive been trying to look into MCC level scripts for keywords or Ad Groups that can pause and enable KWs/AGs between accounts. To give you a background of the request - I manage 7 accounts for the same company (i.e. they have 7 brands) and so the campaigns that are run are the same across the board. Now, competing against each brand does not make sense and it will only drive up my CPCs but I dont want to lose out on traffic when 1 KW starts to perform poorly on 1 particular account. When this happens, I am forced to pause some of the high performing KWs in the account for that particular month. Each month I would move the campaign between the brands so that all brands get equal opportunity to perform well. 

To give you an example - 
  • Account 1
    • Campaign A
      • AG 1
        • KW1
      • AG 2
        • KW2
      • AG 3
        • KW3
  • Account 2 
    • Campaign A
      • AG 1
        • KW1
      • AG 2
        • KW2
      • AG 3
        • KW3
I want to pause AG1/KW1 in Account 1 and enable it in Account 2. Even if I can get a label attached to the AG in the accounts, I can use Rules to pause/enable. 

I have already used the Google Sheets Ad-On to pull data in to give me which AGs need to be paused in which accounts. Im just not able to find a script that will help me pause between accounts. 

Any help on this will be much appreciated! 

Cheers,
Jash

Hiroyuki Miyauchi (AdWords Scripts Team)

unread,
Aug 31, 2018, 4:34:37 AM8/31/18
to AdWords Scripts Forum
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

Jash

unread,
Sep 5, 2018, 7:21:32 AM9/5/18
to AdWords Scripts Forum
Hi Hiroyuki, 

Thank you for the assist. This will be of great help! Will post back if there are any issues that come up. 

Cheers,
Jash
Reply all
Reply to author
Forward
0 new messages