Search in sources :

Example 6 with AdjustmentServiceInterface

use of com.google.api.ads.admanager.axis.v202202.AdjustmentServiceInterface in project googleads-java-lib by googleads.

the class GetAllForecastAdjustments method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices 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(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the AdjustmentService.
    AdjustmentServiceInterface adjustmentService = adManagerServices.get(session, AdjustmentServiceInterface.class);
    // Create a statement to get all forecast adjustments.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get forecast adjustments by statement.
        ForecastAdjustmentPage page = adjustmentService.getForecastAdjustmentsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (ForecastAdjustment adjustment : page.getResults()) {
                System.out.printf("%d) Forecast adjustment with ID %d and name '%s' belonging to ForecastSegment %d" + " was found.%n", i++, adjustment.getId(), adjustment.getName(), adjustment.getTrafficForecastSegmentId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) ForecastAdjustmentPage(com.google.api.ads.admanager.axis.v202111.ForecastAdjustmentPage) AdjustmentServiceInterface(com.google.api.ads.admanager.axis.v202111.AdjustmentServiceInterface) ForecastAdjustment(com.google.api.ads.admanager.axis.v202111.ForecastAdjustment)

Example 7 with AdjustmentServiceInterface

use of com.google.api.ads.admanager.axis.v202202.AdjustmentServiceInterface in project googleads-java-lib by googleads.

the class CreateTrafficForecastSegments method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices 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(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the adjustment service and the network service.
    AdjustmentServiceInterface adjustmentService = adManagerServices.get(session, AdjustmentServiceInterface.class);
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Get the root ad unit ID used to target the whole site.
    String rootAdUnitId = networkService.getCurrentNetwork().getEffectiveRootAdUnitId();
    // Create inventory targeting.
    InventoryTargeting inventoryTargeting = new InventoryTargeting();
    // Create ad unit targeting for the root ad unit (i.e. the whole network).
    AdUnitTargeting adUnitTargeting = new AdUnitTargeting();
    adUnitTargeting.setAdUnitId(rootAdUnitId);
    adUnitTargeting.setIncludeDescendants(true);
    inventoryTargeting.setTargetedAdUnits(new AdUnitTargeting[] { adUnitTargeting });
    // Create targeting for United States traffic.
    GeoTargeting geoTargeting = new GeoTargeting();
    Location countryLocation = new Location();
    countryLocation.setId(2840L);
    geoTargeting.setTargetedLocations(new Location[] { countryLocation });
    Targeting targeting = new Targeting();
    targeting.setInventoryTargeting(inventoryTargeting);
    targeting.setGeoTargeting(geoTargeting);
    TrafficForecastSegment segment = new TrafficForecastSegment();
    segment.setTargeting(targeting);
    segment.setName("Forecast segment #" + new Random().nextInt(Integer.MAX_VALUE));
    // Create the traffic forecst segment on the server.
    TrafficForecastSegment[] segments = adjustmentService.createTrafficForecastSegments(new TrafficForecastSegment[] { segment });
    for (TrafficForecastSegment createdSegment : segments) {
        System.out.printf("Traffic forecast segment with ID %d and %d forecast adjustments was created.%n", createdSegment.getId(), createdSegment.getActiveForecastAdjustmentCount());
    }
}
Also used : NetworkServiceInterface(com.google.api.ads.admanager.axis.v202202.NetworkServiceInterface) TrafficForecastSegment(com.google.api.ads.admanager.axis.v202202.TrafficForecastSegment) AdUnitTargeting(com.google.api.ads.admanager.axis.v202202.AdUnitTargeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202202.InventoryTargeting) Targeting(com.google.api.ads.admanager.axis.v202202.Targeting) GeoTargeting(com.google.api.ads.admanager.axis.v202202.GeoTargeting) AdUnitTargeting(com.google.api.ads.admanager.axis.v202202.AdUnitTargeting) Random(java.util.Random) AdjustmentServiceInterface(com.google.api.ads.admanager.axis.v202202.AdjustmentServiceInterface) InventoryTargeting(com.google.api.ads.admanager.axis.v202202.InventoryTargeting) GeoTargeting(com.google.api.ads.admanager.axis.v202202.GeoTargeting) Location(com.google.api.ads.admanager.axis.v202202.Location)

Example 8 with AdjustmentServiceInterface

use of com.google.api.ads.admanager.axis.v202202.AdjustmentServiceInterface in project googleads-java-lib by googleads.

the class CreateForecastAdjustments method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param trafficForecastSegmentId the ID of the traffic forecast segment to create the adjustment
 *  for.
 * @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(AdManagerServices adManagerServices, AdManagerSession session, long trafficForecastSegmentId) throws RemoteException {
    // Get the adjustment service.
    AdjustmentServiceInterface adjustmentService = adManagerServices.get(session, AdjustmentServiceInterface.class);
    ForecastAdjustment forecastAdjustment = new ForecastAdjustment();
    forecastAdjustment.setName("Forecast adjustment #" + new Random().nextInt(Integer.MAX_VALUE));
    forecastAdjustment.setTrafficForecastSegmentId(trafficForecastSegmentId);
    // Set the date range that this adjustment will be applied to.
    Date startDate = new Date(org.joda.time.DateTime.now().plusYears(1).getYear(), 1, 1);
    Date endDate = new Date(org.joda.time.DateTime.now().plusYears(1).getYear(), 1, 1);
    DateRange dateRange = new DateRange();
    dateRange.setStartDate(startDate);
    dateRange.setEndDate(endDate);
    forecastAdjustment.setDateRange(dateRange);
    // Set the adjustment type to be a historical basis.
    forecastAdjustment.setVolumeType(ForecastAdjustmentVolumeType.HISTORICAL_BASIS_VOLUME);
    HistoricalBasisVolumeSettings settings = new HistoricalBasisVolumeSettings();
    settings.setUseParentTrafficForecastSegmentTargeting(true);
    Date historicalStartDate = new Date(org.joda.time.DateTime.now().getYear(), 1, 1);
    Date historicalEndDate = new Date(org.joda.time.DateTime.now().getYear(), 1, 1);
    DateRange historicalDateRange = new DateRange();
    historicalDateRange.setStartDate(historicalStartDate);
    historicalDateRange.setEndDate(historicalEndDate);
    settings.setHistoricalDateRange(historicalDateRange);
    settings.setMultiplierMilliPercent(110000L);
    forecastAdjustment.setHistoricalBasisVolumeSettings(settings);
    forecastAdjustment.setStatus(ForecastAdjustmentStatus.ACTIVE);
    // Update the forecast adjustment on the server.
    ForecastAdjustment[] forecastAdjustments = adjustmentService.createForecastAdjustments(new ForecastAdjustment[] { forecastAdjustment });
    for (ForecastAdjustment createdForecastAdjustment : forecastAdjustments) {
        System.out.printf("Forecast adjustment with ID %d and name '%s' was created.%n", createdForecastAdjustment.getId(), createdForecastAdjustment.getName());
    }
}
Also used : DateRange(com.google.api.ads.admanager.axis.v202202.DateRange) Random(java.util.Random) HistoricalBasisVolumeSettings(com.google.api.ads.admanager.axis.v202202.HistoricalBasisVolumeSettings) AdjustmentServiceInterface(com.google.api.ads.admanager.axis.v202202.AdjustmentServiceInterface) ForecastAdjustment(com.google.api.ads.admanager.axis.v202202.ForecastAdjustment) Date(com.google.api.ads.admanager.axis.v202202.Date)

Example 9 with AdjustmentServiceInterface

use of com.google.api.ads.admanager.axis.v202202.AdjustmentServiceInterface in project googleads-java-lib by googleads.

the class GetAllForecastAdjustments method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices 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(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the AdjustmentService.
    AdjustmentServiceInterface adjustmentService = adManagerServices.get(session, AdjustmentServiceInterface.class);
    // Create a statement to get all forecast adjustments.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get forecast adjustments by statement.
        ForecastAdjustmentPage page = adjustmentService.getForecastAdjustmentsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (ForecastAdjustment adjustment : page.getResults()) {
                System.out.printf("%d) Forecast adjustment with ID %d and name '%s' belonging to ForecastSegment %d" + " was found.%n", i++, adjustment.getId(), adjustment.getName(), adjustment.getTrafficForecastSegmentId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) ForecastAdjustmentPage(com.google.api.ads.admanager.axis.v202202.ForecastAdjustmentPage) AdjustmentServiceInterface(com.google.api.ads.admanager.axis.v202202.AdjustmentServiceInterface) ForecastAdjustment(com.google.api.ads.admanager.axis.v202202.ForecastAdjustment)

Example 10 with AdjustmentServiceInterface

use of com.google.api.ads.admanager.axis.v202202.AdjustmentServiceInterface in project googleads-java-lib by googleads.

the class GetForecastAdjustmentsForTrafficForecastSegment method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices 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(AdManagerServices adManagerServices, AdManagerSession session, long trafficForecastSegmentId) throws RemoteException {
    // Get the AdjustmentService.
    AdjustmentServiceInterface adjustmentService = adManagerServices.get(session, AdjustmentServiceInterface.class);
    // Create a statement to get all forecast adjustments.
    StatementBuilder statementBuilder = new StatementBuilder().where("trafficForecastSegmentId = :trafficForecastSegmentId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("trafficForecastSegmentId", trafficForecastSegmentId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get forecast adjustments by statement.
        ForecastAdjustmentPage page = adjustmentService.getForecastAdjustmentsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (ForecastAdjustment adjustment : page.getResults()) {
                System.out.printf("%d) Forecast adjustment with ID %d and name '%s' belonging to the traffic forecast" + " segment %d was found.%n", i++, adjustment.getId(), adjustment.getName(), adjustment.getTrafficForecastSegmentId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) ForecastAdjustmentPage(com.google.api.ads.admanager.axis.v202202.ForecastAdjustmentPage) AdjustmentServiceInterface(com.google.api.ads.admanager.axis.v202202.AdjustmentServiceInterface) ForecastAdjustment(com.google.api.ads.admanager.axis.v202202.ForecastAdjustment)

Aggregations

AdjustmentServiceInterface (com.google.api.ads.admanager.axis.v202108.AdjustmentServiceInterface)6 AdjustmentServiceInterface (com.google.api.ads.admanager.axis.v202111.AdjustmentServiceInterface)6 AdjustmentServiceInterface (com.google.api.ads.admanager.axis.v202202.AdjustmentServiceInterface)6 Random (java.util.Random)6 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)4 ForecastAdjustment (com.google.api.ads.admanager.axis.v202108.ForecastAdjustment)4 ForecastAdjustment (com.google.api.ads.admanager.axis.v202111.ForecastAdjustment)4 ForecastAdjustment (com.google.api.ads.admanager.axis.v202202.ForecastAdjustment)4 ForecastAdjustmentPage (com.google.api.ads.admanager.axis.v202108.ForecastAdjustmentPage)3 ForecastAdjustmentPage (com.google.api.ads.admanager.axis.v202111.ForecastAdjustmentPage)3 ForecastAdjustmentPage (com.google.api.ads.admanager.axis.v202202.ForecastAdjustmentPage)3 TrafficForecastSegment (com.google.api.ads.admanager.axis.v202108.TrafficForecastSegment)2 TrafficForecastSegment (com.google.api.ads.admanager.axis.v202111.TrafficForecastSegment)2 AdUnitTargeting (com.google.api.ads.admanager.axis.v202108.AdUnitTargeting)1 Date (com.google.api.ads.admanager.axis.v202108.Date)1 DateRange (com.google.api.ads.admanager.axis.v202108.DateRange)1 GeoTargeting (com.google.api.ads.admanager.axis.v202108.GeoTargeting)1 HistoricalBasisVolumeSettings (com.google.api.ads.admanager.axis.v202108.HistoricalBasisVolumeSettings)1