Exclude by item id, how to detect to which product group it belongs too.

216 views
Skip to first unread message

Razvan Pepelea

unread,
May 15, 2020, 2:31:55 PM5/15/20
to Google Ads Scripts Forum
Hello,

I have many shopping campaigns in my account, from different advertisers, they are not split in different accounts, each campaign has only one adgroup and adgroup is split by custom_label_0, a practical example is:

Campaign 1
- Ad group 1
--All products
---ProductGroup1(CUSTOM_LABEL_0)
---ProductGroup2(CUSTOM_LABEL_0)
---ProductGroup3(CUSTOM_LABEL_0)
---ProductGroup4(CUSTOM_LABEL_0)
---Everything else


Campaign2
- Ad group 2
--All products
---ProductGroup5(CUSTOM_LABEL_0)
---ProductGroup6(CUSTOM_LABEL_0)
---ProductGroup7(CUSTOM_LABEL_0)
---ProductGroup8(CUSTOM_LABEL_0)
---Everything else

Campaign3
- Ad group3
--All products

I want to exclude specific products by id, the problem is that is i do not know to which product group the product belongs too or to everything else, so i add it to every productgroup and than verify if the subgroup created has 0 impressions, if it has 0 impression, i remove it.
It goes without saying, that this is not optimal,  its extremly slow and I am not certain it always works.

I need a way to find out where the product belongs, to which product group parent or to everything else. 

Thank you,
Razvan

Google Ads Scripts Forum Advisor

unread,
May 15, 2020, 5:01:20 PM5/15/20
to adwords-scripts+apn2wqebyez0h6kh...@googlegroups.com, adwords-scripts+apn2wqebyez0h6kh...@googlegroups.co, adwords...@googlegroups.com
Hi Razvan,

You can iterate over product groups and search for an item ID match. For example,
 
  var productId = 1234567; //ID you want to find

  var productGroups = AdsApp.productGroups().get();
  while(productGroups.hasNext()) { //Iterate over all product groups
    var productGroup = productGroups.next();
    var itemId = productGroup.asItemId();
    var id = itemId.getId();
    if(id == productId) //If an ID match is found, pause that item ID
      itemId.exclude();
  }

If you need assistance on an existing script, please provide your CID and script name.

Thanks,
Matt 
Google Ads Scripts Team
 

ref:_00D1U1174p._5004Q1zpda6:ref

Razvan Pepelea

unread,
May 15, 2020, 5:13:31 PM5/15/20
to Google Ads Scripts Forum
Hello,

Yes,  I need help but i would rather understand, because i am trying to create more complex scripts.
The problem is that the GROUP is not created, i need to create the ITEM id subgroup but i do not know in which group it belongs.

Razvan Pepelea

unread,
May 15, 2020, 5:27:05 PM5/15/20
to Google Ads Scripts Forum
At the moment i am using this, but it creates the item subgroup in every group and that is bad, instead of creating in the one that it belongs to, how can i add only in the parent productGroup where it belongs to.

         var adGroup = adGroups.next();
         var productGroupIterator = adGroup.productGroups().get();
         while (productGroupIterator.hasNext()) 
         { 
            var productGroup = productGroupIterator.next();
            var productGroupDimension = productGroup.getDimension();
            var productGroupValue = productGroup.getValue();
            var maxCpc = productGroup.getMaxCpc();
            var impressions = productGroup.getStatsFor('LAST_30_DAYS').getImpressions() ;
           
           
           if ( productGroupDimension != "ITEM_ID" && impressions > 0 && !productGroup.isOtherCase() && !productGroup.isExcluded())
            {             
               var insert = productGroup.newChild().itemIdBuilder()
              .withBid(maxCpc)
              .withValue(OfferId)
              .build();

            }
          }









On Saturday, 16 May 2020 00:01:20 UTC+3, adsscriptsforumadvisor wrote:

Google Ads Scripts Forum Advisor

unread,
May 17, 2020, 9:57:04 PM5/17/20
to adwords...@googlegroups.com

Hi Razvan,

I am a colleague of Matt and let me provide further support to your concern.

If you want to create a sub product group directly under a parent/root product group only, then you may add the condition below to script validation.

productGroupDimension == "ROOT" 

Let me know how it goes after trying the provided solution.

Regards,
Ejay
Google Ads Scripts Team



ref:_00D1U1174p._5004Q1zpda6:ref

Razvan Pepelea

unread,
May 18, 2020, 5:57:50 AM5/18/20
to Google Ads Scripts Forum
are these messages automated? They have little or nothing to do with my request.
I do not need to add in the ROOT, in the ROOT there are 10 CUSTOM LABEL productGroups, but product X only belongs to one of them, how can I know where it belongs to not add to all CUSTOM_LABEL groups

Google Ads Scripts Forum Advisor

unread,
May 18, 2020, 6:57:09 AM5/18/20
to adwords...@googlegroups.com
Hi Razvan,

My recent response was to address your earlier reply in our thread. Based on your reply:


"At the moment i am using this, but it creates the item subgroup in every group and that is bad, instead of creating in the one that it belongs to, how can i add only in the parent productGroup where it belongs to."

It appears that you want to create items right under a parent product groups. However, it doesn't have any validation to check if it is the parent product group where the items will be created (because item builder is implemented), so you've mentioned that the script created the item subgroup in every group. Also, no custom label has been mentioned earlier.

Moving forward to your latest reply, there is no direct way to know the custom label where specific product belongs. As a workaround, you may try to implement this sample code as it will iterate all the product group level until it reached the lowest product group level. You may then try to log the returned value of getId() of custom label as it will give you a hint where an item/product belongs.

Let me know if you have further questions.

Razvan Pepelea

unread,
May 18, 2020, 7:36:41 AM5/18/20
to Google Ads Scripts Forum
Can you please give me a practical example on how to check using the getId()?
This is the code i am using to insert inside the custom group, i do not understand how the getId on the respective group will let me know if the product belongs to that parentGroup or not.
I added in the code, MISSING CONDITION HERE where i need the condition to verify.


         var adGroup = adGroups.next();
        var productGroupIterator = adGroup.productGroups().get();
        while (productGroupIterator.hasNext())
         {
            var productGroup = productGroupIterator.next();
           var productGroupDimension = productGroup.getDimension();
           var productGroupValue = productGroup.getValue();
           var maxCpc = productGroup.getMaxCpc();
           var impressions = productGroup.getStatsFor('LAST_30_DAYS').getImpressions() ;
         
           
          if ( productGroupDimension != "ITEM_ID" && impressions > 0 && !productGroup.isOtherCase() && !productGroup.isExcluded())
           {            
               
             
// HOW CAN I CHECK IF THE item is a child of this parentgroup? <--- MISSING CONDITION HERE
             
var insert = productGroup.newChild().itemIdBuilder()
             .withBid(maxCpc)
             .withValue(OfferId)
             .build();

            }
         }


Reply all
Reply to author
Forward
0 new messages