Search in sources :

Example 11 with Network

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

the class GetCurrentNetwork 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 NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Get the current network.
    Network network = networkService.getCurrentNetwork();
    System.out.printf("Current network has network code '%s' and display name '%s'.%n", network.getNetworkCode(), network.getDisplayName());
}
Also used : NetworkServiceInterface(com.google.api.ads.admanager.axis.v202111.NetworkServiceInterface) Network(com.google.api.ads.admanager.axis.v202111.Network)

Example 12 with Network

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

the class MakeTestNetwork 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 NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Make the test network.
    Network network = networkService.makeTestNetwork();
    System.out.printf("Test network with network code '%s' and display name '%s' created.%n" + "You may now sign in at https://admanager.google.com/%s%n", network.getNetworkCode(), network.getDisplayName(), network.getNetworkCode());
}
Also used : NetworkServiceInterface(com.google.api.ads.admanager.axis.v202111.NetworkServiceInterface) Network(com.google.api.ads.admanager.axis.v202111.Network)

Example 13 with Network

use of com.google.api.ads.admanager.axis.v202111.Network 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.v202111.NetworkServiceInterface) TrafficForecastSegment(com.google.api.ads.admanager.axis.v202111.TrafficForecastSegment) AdUnitTargeting(com.google.api.ads.admanager.axis.v202111.AdUnitTargeting) GeoTargeting(com.google.api.ads.admanager.axis.v202111.GeoTargeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202111.InventoryTargeting) Targeting(com.google.api.ads.admanager.axis.v202111.Targeting) AdUnitTargeting(com.google.api.ads.admanager.axis.v202111.AdUnitTargeting) Random(java.util.Random) AdjustmentServiceInterface(com.google.api.ads.admanager.axis.v202111.AdjustmentServiceInterface) InventoryTargeting(com.google.api.ads.admanager.axis.v202111.InventoryTargeting) GeoTargeting(com.google.api.ads.admanager.axis.v202111.GeoTargeting) Location(com.google.api.ads.admanager.axis.v202111.Location)

Example 14 with Network

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

the class CreateAudienceSegments method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param customTargetingKeyId the ID of the custom criteria to be used in the segment rule.
 * @param customTargetingValueId the custom targeting value ID.
 * @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 customTargetingKeyId, long customTargetingValueId) throws RemoteException {
    // Get the AudienceSegmentService.
    AudienceSegmentServiceInterface audienceSegmentService = adManagerServices.get(session, AudienceSegmentServiceInterface.class);
    // Get the NetworkService.
    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 the custom criteria to be used in the segment rule.
    // TARGETING_KEY_ID == TARGETING_VALUE_ID
    CustomCriteria customCriteria = new CustomCriteria();
    customCriteria.setKeyId(customTargetingKeyId);
    customCriteria.setOperator(CustomCriteriaComparisonOperator.IS);
    customCriteria.setValueIds(new long[] { customTargetingValueId });
    // Create the custom criteria expression.
    CustomCriteriaSet topCustomCriteriaSet = new CustomCriteriaSet();
    topCustomCriteriaSet.setLogicalOperator(CustomCriteriaSetLogicalOperator.AND);
    topCustomCriteriaSet.setChildren(new CustomCriteriaNode[] { customCriteria });
    // Create the audience segment rule.
    FirstPartyAudienceSegmentRule rule = new FirstPartyAudienceSegmentRule();
    rule.setInventoryRule(inventoryTargeting);
    rule.setCustomCriteriaRule(topCustomCriteriaSet);
    // Create an audience segment.
    RuleBasedFirstPartyAudienceSegment audienceSegment = new RuleBasedFirstPartyAudienceSegment();
    audienceSegment.setName("Sports enthusiasts audience segment #" + new Random().nextInt(Integer.MAX_VALUE));
    audienceSegment.setDescription("Sports enthusiasts between the ages of 20 and 30.");
    audienceSegment.setPageViews(6);
    audienceSegment.setRecencyDays(6);
    audienceSegment.setMembershipExpirationDays(88);
    audienceSegment.setRule(rule);
    // Create the audience segment on the server.
    AudienceSegment[] audienceSegments = audienceSegmentService.createAudienceSegments(new FirstPartyAudienceSegment[] { audienceSegment });
    for (AudienceSegment createdAudienceSegment : audienceSegments) {
        System.out.printf("An audience segment with ID %d, name '%s', and type '%s' was created.%n", createdAudienceSegment.getId(), createdAudienceSegment.getName(), createdAudienceSegment.getType());
    }
}
Also used : NetworkServiceInterface(com.google.api.ads.admanager.axis.v202111.NetworkServiceInterface) AdUnitTargeting(com.google.api.ads.admanager.axis.v202111.AdUnitTargeting) Random(java.util.Random) FirstPartyAudienceSegmentRule(com.google.api.ads.admanager.axis.v202111.FirstPartyAudienceSegmentRule) CustomCriteria(com.google.api.ads.admanager.axis.v202111.CustomCriteria) InventoryTargeting(com.google.api.ads.admanager.axis.v202111.InventoryTargeting) CustomCriteriaSet(com.google.api.ads.admanager.axis.v202111.CustomCriteriaSet) RuleBasedFirstPartyAudienceSegment(com.google.api.ads.admanager.axis.v202111.RuleBasedFirstPartyAudienceSegment) FirstPartyAudienceSegment(com.google.api.ads.admanager.axis.v202111.FirstPartyAudienceSegment) AudienceSegment(com.google.api.ads.admanager.axis.v202111.AudienceSegment) RuleBasedFirstPartyAudienceSegment(com.google.api.ads.admanager.axis.v202111.RuleBasedFirstPartyAudienceSegment) AudienceSegmentServiceInterface(com.google.api.ads.admanager.axis.v202111.AudienceSegmentServiceInterface)

Example 15 with Network

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

the class CreateSites method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param childNetworkCode the child network code of the site.
 * @param url the URL of the site.
 * @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, String childNetworkCode, String url) throws RemoteException {
    // Get the SiteService.
    SiteServiceInterface siteService = adManagerServices.get(session, SiteServiceInterface.class);
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Validate that the site can be created.
    Network currentNetwork = networkService.getCurrentNetwork();
    ChildPublisher childNetwork = null;
    for (ChildPublisher child : currentNetwork.getChildPublishers()) {
        if (childNetworkCode.equals(child.getChildNetworkCode())) {
            childNetwork = child;
            break;
        }
    }
    if (childNetwork == null) {
        throw new IllegalStateException(String.format("Child network %s not found on the current network (%s). Cannot create site.", childNetworkCode, currentNetwork.getNetworkCode()));
    }
    if (!DelegationType.MANAGE_INVENTORY.equals(childNetwork.getApprovedDelegationType())) {
        throw new IllegalStateException(String.format("Child network %s has not approved the current network (%s) to manage its inventory." + " Cannot create site.", childNetworkCode, currentNetwork.getNetworkCode()));
    }
    // Create a site.
    Site site = new Site();
    site.setChildNetworkCode(childNetworkCode);
    site.setUrl(url);
    // Create the site on the server.
    Site[] sites = siteService.createSites(new Site[] { site });
    for (Site createdSite : sites) {
        System.out.printf("A site with ID %d and URL '%s' was created.%n", createdSite.getId(), createdSite.getUrl());
    }
}
Also used : Site(com.google.api.ads.admanager.axis.v202202.Site) NetworkServiceInterface(com.google.api.ads.admanager.axis.v202202.NetworkServiceInterface) SiteServiceInterface(com.google.api.ads.admanager.axis.v202202.SiteServiceInterface) ChildPublisher(com.google.api.ads.admanager.axis.v202202.ChildPublisher) Network(com.google.api.ads.admanager.axis.v202202.Network)

Aggregations

NetworkServiceInterface (com.google.api.ads.admanager.axis.v202111.NetworkServiceInterface)10 Network (com.google.api.ads.admanager.axis.v202202.Network)6 NetworkServiceInterface (com.google.api.ads.admanager.axis.v202202.NetworkServiceInterface)6 Random (java.util.Random)6 AdUnitTargeting (com.google.api.ads.admanager.axis.v202111.AdUnitTargeting)5 InventoryTargeting (com.google.api.ads.admanager.axis.v202111.InventoryTargeting)5 Network (com.google.api.ads.admanager.axis.v202108.Network)4 NetworkServiceInterface (com.google.api.ads.admanager.axis.v202108.NetworkServiceInterface)4 Network (com.google.api.ads.admanager.axis.v202111.Network)4 Size (com.google.api.ads.admanager.axis.v202111.Size)4 Targeting (com.google.api.ads.admanager.axis.v202111.Targeting)4 CreativePlaceholder (com.google.api.ads.admanager.axis.v202111.CreativePlaceholder)3 Goal (com.google.api.ads.admanager.axis.v202111.Goal)3 Money (com.google.api.ads.admanager.axis.v202111.Money)3 CustomCriteria (com.google.api.ads.admanager.axis.v202111.CustomCriteria)2 CustomCriteriaSet (com.google.api.ads.admanager.axis.v202111.CustomCriteriaSet)2 GeoTargeting (com.google.api.ads.admanager.axis.v202111.GeoTargeting)2 LineItem (com.google.api.ads.admanager.axis.v202111.LineItem)2 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202111.LineItemServiceInterface)2 Location (com.google.api.ads.admanager.axis.v202111.Location)2