use of com.google.api.ads.admanager.axis.v202205.NetworkServiceInterface in project googleads-java-lib by googleads.
the class GetAdUnitHierarchy 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 InventoryService.
InventoryServiceInterface inventoryService = adManagerServices.get(session, InventoryServiceInterface.class);
// Get the NetworkService.
NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
// Get the effective root ad unit.
String rootAdUnitId = networkService.getCurrentNetwork().getEffectiveRootAdUnitId();
// Create a statement to select only the root ad unit by ID.
StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", rootAdUnitId);
AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.toStatement());
AdUnit effectiveRootAdUnit = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
// Get all ad units.
List<AdUnit> adUnits = getAllAdUnits(adManagerServices, session);
buildAndDisplayAdUnitTree(effectiveRootAdUnit, adUnits);
}
use of com.google.api.ads.admanager.axis.v202205.NetworkServiceInterface 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());
}
}
use of com.google.api.ads.admanager.axis.v202205.NetworkServiceInterface 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());
}
}
use of com.google.api.ads.admanager.axis.v202205.NetworkServiceInterface 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());
}
}
use of com.google.api.ads.admanager.axis.v202205.NetworkServiceInterface in project googleads-java-lib by googleads.
the class GetDefaultThirdPartyDataDeclaration 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 Exception {
// Get the NetworkService.
NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
// Get the PublisherQueryLanguageService.
PublisherQueryLanguageServiceInterface pqlService = adManagerServices.get(session, PublisherQueryLanguageServiceInterface.class);
// Get the current network's default third party data declaration.
ThirdPartyDataDeclaration declaration = networkService.getDefaultThirdPartyDataDeclaration();
if (declaration == null) {
System.out.println("No default ad technology partners have been set on this network.");
} else if (DeclarationType.NONE.equals(declaration.getDeclarationType()) || declaration.getThirdPartyCompanyIds().length == 0) {
System.out.println("This network has specified that there are no ad technology providers " + " associated with its reservation creatives by default.");
} else {
System.out.printf("This network has specified %d ad technology provider(s) associated with its reservation" + " creatives by default:%n", declaration.getThirdPartyCompanyIds().length);
ResultSet companies = pqlService.select(new StatementBuilder().select("name, id").from("rich_media_ad_company").where("id in (:ids)").withBindVariableValue("ids", ImmutableSet.copyOf(Longs.asList(declaration.getThirdPartyCompanyIds()))).toStatement());
System.out.println(Pql.resultSetToString(companies));
}
}
Aggregations