Search in sources :

Example 11 with BiddableAdGroupCriterion

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

the class JaxWsBatchJobResponseDeserializerTest method testDeserializeBatchJobResponseWithoutErrors.

/**
 * Tests that a response without errors will be properly deserialized.
 */
@Test
public void testDeserializeBatchJobResponseWithoutErrors() throws Exception {
    BatchJobMutateResponse response = deserializer.deserializeBatchJobMutateResults(BatchJobMutateResponse.class, JaxWsBatchJobResponseDeserializerTest.class.getResource("resources/BatchJobMutate.responseWithoutErrors.xml"));
    assertNotNull(response);
    // Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion
    assertEquals(4, response.getMutateResults().length);
    assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
    assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
    assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
    assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
    assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
    assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
}
Also used : BatchJobMutateResponse(com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse) BiddableAdGroupCriterion(com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion) Test(org.junit.Test)

Example 12 with BiddableAdGroupCriterion

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

the class AddDynamicPageFeed method addDsaTargeting.

/**
 * Sets custom targeting for the page feed URLs based on a list of labels.
 *
 * @param adWordsServices
 * @param session
 * @param adGroupId
 * @param dsaPageUrlLabel
 */
private static void addDsaTargeting(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long adGroupId, String dsaPageUrlLabel) throws ApiException, RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    // Create a webpage criterion.
    Webpage webpage = new Webpage();
    WebpageParameter parameter = new WebpageParameter();
    parameter.setCriterionName("Test criterion");
    webpage.setParameter(parameter);
    // Add a condition for label=specified_label_name.
    WebpageCondition condition = new WebpageCondition();
    condition.setOperand(WebpageConditionOperand.CUSTOM_LABEL);
    condition.setArgument(dsaPageUrlLabel);
    parameter.setConditions(new WebpageCondition[] { condition });
    BiddableAdGroupCriterion criterion = new BiddableAdGroupCriterion();
    criterion.setAdGroupId(adGroupId);
    criterion.setCriterion(webpage);
    // Set a custom bid for this criterion.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    CpcBid cpcBid = new CpcBid();
    Money money = new Money();
    money.setMicroAmount(1_500_000L);
    cpcBid.setBid(money);
    biddingStrategyConfiguration.setBids(new Bids[] { cpcBid });
    criterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
    operation.setOperand(criterion);
    operation.setOperator(Operator.ADD);
    BiddableAdGroupCriterion newCriterion = (BiddableAdGroupCriterion) adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { operation }).getValue(0);
    System.out.printf("Web page criterion with ID %d and status '%s' was created.%n", newCriterion.getCriterion().getId(), newCriterion.getUserStatus());
}
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) 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 13 with BiddableAdGroupCriterion

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

the class AddDemographicTargetingCriteria method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group where demographic targeting will be modified.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long adGroupId) throws RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    // https://developers.google.com/adwords/api/docs/appendix/genders
    Gender male = new Gender();
    male.setId(10L);
    BiddableAdGroupCriterion genderBiddableAdGroupCriterion = new BiddableAdGroupCriterion();
    genderBiddableAdGroupCriterion.setAdGroupId(adGroupId);
    genderBiddableAdGroupCriterion.setCriterion(male);
    // https://developers.google.com/adwords/api/docs/appendix/ages
    AgeRange undetermined = new AgeRange();
    undetermined.setId(503999L);
    NegativeAdGroupCriterion ageRangeNegativeAdGroupCriterion = new NegativeAdGroupCriterion();
    ageRangeNegativeAdGroupCriterion.setAdGroupId(adGroupId);
    ageRangeNegativeAdGroupCriterion.setCriterion(undetermined);
    AdGroupCriterionOperation genderAdGroupCriterionOperation = new AdGroupCriterionOperation();
    genderAdGroupCriterionOperation.setOperand(genderBiddableAdGroupCriterion);
    genderAdGroupCriterionOperation.setOperator(Operator.ADD);
    AdGroupCriterionOperation ageRangeNegativeAdGroupCriterionOperation = new AdGroupCriterionOperation();
    ageRangeNegativeAdGroupCriterionOperation.setOperand(ageRangeNegativeAdGroupCriterion);
    ageRangeNegativeAdGroupCriterionOperation.setOperator(Operator.ADD);
    AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { genderAdGroupCriterionOperation, ageRangeNegativeAdGroupCriterionOperation });
    // Display campaigns.
    for (AdGroupCriterion adGroupCriterion : result.getValue()) {
        System.out.printf("AdGroup criterion with adGroup ID %d, criterion ID %d, " + "and type '%s' was added.%n", adGroupCriterion.getAdGroupId(), adGroupCriterion.getCriterion().getId(), adGroupCriterion.getCriterion().getCriterionType());
    }
}
Also used : AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) AdGroupCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AgeRange(com.google.api.ads.adwords.axis.v201809.cm.AgeRange) 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) Gender(com.google.api.ads.adwords.axis.v201809.cm.Gender) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)

Example 14 with BiddableAdGroupCriterion

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

the class ProductPartitionTreeImpl method createAdGroupTree.

/**
 * Returns a new instance of this class based on the collection of ad group criteria provided.
 * <p>NOTE: If retrieving existing criteria for use with this method, you must include all of the
 * fields in {@link #REQUIRED_SELECTOR_FIELD_ENUMS} in your {@link Selector}.
 *
 * @param adGroupId the ID of the ad group
 * @param biddingStrategyConfig the {@link BiddingStrategyConfiguration} for the ad group
 * @param adGroupCriteria the non-null (but possibly empty) list of ad group criteria
 *
 * @throws NullPointerException if any argument is null, any element in {@code adGroupCriteria} is
 *         null, or any required field from {@link #REQUIRED_SELECTOR_FIELD_ENUMS} is missing from
 *         an element in {@code adGroupCriteria}
 * @throws IllegalArgumentException if {@code adGroupCriteria} does not include the root criterion
 *         of the product partition tree
 */
static ProductPartitionTreeImpl createAdGroupTree(Long adGroupId, BiddingStrategyConfiguration biddingStrategyConfig, List<AdGroupCriterion> adGroupCriteria) {
    Preconditions.checkNotNull(adGroupId, "Null ad group ID");
    Preconditions.checkNotNull(biddingStrategyConfig, "Null bidding strategy configuration");
    Preconditions.checkNotNull(adGroupCriteria, "Null criteria list");
    if (adGroupCriteria.isEmpty()) {
        return createEmptyAdGroupTree(adGroupId, biddingStrategyConfig);
    }
    ListMultimap<Long, AdGroupCriterion> parentIdMap = LinkedListMultimap.create();
    for (AdGroupCriterion adGroupCriterion : adGroupCriteria) {
        Preconditions.checkNotNull(adGroupCriterion.getCriterion(), "AdGroupCriterion has a null criterion");
        if (adGroupCriterion instanceof BiddableAdGroupCriterion) {
            BiddableAdGroupCriterion biddableCriterion = (BiddableAdGroupCriterion) adGroupCriterion;
            Preconditions.checkNotNull(biddableCriterion.getUserStatus(), "User status is null for criterion ID %s", biddableCriterion.getCriterion().getId());
            if (UserStatus.REMOVED.equals(biddableCriterion.getUserStatus())) {
                // Skip REMOVED criteria.
                continue;
            }
        }
        if (adGroupCriterion.getCriterion() instanceof ProductPartition) {
            ProductPartition partition = (ProductPartition) adGroupCriterion.getCriterion();
            parentIdMap.put(partition.getParentCriterionId(), adGroupCriterion);
        }
    }
    return createNonEmptyAdGroupTree(adGroupId, parentIdMap);
}
Also used : BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) ProductPartition(com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)

Example 15 with BiddableAdGroupCriterion

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

the class ProductPartitionTreeImpl method getBid.

/**
 * Returns the criterion-level bid, or null if no such bid exists.
 */
private static Money getBid(BiddableAdGroupCriterion biddableCriterion) {
    BiddingStrategyConfiguration biddingConfig = biddableCriterion.getBiddingStrategyConfiguration();
    Money cpcBidAmount = null;
    if (biddingConfig.getBids() != null) {
        for (Bids bid : biddingConfig.getBids()) {
            if (bid instanceof CpcBid) {
                CpcBid cpcBid = (CpcBid) bid;
                if (BidSource.CRITERION.equals(cpcBid.getCpcBidSource())) {
                    cpcBidAmount = cpcBid.getBid();
                    break;
                }
            }
        }
    }
    return cpcBidAmount;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) Bids(com.google.api.ads.adwords.axis.v201809.cm.Bids) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid)

Aggregations

BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)18 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)11 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)11 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)9 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)8 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)7 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)7 Test (org.junit.Test)7 NegativeAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)5 ProductPartition (com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)5 AdGroupCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue)4 Bids (com.google.api.ads.adwords.axis.v201809.cm.Bids)4 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)4 BatchJobMutateResponse (com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse)3 BiddableAdGroupCriterion (com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion)3 MockHttpIntegrationTest (com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)3 ArrayList (java.util.ArrayList)3 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)2 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)2 Webpage (com.google.api.ads.adwords.axis.v201809.cm.Webpage)2