Search in sources :

Example 16 with Money

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

the class CreateVideoLineItems method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param orderId the ID of the order that the line item will belong to.
 * @param targetedVideoAdUnitId the ID of the d unit that the line item will target.
 * @param contentId the ID of the video content that the line item will target.
 * @param contentBundleId the ID of the video content bundle that the line item will target.
 * @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 orderId, String targetedVideoAdUnitId, long contentId, long contentBundleId, long cmsMetadataValueId) throws RemoteException {
    // Get the LineItemService.
    LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
    // Create content targeting.
    ContentTargeting contentTargeting = new ContentTargeting();
    contentTargeting.setTargetedContentIds(new long[] { contentId });
    contentTargeting.setTargetedVideoContentBundleIds(new long[] { contentBundleId });
    // Target only video players
    RequestPlatformTargeting requestPlatformTargeting = new RequestPlatformTargeting();
    requestPlatformTargeting.setTargetedRequestPlatforms(new RequestPlatform[] { RequestPlatform.VIDEO_PLAYER });
    // Create inventory targeting.
    InventoryTargeting inventoryTargeting = new InventoryTargeting();
    inventoryTargeting.setTargetedAdUnits(new AdUnitTargeting[] { new AdUnitTargeting(targetedVideoAdUnitId, true) });
    // Create video position targeting.
    VideoPosition videoPosition = new VideoPosition();
    videoPosition.setPositionType(VideoPositionType.PREROLL);
    VideoPositionTarget videoPositionTarget = new VideoPositionTarget();
    videoPositionTarget.setVideoPosition(videoPosition);
    VideoPositionTargeting videoPositionTargeting = new VideoPositionTargeting();
    videoPositionTargeting.setTargetedPositions(new VideoPositionTarget[] { videoPositionTarget });
    // Create custom targeting for CmsMetadataValues.
    CmsMetadataCriteria contentCustomCriteria = new CmsMetadataCriteria();
    contentCustomCriteria.setCmsMetadataValueIds(new long[] { cmsMetadataValueId });
    contentCustomCriteria.setOperator(CmsMetadataCriteriaComparisonOperator.EQUALS);
    CustomCriteriaSet customCriteriaSet = new CustomCriteriaSet();
    customCriteriaSet.setChildren(new CustomCriteriaNode[] { contentCustomCriteria });
    customCriteriaSet.setLogicalOperator(CustomCriteriaSetLogicalOperator.AND);
    // Create targeting.
    Targeting targeting = new Targeting();
    targeting.setContentTargeting(contentTargeting);
    targeting.setInventoryTargeting(inventoryTargeting);
    targeting.setVideoPositionTargeting(videoPositionTargeting);
    targeting.setRequestPlatformTargeting(requestPlatformTargeting);
    targeting.setCustomTargeting(customCriteriaSet);
    // Create local line item object.
    LineItem lineItem = new LineItem();
    lineItem.setName("Video line item #" + new Random().nextInt(Integer.MAX_VALUE));
    lineItem.setOrderId(orderId);
    lineItem.setTargeting(targeting);
    // Allow the line item to be booked even if there is not enough inventory.
    lineItem.setAllowOverbook(true);
    // Set the line item type to SPONSORSHIP.
    lineItem.setLineItemType(LineItemType.SPONSORSHIP);
    // Set the environment type to video.
    lineItem.setEnvironmentType(EnvironmentType.VIDEO_PLAYER);
    // Set the creative rotation type to optimized.
    lineItem.setCreativeRotationType(CreativeRotationType.OPTIMIZED);
    // Create the master creative placeholder.
    CreativePlaceholder creativeMasterPlaceholder = new CreativePlaceholder();
    creativeMasterPlaceholder.setSize(new Size(640, 360, false));
    // Create companion creative placeholders.
    CreativePlaceholder companionCreativePlaceholder = new CreativePlaceholder();
    companionCreativePlaceholder.setSize(new Size(300, 250, false));
    // Set companion creative placeholders.
    creativeMasterPlaceholder.setCompanions(new CreativePlaceholder[] { companionCreativePlaceholder });
    // Set the size of creatives that can be associated with this line item.
    lineItem.setCreativePlaceholders(new CreativePlaceholder[] { creativeMasterPlaceholder });
    // Set delivery of video companions to optional.
    lineItem.setCompanionDeliveryOption(CompanionDeliveryOption.OPTIONAL);
    // Set the maximum video creative length for this line item to 15 seconds.
    lineItem.setVideoMaxDuration(15000L);
    // Set the length of the line item to run.
    lineItem.setStartDateTimeType(StartDateTimeType.IMMEDIATELY);
    lineItem.setEndDateTime(DateTimes.toDateTime(Instant.now().plus(Duration.standardDays(30L)), "America/New_York"));
    // Set the cost per day to $1.
    lineItem.setCostType(CostType.CPD);
    lineItem.setCostPerUnit(new Money("USD", 1000000L));
    // Set the percentage to be 100%.
    Goal goal = new Goal();
    goal.setGoalType(GoalType.DAILY);
    goal.setUnits(100L);
    lineItem.setPrimaryGoal(goal);
    // Create the line item on the server.
    LineItem[] lineItems = lineItemService.createLineItems(new LineItem[] { lineItem });
    for (LineItem createdLineItem : lineItems) {
        System.out.printf("A video line item with ID %d and name '%s' was created.%n", createdLineItem.getId(), createdLineItem.getName());
    }
}
Also used : RequestPlatformTargeting(com.google.api.ads.admanager.axis.v202202.RequestPlatformTargeting) RequestPlatformTargeting(com.google.api.ads.admanager.axis.v202202.RequestPlatformTargeting) ContentTargeting(com.google.api.ads.admanager.axis.v202202.ContentTargeting) 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) VideoPositionTargeting(com.google.api.ads.admanager.axis.v202202.VideoPositionTargeting) LineItemServiceInterface(com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface) Size(com.google.api.ads.admanager.axis.v202202.Size) LineItem(com.google.api.ads.admanager.axis.v202202.LineItem) ContentTargeting(com.google.api.ads.admanager.axis.v202202.ContentTargeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202202.InventoryTargeting) VideoPositionTargeting(com.google.api.ads.admanager.axis.v202202.VideoPositionTargeting) CustomCriteriaSet(com.google.api.ads.admanager.axis.v202202.CustomCriteriaSet) VideoPosition(com.google.api.ads.admanager.axis.v202202.VideoPosition) CreativePlaceholder(com.google.api.ads.admanager.axis.v202202.CreativePlaceholder) Money(com.google.api.ads.admanager.axis.v202202.Money) Goal(com.google.api.ads.admanager.axis.v202202.Goal) AdUnitTargeting(com.google.api.ads.admanager.axis.v202202.AdUnitTargeting) Random(java.util.Random) VideoPositionTarget(com.google.api.ads.admanager.axis.v202202.VideoPositionTarget) CmsMetadataCriteria(com.google.api.ads.admanager.axis.v202202.CmsMetadataCriteria)

Aggregations

Random (java.util.Random)16 AdUnitTargeting (com.google.api.ads.admanager.axis.v202108.AdUnitTargeting)4 CreativePlaceholder (com.google.api.ads.admanager.axis.v202108.CreativePlaceholder)4 Goal (com.google.api.ads.admanager.axis.v202108.Goal)4 InventoryTargeting (com.google.api.ads.admanager.axis.v202108.InventoryTargeting)4 Money (com.google.api.ads.admanager.axis.v202108.Money)4 Size (com.google.api.ads.admanager.axis.v202108.Size)4 Targeting (com.google.api.ads.admanager.axis.v202108.Targeting)4 AdUnitTargeting (com.google.api.ads.admanager.axis.v202111.AdUnitTargeting)4 CreativePlaceholder (com.google.api.ads.admanager.axis.v202111.CreativePlaceholder)4 Goal (com.google.api.ads.admanager.axis.v202111.Goal)4 InventoryTargeting (com.google.api.ads.admanager.axis.v202111.InventoryTargeting)4 Money (com.google.api.ads.admanager.axis.v202111.Money)4 Size (com.google.api.ads.admanager.axis.v202111.Size)4 Targeting (com.google.api.ads.admanager.axis.v202111.Targeting)4 AdUnitTargeting (com.google.api.ads.admanager.axis.v202205.AdUnitTargeting)4 CreativePlaceholder (com.google.api.ads.admanager.axis.v202205.CreativePlaceholder)4 Goal (com.google.api.ads.admanager.axis.v202205.Goal)4 InventoryTargeting (com.google.api.ads.admanager.axis.v202205.InventoryTargeting)4 Money (com.google.api.ads.admanager.axis.v202205.Money)4