error using newPlacementBuilder method for adGroup

35 views
Skip to first unread message

Alberto Esteves Correia

unread,
Nov 12, 2018, 7:32:32 PM11/12/18
to AdWords Scripts Forum
Hi everyone, 

I'm trying to exclude some placements from an adGroup, but it gives me an execution error:


// ...
function excludeSpamPlacementsAtAdGroupLevel(){
  
  var adGroupsIterator = AdWordsApp.adGroups()
                                   .withCondition("AdGroupStatus IN [ENABLED, PAUSED]")
                                   .withCondition("CampaignStatus IN [ENABLED, PAUSED]")
                                   .get();
  
  while (adGroupsIterator.hasNext()){
    var adGroup = adGroupsIterator.next();

    Logger.log("Before excluding");
    var excludeOperation = adGroup.display();
    
    Logger.log("Before aux");
    var aux = excludeOperation.newPlacementBuilder();
    
    Logger.log("Before aux2");
    var aux2 = aux.withUrl("test12345.com")
    
    Logger.log("Before aux3");
    var aux3 = aux2.exclude();
    
    Logger.log("After excluding");

// ...



output-log.png


I've located the error at newPlacementBuilder method, but I don't know why it happens. 


Any ideas?

Lots of thanks!


Regards,
Alberto Esteves Correia

Hiroyuki Miyauchi (AdWords Scripts Team)

unread,
Nov 13, 2018, 3:07:01 AM11/13/18
to AdWords Scripts Forum
Hello Alberto,

The possible reason why you are encountering the issue is because the script tries to add the placement to an ad group which do not belong to display campaigns. Since the placements should be in the display campaigns only (you may refer to this guide), then, you may add a condition (filter by AdGroupType) in your code below.

var adGroupsIterator = AdWordsApp.adGroups()
   
.withCondition("AdGroupStatus IN [ENABLED, PAUSED]")
   
.withCondition("CampaignStatus IN [ENABLED, PAUSED]")

   
.withCondition("AdGroupType = 'DISPLAY_STANDARD'") // Specify AdGroupType
   
.get();

After trying the code above and if you still see the same issue, could you please provide your CID and script name via Reply privately to author so I can further investigate?

Regards,
Hiroyuki
AdWords Scripts Team

Alberto Esteves Correia

unread,
Nov 13, 2018, 12:51:20 PM11/13/18
to AdWords Scripts Forum
Wonderful! 

I see that AdGroupType can have all these values: 

adGroupTypes.PNG


Which o these ones can I use in that query (to get placements and exclude them from the adGroup)? 

How Can I choose adGroups of Smart Display campaigns

Thanks!

Regards, 

Alberto Esteves Correia

unread,
Nov 13, 2018, 6:44:54 PM11/13/18
to AdWords Scripts Forum
I want to do the same at campaign level, at Display & Smart Display campaigns. 

Is this code correct? 


function excludeSpamPlacementsAtCampaignLevel(){
  
  var campaignsIterator = AdWordsApp.campaigns()
                                   .withCondition("CampaignStatus IN [ENABLED, PAUSED]")
                                   .withCondition("AdNetworkType1 = 'CONTENT'")
                                   .get();
  
  while (campaignsIterator.hasNext()){
    var campaign = campaignsIterator.next();

    Logger.log("Before excluding at Campaign level");

    SPAM_LIST.forEach(function (placement_url) {
      Logger.log(placement_url);  
      
      var excludeOperation = campaign.display().newPlacementBuilder().withUrl(placement_url).exclude();
      Logger.log(placement_url + " excluded from " + campaign.getName() + " campaign");               
     });

    Logger.log("After excluding at Campaign level");
  } 
} // End of excludeSpamPlacementsAtCampaignLevel function


NOTE: SPAM_LIST is a global variable with the placement urls that must be excluded. 


It would be wonderful if get the code for exclude placements at both levels (campaign & adGroup)

Lots of thanks!

Hiroyuki Miyauchi (AdWords Scripts Team)

unread,
Nov 14, 2018, 1:58:06 AM11/14/18
to AdWords Scripts Forum
Hello Alberto,

So I can check the script, could you please provide your CID and script name as well as sample Smart Display campaigns (kindly provide the campaign ID) via Reply privately to author?

Regards,
Hiroyuki
AdWords Scripts Team

Reply all
Reply to author
Forward
0 new messages