Script to restore removed keywords?

1,552 views
Skip to first unread message

Christopher Larkin

unread,
Mar 2, 2020, 10:38:34 PM3/2/20
to Google Ads Scripts Forum
Hi -

I have a number of keywords in some campaigns that I want to add back. I exported all of the keywords that were removed so I could do this in Google Ads Editor, but I am wondering if there is a programmatic solution - where I might read removed keywords and then add them back to ad groups.

Is this possible? 

Thanks in advance -
Christopher 

Google Ads Scripts Forum Advisor

unread,
Mar 3, 2020, 1:34:27 AM3/3/20
to adwords-scripts+apn2wqefskufq04q...@googlegroups.com, adwords-scripts+apn2wqefskufq04q...@googlegroups.co, adwords...@googlegroups.com
Hi Christopher,

Re-enabling REMOVED keywords is currently not supported. However, creating new keywords with similar attributes as the removed ones should be possible.

Using the Google Ads Scripts, you should be able to retrieve those removed keywords first by using the AdsApp.KeywordSelector and using the withCondition(condition) method and the Status = REMOVED condition. You can refer to this sample code on how you can implement this get feature.

As for creating the said keywords, you can then refer to this example as to how. Let me know if this is what you're looking for.

Thanks,
Peter
Google Ads Scripts Team

ref:_00D1U1174p._5001UXTvBe:ref

Christopher Larkin

unread,
Mar 3, 2020, 2:07:53 AM3/3/20
to Google Ads Scripts Forum
Hey Peter -

That is exactly my request. I think what I want is something like this (rough code, not quite actually usable):

Loop the campaigns/ad groups I want to process, calling a function that finds the removed keywords (using the examples at the links you provided) then adds them to the affected ad groups.

function restoreKeywords(campaign, adGroup) {
    select all the keywords in adGroup that have been removed with a certain quality score or other KPIs that I want to restore
    add the keywords back to the ad groups
    log each keyword as added
}

Does that look right to you? Am I missing something? 

Any KPIs that make sense to you to add? We removed these because in 13 months the keywords had 0 conversions (and we have used position-based attribution for years on these campaigns). 

Christopher Larkin

unread,
Mar 3, 2020, 2:11:22 AM3/3/20
to Google Ads Scripts Forum
Peter - also, are there certain attributes of the keywords I need to pull in from that loop to push into the new settings. I'm wondering if there's anything I'm not thinking of -- thanks!

Google Ads Scripts Forum Advisor

unread,
Mar 3, 2020, 5:57:51 AM3/3/20
to adwords-scripts+apn2wqefskufq04q...@googlegroups.com, adwords-scripts+apn2wqefskufq04q...@googlegroups.co, adwords...@googlegroups.com
Hi Christopher,

Thank you for providing more details as to what it is you wish to achieve.

What you have outlined in your pseudo code is possible. Referring once again to the columns that can be used in the withCondition(condition) method, you can add a condition for retrieving which keywords had the reached a certain value for its Impressions, Clicks, and maybe also the QualityScore.

Also, the fields included in the add keyword example are already those that are immediately required. However, you may also refer to the fields listed here for those that you can retrieve and also include when re-creating the previously removed keyword. 
Message has been deleted

Christopher Larkin

unread,
Mar 6, 2020, 1:11:51 AM3/6/20
to Google Ads Scripts Forum
HI Peter -

Having a number of problems here. I can't seem to get the keywords in place via automation. 

I've included the code I'm trying below, but it doesn't do anything (no keyword is added). Also, is there a way to add the match type? 

Thanks!


 
 function main() {
    
var CID = 'xxx-xxxxxxx';
    
var matchType = 'Contains';


    
var accountSelector = AdsManagerApp
        
.accounts()
        
.withIds([CID]);
        
var accountIterator = accountSelector.get();
        
while (accountIterator.hasNext()) {
            
var thisAccount = accountIterator.next();
            
Logger.log('Account ' + thisAccount.getName());
        
}
        
MccApp.select(thisAccount);
     
        addKeyword
('Alexandria Master (Arc)','WeWork','+shared +office +washington +dc');
     
     
//   getKeywordsInAdGroup();
   
}




   
function getKeywordsInAdGroup() {
    
var keywordIterator = AdsApp.keywords()
        
.withCondition('CampaignName = "Alexandria Master (Arc)"')
        
.withCondition('Status = REMOVED')
        
.get();
    
if (keywordIterator.hasNext()) {
      
while (keywordIterator.hasNext()) {
        
var keyword = keywordIterator.next();
        
Logger.log(formatKeyword(keyword));
      
}
    
}
  
}
 
  
function formatKeyword(keyword) {
    
return 'Text : ' + keyword.getText() + '\n' +
        
'Match type : ' + keyword.getMatchType() + '\n' +
        
'CPC : ' + keyword.bidding().getCpc() + '\n' +
        
'Final URL : ' + keyword.urls().getFinalUrl() + '\n' +
        
'Approval Status : ' + keyword.getApprovalStatus() + '\n' +
        
'Ad Group : ' + keyword.getAdGroup() + '\n' +
        
'Enabled : ' + keyword.isEnabled() + '\n';
       
  
}




  
function addKeyword(campaignName, adGroupName, keywordText) {
    
// If you have multiple adGroups with the same name, this snippet will
    
// pick an arbitrary matching ad group each time. In such cases, just
    
// filter on the campaign name as well:
    
//
    
var adGroupIterator = AdsApp.adGroups()
        
.withCondition('Name = "'+adGroupName+'"')
        
.withCondition('CampaignName = "'+campaignName+'"')
    
// var adGroupIterator = AdsApp.adGroups()
    
//     .withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
        
.get();
    
if (adGroupIterator.hasNext()) {
      
var adGroup = adGroupIterator.next();
 
      adGroup
.newKeywordBuilder()
          
.withText(keywordText)
          
//.withMatchType(matchType);
         
          
.build();
 
      
// KeywordBuilder has a number of other options. For more details see
      
// https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_keywordbuilder
    
}

Google Ads Scripts Forum Advisor

unread,
Mar 6, 2020, 5:02:17 AM3/6/20
to adwords-scripts+apn2wqefskufq04q...@googlegroups.com, adwords-scripts+apn2wqefskufq04q...@googlegroups.co, adwords...@googlegroups.com
Hi Christopher,

Upon checking your Scripts on my end, they appear to be working correctly. However, it appears that the reason why it is not working on your end is because the WeWork ad group that you hard coded does not appear to be under the Alexandria Master (Arc) campaign. That being said, you may check first whether the campaign and ad group you are testing should belong to the same hierarchy.

As for the Match Type, you can follow this guide on how Scripts would automatically detect whether you are setting your keyword as either broad, phrase, or exact.
Reply all
Reply to author
Forward
0 new messages