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());
}
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());
}
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));
}
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);
}
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;
}
Aggregations