I am working with Google AdWords API to create ad groups and product groups (Product partitions) using the PHP client library provided by Google team. I have successfully created the ad groups using that library. But I am stuck at the point to create product groups for that ad group.
I am sure to create product groups we need Shopping campaigns. I have tried to create products partitions for that shopping campaign using the script "AddProductPartitionTree.php" provided in the client library. But every time it throws an error
[AdGroupCriterionError.PRODUCT_PARTITION_ALREADY_EXISTS @ operations[8].
There is something wrong while creating the root node of the product partitions
I am sharing the code of product partition script below:
private function createProductPartition(AdWordsServices $adWordsServices,
AdWordsSession $session,
$adGroupId)
{
// The most trivial partition tree has only a unit node as the root:
// $productPartitions->createBiddableUnit(null, null, 100000);
$operations = [];
$root = ProductPartitions::createSubdivision();
// print_r($root);
$criterion = ProductPartitions::asBiddableAdGroupCriterion($adGroupId, $root);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$newCondition = new ProductCanonicalCondition();
$newCondition->setCondition(ProductCanonicalConditionCondition::NEW_VALUE);
$newConditionUnit = ProductPartitions::createUnit($root, $newCondition);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$newConditionUnit,
200000
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$usedCondition = new ProductCanonicalCondition();
$usedCondition->setCondition(ProductCanonicalConditionCondition::USED);
$usedConditionUnit = ProductPartitions::createUnit($root, $usedCondition);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$usedConditionUnit,
100000
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$otherCondition = ProductPartitions::createSubdivision(
$root,
new ProductCanonicalCondition()
);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$otherCondition
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$coolBrand = new ProductBrand();
$coolBrand->setValue('aerotech');
$coolBrandUnit = ProductPartitions::createUnit($otherCondition, $coolBrand);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$coolBrandUnit,
900000
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$cheapBrand = new ProductBrand();
$cheapBrand->setValue('taylormade');
$cheapBrandUnit = ProductPartitions::createUnit($otherCondition, $cheapBrand);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$cheapBrandUnit,
10000
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$otherBrand = ProductPartitions::createSubdivision(
$otherCondition,
new ProductBrand()
);
// print_r($otherBrand);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$otherBrand
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
// The value for the bidding category is a fixed ID for the 'Luggage & Bags'
// category. You can retrieve IDs for categories from the
// ConstantDataService.
// See the 'GetProductCategoryTaxonomy' example for more details.
$productBiddingCategory = new ProductBiddingCategory();
// $productBiddingCategory->setType(ProductDimensionType::UNKNOWN);
$productBiddingCategory->setType(ProductDimensionType::BIDDING_CATEGORY_L1);
// $productBiddingCategory->setValue(-5914235892932915235);
// $productBiddingCategory->setValue(6085370270382700000);
$productBiddingCategoryUnit = ProductPartitions::createUnit($otherBrand, $productBiddingCategory);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$productBiddingCategoryUnit,
750000
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$productBiddingCategory = new ProductBiddingCategory();
$productBiddingCategory->setType(ProductDimensionType::BIDDING_CATEGORY_L1);
$productBiddingCategoryUnit = ProductPartitions::createUnit($otherBrand, $productBiddingCategory);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$productBiddingCategoryUnit,
110000
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$adGroupCriterionService = $adWordsServices->get($session, AdGroupCriterionService::class);
print_r($operations);
exit;
// Creates ad group criteria on the server.
$adGroupCriterionService->mutate($operations);
// Display the production partition tree.
printf(
"%s\n",
ProductPartitions::showAdGroupTree(
$adWordsServices,
$session,
$adGroupId
)
);
}
I wanted to get help to create product groups for ad groups in AdWords.
Help would be appreciated. Thanks