var productGroups = AdWordsApp.productGroups()
.withCondition("ProductGroup CONTAINS '" + ITEM_ID + "'")
.withCondition("CampaignName = '" + CAMPAIGN_NAME + "'")
.get();
if (productGroups.hasNext()) {
var productGroup = productGroups.next();
// adjust productGroup cpc as needed.
}function main() {
// All of the product groups are defined in a single campaign, so let's focus on it.
var campaign = AdWordsApp.shoppingCampaigns().withCondition("Name = '" + CAMPAIGN_NAME + "'");
// Find all active product groups in the campaign that match the specified conditions.
// (We want to ignore any product groups that are already set aside in their own ad groups.
var outliers = campaign.productGroups()
.withCondition("Impressions > 500")
.withCondition("AdGroupName DOES_NOT_CONTAIN 'Outlier'")
.forDateRange("THIS_MONTH")
.get();
while (outliers.hasNext()) {
// We found an "outlier" product group. Let's split it off from the rest of the product groups and move it into its own ad group.
var outlier = outliers.next();
var itemId = outlier.asItemId();
// First we create a fresh ad group for this product.
// The bids are less important than the name. The name contains 'Outlier' and ensures that subsequent iterations of this script
// do not move the product group again (it's already in its own ad group, no need to do it again).
var newAdGroup = campaign.newAdGroupBuilder()
.withBiddingStrategy("MANUAL_CPC")
.withCpc(0.5)
.withName("Outlier - " + itemId.getValue())
.build()
.getResult();
// Now we need to create a root product group (aka "All products").
newAdGroup.createRootProductGroup();
var root = newAdGroup.rootProductGroup();
// Now we can create the product group for the outlier item id.
root.newChild().itemIdBuilder()
.withBid(0.6)
.withValue(itemId.getValue())
.build();
// We want to exclude every other product from serving in this ad group
var children = root.children().get();
while (children.hasNext()) {
var child = children.next();
if (child.isOtherCase()) {
child.exclude();
}
}
// Now we can remove the product group from the rest of the ad groups.
itemId.remove();
}
}Hi Troy,
It seems that the script which is provided by Alex is missing an iteration of shopping campaigns. With this, you may try to modify the line 6 - 10 in the script like below:
var campaignIterator = campaign.get();
if(campaignIterator.hasNext()){
var shoppingCampaigns = campaignIterator.next();
}else{
return;
}
var outliers = shoppingCampaigns.productGroups()
.withCondition("Impressions > 500")
.withCondition("AdGroupName DOES_NOT_CONTAIN 'Outlier'")
.forDateRange("THIS_MONTH")
.get();
Also, since this is an old thread, feel free to open a new thread so we can track this on our end better.
Regards,
Hiroyuki
Google Ads Scripts Team