Search in sources :

Example 21 with Criterion

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

the class GetCampaignTargetingCriteria method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @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) throws RemoteException {
    // Get the CampaignService.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    int offset = 0;
    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(CampaignCriterionField.CampaignId, CampaignCriterionField.Id, CampaignCriterionField.CriteriaType, CampaignCriterionField.PlatformName, CampaignCriterionField.LanguageName, CampaignCriterionField.LocationName, CampaignCriterionField.KeywordText).in(CampaignCriterionField.CriteriaType, "KEYWORD", "LANGUAGE", "LOCATION", "PLATFORM").offset(0).limit(PAGE_SIZE).build();
    CampaignCriterionPage page = null;
    do {
        page = campaignCriterionService.get(selector);
        if (page.getEntries() != null) {
            // Display campaigns.
            for (CampaignCriterion campaignCriterion : page.getEntries()) {
                System.out.printf("Campaign criterion with campaign ID %d, criterion ID %d, " + "and type '%s' was found.%n", campaignCriterion.getCampaignId(), campaignCriterion.getCriterion().getId(), campaignCriterion.getCriterion().getCriterionType());
            }
        } else {
            System.out.println("No campaign criteria were found.");
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
    } while (offset < page.getTotalNumEntries());
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) CampaignCriterionPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionPage) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 22 with Criterion

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

the class ServiceQueryTest method testNextPageWithSpecifiedCriterionBidLandscapePage.

/**
 * Tests using {@link ServiceQuery#nextPage(CriterionBidLandscapePage)} ] to get a next page of
 * the result by specifying the previous criterion bid landscape page.
 */
@Test
public void testNextPageWithSpecifiedCriterionBidLandscapePage() {
    // Make criterion bid landscape page contain 400 bid landscape points (200 per criterion bid
    // landscape point).
    int numBidLandscapePoints = 200;
    BidLandscapeLandscapePoint bidLandscapeLandscapePoint = new BidLandscapeLandscapePoint();
    List<BidLandscapeLandscapePoint> bidLandscapeLandscapePoints = new ArrayList<>();
    bidLandscapeLandscapePoints.addAll(Collections.nCopies(numBidLandscapePoints, bidLandscapeLandscapePoint));
    CriterionBidLandscape bidLandscape = mock(CriterionBidLandscape.class);
    when(bidLandscape.getLandscapePoints()).thenReturn(bidLandscapeLandscapePoints.toArray(new BidLandscapeLandscapePoint[0]));
    CriterionBidLandscapePage page = mock(CriterionBidLandscapePage.class);
    when(page.getEntries()).thenReturn(new CriterionBidLandscape[] { bidLandscape, bidLandscape });
    expectedAwql = "SELECT Id, Name WHERE Status = \"ENABLED\" ORDER BY Name DESC LIMIT 400,100";
    serviceQuery.nextPage(page);
    assertEquals(expectedAwql, serviceQuery.toString());
}
Also used : CriterionBidLandscapePage(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscapePage) ArrayList(java.util.ArrayList) CriterionBidLandscape(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscape) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) Test(org.junit.Test)

Example 23 with Criterion

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

the class ServiceQueryTest method testHasNextWithSpecifiedCriterionBidLandscapePage.

/**
 * Tests using {@link ServiceQuery#hasNext(CriterionBidLandscapePage)} to check if there is still
 * a next page.
 */
@Test
public void testHasNextWithSpecifiedCriterionBidLandscapePage() {
    // First iteration. There are no previous pages.
    CriterionBidLandscapePage page = null;
    assertTrue(serviceQuery.hasNext(page));
    // Make criterion bid landscape page contain 400 bid landscape points (200 per criterion bid
    // landscape point).
    int numBidLandscapePoints = 200;
    BidLandscapeLandscapePoint bidLandscapeLandscapePoint = new BidLandscapeLandscapePoint();
    List<BidLandscapeLandscapePoint> bidLandscapeLandscapePoints = new ArrayList<>();
    bidLandscapeLandscapePoints.addAll(Collections.nCopies(numBidLandscapePoints, bidLandscapeLandscapePoint));
    CriterionBidLandscape bidLandscape = mock(CriterionBidLandscape.class);
    when(bidLandscape.getLandscapePoints()).thenReturn(bidLandscapeLandscapePoints.toArray(new BidLandscapeLandscapePoint[0]));
    page = mock(CriterionBidLandscapePage.class);
    when(page.getEntries()).thenReturn(new CriterionBidLandscape[] { bidLandscape, bidLandscape });
    serviceQuery = new ServiceQuery.Builder().fields("Id", "Name").limit(0, 100).build();
    // 2 * 200 landscape points are greater than the page size that is 100.
    assertTrue(serviceQuery.hasNext(page));
    serviceQuery = new ServiceQuery.Builder().fields("Id", "Name").limit(0, 500).build();
    // 2 * 200 landscape points are less than the page size that is 500.
    assertFalse(serviceQuery.hasNext(page));
}
Also used : CriterionBidLandscapePage(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscapePage) ArrayList(java.util.ArrayList) CriterionBidLandscape(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscape) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) Test(org.junit.Test)

Example 24 with Criterion

use of com.google.api.ads.adwords.axis.v201809.cm.Criterion 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 25 with Criterion

use of com.google.api.ads.adwords.axis.v201809.cm.Criterion 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

AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)14 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)13 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)11 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)10 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)9 ArrayList (java.util.ArrayList)9 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)8 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)8 AdGroupCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue)7 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)7 CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)6 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)6 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)5 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)5 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)5 NegativeAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)5 ProductPartition (com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)5 BidLandscapeLandscapePoint (com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint)4 Bids (com.google.api.ads.adwords.axis.v201809.cm.Bids)4 CampaignCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue)4