Search in sources :

Example 1 with CriterionBidLandscape

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

the class GetKeywordBidSimulations method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group.
 * @param criterionId the ID of the criterion.
 * @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, Long criterionId) throws RemoteException {
    // Get the DataService.
    DataServiceInterface dataService = adWordsServices.get(session, DataServiceInterface.class);
    // Create a query to select all keyword bid simulations for the ad group.
    ServiceQuery query = new ServiceQuery.Builder().fields(DataField.AdGroupId, DataField.CriterionId, DataField.StartDate, DataField.EndDate, DataField.Bid, DataField.BiddableConversions, DataField.BiddableConversionsValue, DataField.LocalClicks, DataField.LocalCost, DataField.LocalImpressions).where(DataField.AdGroupId).equalTo(adGroupId).where(DataField.CriterionId).equalTo(criterionId).limit(0, PAGE_SIZE).build();
    // Display bid landscapes.
    CriterionBidLandscapePage page = null;
    do {
        query.nextPage(page);
        // Retrieve keyword bid simulations one page at a time, continuing to request pages until all
        // of them have been retrieved.
        page = dataService.queryCriterionBidLandscape(query.toString());
        if (page.getEntries() != null) {
            for (CriterionBidLandscape criterionBidLandscape : page.getEntries()) {
                System.out.printf("Criterion bid landscape with ad group ID %d, criterion ID %d, " + "start date %s, end date %s, with landscape points:%n", criterionBidLandscape.getAdGroupId(), criterionBidLandscape.getCriterionId(), criterionBidLandscape.getStartDate(), criterionBidLandscape.getEndDate());
                for (BidLandscapeLandscapePoint bidLanscapePoint : criterionBidLandscape.getLandscapePoints()) {
                    System.out.printf("\t{bid: %d clicks: %d cost: %d impressions: %d, biddable conversions: %.2f, " + "biddable conversions value: %.2f}%n", bidLanscapePoint.getBid().getMicroAmount(), bidLanscapePoint.getClicks(), bidLanscapePoint.getCost().getMicroAmount(), bidLanscapePoint.getImpressions(), bidLanscapePoint.getBiddableConversions(), bidLanscapePoint.getBiddableConversionsValue());
                }
                System.out.println(" was found.");
            }
        }
    } while (query.hasNext(page));
}
Also used : CriterionBidLandscapePage(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscapePage) CriterionBidLandscape(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscape) DataServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.DataServiceInterface) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) ServiceQuery(com.google.api.ads.adwords.axis.utils.v201809.ServiceQuery)

Example 2 with CriterionBidLandscape

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

the class GetCampaignCriterionBidModifierSimulations method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign.
 * @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 campaignId) throws RemoteException {
    // Get the DataService.
    DataServiceInterface dataService = adWordsServices.get(session, DataServiceInterface.class);
    // Create selector.
    Selector selector = new SelectorBuilder().fields(DataField.BidModifier, DataField.CampaignId, DataField.CriterionId, DataField.StartDate, DataField.EndDate, DataField.LocalClicks, DataField.LocalCost, DataField.LocalImpressions, DataField.TotalLocalClicks, DataField.TotalLocalCost, DataField.TotalLocalImpressions, DataField.RequiredBudget).equals(DataField.CampaignId, campaignId.toString()).limit(PAGE_SIZE).build();
    // Display bid landscapes.
    int landscapePointsInPreviousPage = 0;
    int startIndex = 0;
    do {
        // Offset the start index by the number of landscape points in the last retrieved page,
        // NOT the number of entries (bid landscapes) in the page.
        startIndex += landscapePointsInPreviousPage;
        selector.getPaging().setStartIndex(startIndex);
        // Reset the count of landscape points in preparation for processing the next page.
        landscapePointsInPreviousPage = 0;
        // Request the next page of bid landscapes.
        CriterionBidLandscapePage page = dataService.getCampaignCriterionBidLandscape(selector);
        if (page.getEntries() != null) {
            for (CriterionBidLandscape criterionBidLandscape : page.getEntries()) {
                System.out.printf("Found campaign-level criterion bid modifier landscape for" + " criterion with ID %d, start date '%s', end date '%s', and" + " landscape points:%n", criterionBidLandscape.getCriterionId(), criterionBidLandscape.getStartDate(), criterionBidLandscape.getEndDate());
                for (BidLandscapeLandscapePoint bidLandscapePoint : criterionBidLandscape.getLandscapePoints()) {
                    landscapePointsInPreviousPage++;
                    System.out.printf("  {bid modifier: %.2f => clicks: %d, cost: %d, impressions: %d, " + "total clicks: %d, total cost: %d, total impressions: %d, and " + "required budget: %d%n", bidLandscapePoint.getBidModifier(), bidLandscapePoint.getClicks(), bidLandscapePoint.getCost().getMicroAmount(), bidLandscapePoint.getImpressions(), bidLandscapePoint.getTotalLocalClicks(), bidLandscapePoint.getTotalLocalCost().getMicroAmount(), bidLandscapePoint.getTotalLocalImpressions(), bidLandscapePoint.getRequiredBudget().getMicroAmount());
                }
            }
        }
    } while (landscapePointsInPreviousPage >= PAGE_SIZE);
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) CriterionBidLandscapePage(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscapePage) CriterionBidLandscape(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscape) DataServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.DataServiceInterface) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 3 with CriterionBidLandscape

use of com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscape 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);
    CriterionBidLandscapePage page = mock(CriterionBidLandscapePage.class);
    when(page.getEntries()).thenReturn(ImmutableList.of(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.jaxws.v201809.cm.CriterionBidLandscapePage) ArrayList(java.util.ArrayList) CriterionBidLandscape(com.google.api.ads.adwords.jaxws.v201809.cm.CriterionBidLandscape) BidLandscapeLandscapePoint(com.google.api.ads.adwords.jaxws.v201809.cm.BidLandscapeLandscapePoint) BidLandscapeLandscapePoint(com.google.api.ads.adwords.jaxws.v201809.cm.BidLandscapeLandscapePoint) Test(org.junit.Test)

Example 4 with CriterionBidLandscape

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

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

Aggregations

BidLandscapeLandscapePoint (com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint)4 CriterionBidLandscape (com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscape)4 CriterionBidLandscapePage (com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscapePage)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 DataServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.DataServiceInterface)2 BidLandscapeLandscapePoint (com.google.api.ads.adwords.jaxws.v201809.cm.BidLandscapeLandscapePoint)2 CriterionBidLandscape (com.google.api.ads.adwords.jaxws.v201809.cm.CriterionBidLandscape)2 CriterionBidLandscapePage (com.google.api.ads.adwords.jaxws.v201809.cm.CriterionBidLandscapePage)2 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 ServiceQuery (com.google.api.ads.adwords.axis.utils.v201809.ServiceQuery)1 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)1