Search in sources :

Example 1 with AdGroupCriterion

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion in project googleads-java-lib by googleads.

the class ProductPartitionTreeTest method testCreateUltimatelyEmptyTree.

/**
 * Tests creating a tree that in its <em>final</em> state is just an empty tree.
 */
@Test
public void testCreateUltimatelyEmptyTree() {
    ProductPartitionTree tree = ProductPartitionTree.createAdGroupTree(-1L, biddingStrategyConfig, Collections.<AdGroupCriterion>emptyList());
    ProductPartitionNode rootNode = tree.getRoot().asSubdivision();
    ProductPartitionNode brand1 = rootNode.addChild(ProductDimensions.createBrand("google")).asSubdivision();
    brand1.addChild(ProductDimensions.createOfferId("A")).asBiddableUnit().setBid(1000000L);
    brand1.addChild(ProductDimensions.createOfferId(null)).asExcludedUnit();
    ProductPartitionNode brand2 = rootNode.addChild(ProductDimensions.createBrand(null)).asExcludedUnit();
    // Now remove the two child nodes under the root and set the root back to a UNIT. This should
    // result in operations that simply create the root node.
    rootNode.removeChild(brand1.getDimension());
    rootNode.removeChild(brand2.getDimension());
    rootNode = rootNode.asBiddableUnit();
    List<AdGroupCriterionOperation> mutateOperations = tree.getMutateOperations();
    assertEquals("Number of operations is incorrect", 1, mutateOperations.size());
    AdGroupCriterionOperation operation = mutateOperations.iterator().next();
    assertEquals("Should have a single operation to ADD the root node", Operator.ADD, operation.getOperator());
    BiddableAdGroupCriterion adGroupCriterion = (BiddableAdGroupCriterion) operation.getOperand();
    assertNull("Product dimension of operation's operand should be null", ((ProductPartition) adGroupCriterion.getCriterion()).getCaseValue());
    assertTrue("Partition ID of the operand should be negative", adGroupCriterion.getCriterion().getId().longValue() < 0L);
}
Also used : AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest) Test(org.junit.Test)

Example 2 with AdGroupCriterion

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion in project googleads-java-lib by googleads.

the class ProductPartitionTreeTest method testMutateMultiNodeTree.

/**
 * Tests mutating an existing tree with multiple nodes.
 */
@Test
public void testMutateMultiNodeTree() {
    List<AdGroupCriterion> adGroupCriteria = Lists.newArrayList();
    List<CriterionDescriptor> descriptors = Lists.newArrayList();
    descriptors.add(new CriterionDescriptor(false, false, null, null, 1L, null));
    ProductBrand brandGoogle = ProductDimensions.createBrand("google");
    descriptors.add(new CriterionDescriptor(false, false, brandGoogle, null, 2L, 1L));
    descriptors.add(new CriterionDescriptor(true, false, ProductDimensions.createOfferId("A"), 1000000L, 3L, 2L));
    Long offerBOriginalPartitionId = 4L;
    descriptors.add(new CriterionDescriptor(true, true, ProductDimensions.createOfferId("B"), null, offerBOriginalPartitionId, 2L));
    Long brandOtherOriginalPartitionId = 5L;
    descriptors.add(new CriterionDescriptor(true, true, ProductDimensions.createBrand(null), null, brandOtherOriginalPartitionId, 1L));
    ProductBrand brandMotorola = ProductDimensions.createBrand("motorola");
    Long brandMotorolaOriginalPartitionId = 6L;
    descriptors.add(new CriterionDescriptor(true, true, brandMotorola, null, brandMotorolaOriginalPartitionId, 1L));
    descriptors.forEach(descriptor -> adGroupCriteria.add(descriptor.createCriterion()));
    Map<Long, Map<Long, CriterionDescriptor>> descriptorMap = buildDescriptorMap(descriptors);
    ProductPartitionTree tree = ProductPartitionTree.createAdGroupTree(-1L, biddingStrategyConfig, adGroupCriteria);
    assertEquals("ad group ID is incorrect", -1L, tree.getAdGroupId().longValue());
    Queue<ProductPartitionNode> nodes = Lists.newLinkedList();
    nodes.add(tree.getRoot());
    int nodesFound = 0;
    while (!nodes.isEmpty()) {
        ProductPartitionNode node = nodes.remove();
        Long parentId = node.getParent() == null ? null : node.getParent().getProductPartitionId();
        CriterionDescriptor expectedDescriptor = descriptorMap.get(parentId).get(node.getProductPartitionId());
        CriterionDescriptor actualDescriptor = new CriterionDescriptor(node);
        expectedDescriptor.assertDescriptorEquals(actualDescriptor);
        // Add children to process.
        Iterables.addAll(nodes, node.getChildren());
        nodesFound++;
    }
    assertEquals("Tree does not contain the expected # of nodes", adGroupCriteria.size(), nodesFound);
    // Change the bids on leaf nodes.
    ProductPartitionNode brandGoogleNode = tree.getRoot().getChild(brandGoogle);
    ProductPartitionNode offerANode = brandGoogleNode.getChild(ProductDimensions.createOfferId("A"));
    // This should produce 1 SET operation.
    offerANode.setBid(offerANode.getBid() * 10);
    // This should produce 1 REMOVE operation + 1 ADD operation.
    ProductPartitionNode offerBNode = brandGoogleNode.getChild(ProductDimensions.createOfferId("B"));
    offerBNode.asBiddableUnit().setBid(5000000L);
    // This should produce 1 REMOVE operation + 1 ADD operation.
    ProductPartitionNode brandOtherNode = tree.getRoot().getChild(ProductDimensions.createBrand(null));
    brandOtherNode = brandOtherNode.asBiddableUnit();
    // Add an offer C node. This should produce 1 ADD operation.
    ProductPartitionNode offerCNode = brandGoogleNode.addChild(ProductDimensions.createOfferId("C")).asBiddableUnit().setBid(1500000L).putCustomParameter("param1", "value1");
    // Remove the brand Motorola node. This should produce 1 REMOVE operation.
    tree.getRoot().removeChild(brandMotorola);
    // Get the mutate operations generated by the modifications made to the tree.
    List<AdGroupCriterionOperation> mutateOperations = tree.getMutateOperations();
    assertEquals(7, mutateOperations.size());
    // Put the mutate operations in a map keyed by partition ID.
    Map<Long, CriterionDescriptor> opsDescriptorMap = Maps.newHashMap();
    int i = 0;
    for (AdGroupCriterionOperation mutateOperation : mutateOperations) {
        CriterionDescriptor descriptor = new CriterionDescriptor(mutateOperation.getOperand(), i++);
        opsDescriptorMap.put(descriptor.partitionId, descriptor);
    }
    // Check the node that simply had a bid update.
    int setOpNumber = opsDescriptorMap.get(offerANode.getProductPartitionId()).operationNumber;
    assertEquals("Offer A node with a bid update should have a SET operation", Operator.SET, mutateOperations.get(setOpNumber).getOperator());
    // Check the offer B node that went from excluded to biddable.
    int addOfferBOpNumber = opsDescriptorMap.get(offerBNode.getProductPartitionId()).operationNumber;
    assertEquals("Offer B node with a biddable change should have an ADD operation for the new ID", Operator.ADD, mutateOperations.get(addOfferBOpNumber).getOperator());
    int removeOfferBOpNumber = opsDescriptorMap.get(offerBOriginalPartitionId).operationNumber;
    assertEquals("Offer B node with a biddable change should have a REMOVE operation for the original ID", Operator.REMOVE, mutateOperations.get(removeOfferBOpNumber).getOperator());
    // Check the offer C node that was added.
    int addOfferCOpNumber = opsDescriptorMap.get(offerCNode.getProductPartitionId()).operationNumber;
    assertEquals("New offer C node should have an ADD operation for the new ID", Operator.ADD, mutateOperations.get(addOfferCOpNumber).getOperator());
    // Check the brand null node that went from excluded to biddable.
    int addBrandOtherOpNumber = opsDescriptorMap.get(brandOtherNode.getProductPartitionId()).operationNumber;
    assertEquals("Brand null node with a biddable change should have an ADD operation for the new ID", Operator.ADD, mutateOperations.get(addBrandOtherOpNumber).getOperator());
    int brandOtherOpNumber = opsDescriptorMap.get(offerBOriginalPartitionId).operationNumber;
    assertEquals("Brand null node with a biddable change should have a REMOVE operation for the original ID", Operator.REMOVE, mutateOperations.get(brandOtherOpNumber).getOperator());
    // Check the brand Motorola node that was removed.
    int brandMotorolaOpNumber = opsDescriptorMap.get(brandMotorolaOriginalPartitionId).operationNumber;
    assertEquals("Removed node should have a REMOVE operation", Operator.REMOVE, mutateOperations.get(brandMotorolaOpNumber).getOperator());
}
Also used : ProductBrand(com.google.api.ads.adwords.axis.v201809.cm.ProductBrand) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) Map(java.util.Map) HashMap(java.util.HashMap) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest) Test(org.junit.Test)

Example 3 with AdGroupCriterion

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion in project googleads-java-lib by googleads.

the class ProductPartitionTreeTest method testCreateEmptyTree.

/**
 * Tests creating an empty ad group tree. In this case, all operations generated should be ADD
 * operations.
 */
@Test
public void testCreateEmptyTree() {
    ProductPartitionTree tree = ProductPartitionTree.createAdGroupTree(-1L, biddingStrategyConfig, Collections.<AdGroupCriterion>emptyList());
    assertNotNull("Even an empty tree should automatically have a root node", tree.getRoot());
    assertTrue("The root node for an empty tree should have a negative (temporary) ID", tree.getRoot().getProductPartitionId().longValue() < 0L);
    assertTrue("The root node for an empty tree should be a UNIT", tree.getRoot().isUnit());
    List<AdGroupCriterionOperation> mutateOperations = tree.getMutateOperations();
    assertEquals("Number of operations is incorrect", 1, mutateOperations.size());
    AdGroupCriterionOperation operation = mutateOperations.iterator().next();
    assertEquals("Should have a single operation to ADD the root node", Operator.ADD, operation.getOperator());
    BiddableAdGroupCriterion adGroupCriterion = (BiddableAdGroupCriterion) operation.getOperand();
    assertNull("Product dimension of operation's operand should be null", ((ProductPartition) adGroupCriterion.getCriterion()).getCaseValue());
    assertTrue("Partition ID of the operand should be negative", adGroupCriterion.getCriterion().getId().longValue() < 0L);
}
Also used : AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest) Test(org.junit.Test)

Example 4 with AdGroupCriterion

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion in project googleads-java-lib by googleads.

the class AddDynamicSearchAdsCampaign method addWebPageCriteria.

/**
 * Adds a web page criteria to target Dynamic Search Ads.
 */
private static void addWebPageCriteria(AdWordsServicesInterface adWordsServices, AdWordsSession session, AdGroup adGroup) throws ApiException, RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    // Create a webpage criterion for special offers.
    WebpageParameter param = new WebpageParameter();
    param.setCriterionName("Special offers");
    WebpageCondition urlCondition = new WebpageCondition();
    urlCondition.setOperand(WebpageConditionOperand.URL);
    urlCondition.setArgument("/specialoffers");
    WebpageCondition titleCondition = new WebpageCondition();
    titleCondition.setOperand(WebpageConditionOperand.PAGE_TITLE);
    titleCondition.setArgument("Special Offer");
    param.setConditions(new WebpageCondition[] { urlCondition, titleCondition });
    Webpage webpage = new Webpage();
    webpage.setParameter(param);
    // Create biddable ad group criterion.
    BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();
    biddableAdGroupCriterion.setAdGroupId(adGroup.getId());
    biddableAdGroupCriterion.setCriterion(webpage);
    biddableAdGroupCriterion.setUserStatus(UserStatus.PAUSED);
    // Optional: set a custom bid.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    CpcBid bid = new CpcBid();
    bid.setBid(new Money());
    bid.getBid().setMicroAmount(10000000L);
    biddingStrategyConfiguration.setBids(new Bids[] { bid });
    biddableAdGroupCriterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // Create operations.
    AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(biddableAdGroupCriterion);
    // Create the criterion.
    AdGroupCriterion newAdGroupCriterion = adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { operation }).getValue(0);
    System.out.printf("Webpage criterion with ID %d was added to ad group ID %d.%n", newAdGroupCriterion.getCriterion().getId(), newAdGroupCriterion.getAdGroupId());
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) Webpage(com.google.api.ads.adwords.axis.v201809.cm.Webpage) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) WebpageParameter(com.google.api.ads.adwords.axis.v201809.cm.WebpageParameter) WebpageCondition(com.google.api.ads.adwords.axis.v201809.cm.WebpageCondition)

Example 5 with AdGroupCriterion

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion in project googleads-java-lib by googleads.

the class AddShoppingDynamicRemarketingCampaign method attachUserList.

/**
 * Attach a user list to an ad group. The user list provides positive targeting and feed
 * information to drive the dynamic content of the ad.
 *
 * <p>Note: User lists must be attached at the ad group level for positive targeting in Shopping
 * dynamic remarketing campaigns.
 *
 * @param adGroup the ad group which will have the user list attached.
 * @param userListId the user list to use for targeting and dynamic content.
 */
private static void attachUserList(AdWordsServicesInterface services, AdWordsSession session, AdGroup adGroup, long userListId) throws RemoteException {
    AdGroupCriterionServiceInterface adGroupCriterionService = services.get(session, AdGroupCriterionServiceInterface.class);
    CriterionUserList userList = new CriterionUserList();
    userList.setUserListId(userListId);
    BiddableAdGroupCriterion adGroupCriterion = new BiddableAdGroupCriterion();
    adGroupCriterion.setCriterion(userList);
    adGroupCriterion.setAdGroupId(adGroup.getId());
    AdGroupCriterionOperation op = new AdGroupCriterionOperation();
    op.setOperand(adGroupCriterion);
    op.setOperator(Operator.ADD);
    adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { op });
}
Also used : AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) CriterionUserList(com.google.api.ads.adwords.axis.v201809.cm.CriterionUserList)

Aggregations

BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)18 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)17 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)13 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)10 AdGroupCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue)7 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)7 NegativeAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)7 ProductPartition (com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)7 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)6 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)6 MockHttpIntegrationTest (com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)6 Test (org.junit.Test)6 Bids (com.google.api.ads.adwords.axis.v201809.cm.Bids)3 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)3 ProductPartitionTree (com.google.api.ads.adwords.axis.utils.v201809.shopping.ProductPartitionTree)2 AdGroupCriterionPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionPage)2 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)2 ProductBrand (com.google.api.ads.adwords.axis.v201809.cm.ProductBrand)2 AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)2 AdWordsServicesInterface (com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface)2