Copy / Clone an Existing Ad Group

698 views
Skip to first unread message

je...@pumpkinlabs.com

unread,
Mar 26, 2018, 3:43:20 PM3/26/18
to AdWords Scripts Forum
Is there an easy way to copy or clone an existing adgroup via an Adwords Script?

I'd like to:

- copy an existing ad group
- change it's name
- remove all keywords
- add a new (exact match) keyword

Thanks!
Jeff

Adrian Catambay (AdWords Scripts Team)

unread,
Mar 27, 2018, 4:13:55 AM3/27/18
to AdWords Scripts Forum
Hello Jeff,

Based on my understanding, you would want to clone an existing ad group together with its keywords. If so, there is currently no way to copy an ad group. However, you may use the AdGroupBuilder to create a new ad group with configurations the same as the ad group you would want to copy. Here is an example script as reference on how to create ad groups.

Please take note that when creating the ad group, these are the only methods available. If you would want to add exact keywords on the ad group that you will be creating, you must first create the ad group. You may then use the KeywordBuilder to add exact match keywords. Here is an example script on how to ad keywords on an exiting add group. To add an exact match keyword, you may add brackets ([]) in the text inside the withText() function (e.g. withText('[SAMPLE]')).

You may also see the sample script below on how to create ad group and add exact match keyword on the said ad group as reference:

function main() {
 
var campaignSelector = AdWordsApp
 
.campaigns();

 
var campaignIterator = campaignSelector.get();
 
while (campaignIterator.hasNext()) {
   
var campaign = campaignIterator.next();
   
Logger.log(campaign.getName());

   
var adGroupOperation = campaign.newAdGroupBuilder()
   
.withName('INSERT_ADGROUP_NAME_HERE')
   
.withCpc(INSERT_CPC_HERE)
   
.build();
   
   
var adgroup = adGroupOperation.getResult();

   
if(adGroupOperation.isSuccessful()) {

     
//creates the exact match keyword on an adgroup level
     
//note that all adgroups on this specific campaign will have exact match keywords created
     
var keywordOperation = adgroup.newKeywordBuilder()
     
.withText('[INSERT_KEYWORD_NAME_HERE]')
     
.withCpc(INSERT_CPC_HERE)
     
.build();
     
var keyword = keywordOperation.getResult();
   
}
 
}
}

To delete all keywords under an ad group, you may refer to the sample code below as reference:

function main() {

   
var keywordSelector = AdWordsApp
     
.keywords()
     
.withCondition("AdGroupName CONTAINS 'ADGROUP_NAME_HERE'"); // selects keywords you want to remove. you may change the condition based on your requirements.

   
var keywordIterator = keywordSelector.get();
   
while (keywordIterator.hasNext()) {
     
var keyword = keywordIterator.next();
     keyword
.remove(); // removes keywords
   
}
}

You may try the suggested sample codes above using the Preview button.

Let me know if the suggestions above works for your requirements.

Thanks,
Adrian
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages