/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the LineItemService. LineItemService lineItemService = (LineItemService)user.GetService(DfpService.v201511.LineItemService); // Set the order that all created line items will belong to and the // video ad unit ID to target. long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE")); string targetedVideoAdUnitId = _T("INSERT_TARGETED_VIDEO_AD_UNIT_ID_HERE"); // Set the custom targeting value ID representing the metadata // on the content to target. This would typically be from a key representing // a "genre" and a value representing something like "comedy". The value must // be from a key in a content metadata key hierarchy. long contentCustomTargetingValueId = long.Parse(_T("INSERT_CONTENT_CUSTOM_TARGETING_VALUE_ID_HERE")); // Create content targeting. ContentMetadataKeyHierarchyTargeting contentMetadataTargeting = new ContentMetadataKeyHierarchyTargeting(); contentMetadataTargeting.customTargetingValueIds = new long[] { contentCustomTargetingValueId }; ContentTargeting contentTargeting = new ContentTargeting(); contentTargeting.targetedContentMetadata = new ContentMetadataKeyHierarchyTargeting[] { contentMetadataTargeting }; // Create inventory targeting. InventoryTargeting inventoryTargeting = new InventoryTargeting(); AdUnitTargeting adUnitTargeting = new AdUnitTargeting(); adUnitTargeting.adUnitId = targetedVideoAdUnitId; adUnitTargeting.includeDescendants = true; inventoryTargeting.targetedAdUnits = new AdUnitTargeting[] { adUnitTargeting }; // Create video position targeting. VideoPosition videoPosition = new VideoPosition(); videoPosition.positionType = VideoPositionType.PREROLL; VideoPositionTarget videoPositionTarget = new VideoPositionTarget(); videoPositionTarget.videoPosition = videoPosition; VideoPositionTargeting videoPositionTargeting = new VideoPositionTargeting(); videoPositionTargeting.targetedPositions = new VideoPositionTarget[] { videoPositionTarget }; // Create targeting. Targeting targeting = new Targeting(); targeting.contentTargeting = contentTargeting; targeting.inventoryTargeting = inventoryTargeting; targeting.videoPositionTargeting = videoPositionTargeting; // Create local line item object. LineItem lineItem = new LineItem(); lineItem.name = "Video line item - " + this.GetTimeStamp(); lineItem.orderId = orderId; lineItem.targeting = targeting; lineItem.lineItemType = LineItemType.SPONSORSHIP; lineItem.allowOverbook = true; // Set the environment type to video. lineItem.environmentType = EnvironmentType.VIDEO_PLAYER; // Set the creative rotation type to optimized. lineItem.creativeRotationType = CreativeRotationType.OPTIMIZED; // Create the master creative placeholder. CreativePlaceholder creativeMasterPlaceholder = new CreativePlaceholder(); Size size1 = new Size(); size1.width = 400; size1.height = 300; size1.isAspectRatio = false; creativeMasterPlaceholder.size = size1; // Create companion creative placeholders. CreativePlaceholder companionCreativePlaceholder1 = new CreativePlaceholder(); Size size2 = new Size(); size2.width = 300; size2.height = 250; size2.isAspectRatio = false; companionCreativePlaceholder1.size = size2; CreativePlaceholder companionCreativePlaceholder2 = new CreativePlaceholder(); Size size3 = new Size(); size3.width = 728; size3.height = 90; size3.isAspectRatio = false; companionCreativePlaceholder2.size = size3; // Set companion creative placeholders. creativeMasterPlaceholder.companions = new CreativePlaceholder[] { companionCreativePlaceholder1, companionCreativePlaceholder2 }; // Set the size of creatives that can be associated with this line item. lineItem.creativePlaceholders = new CreativePlaceholder[] { creativeMasterPlaceholder }; // Set delivery of video companions to optional. lineItem.companionDeliveryOption = CompanionDeliveryOption.OPTIONAL; // Set the line item to run for one month. lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY; lineItem.endDateTime = DateTimeUtilities.FromDateTime(System.DateTime.Now.AddMonths(1), "America/New_York"); // Set the cost per day to $1. lineItem.costType = CostType.CPD; Money money = new Money(); money.currencyCode = "USD"; money.microAmount = 1000000L; lineItem.costPerUnit = money; // Set the percentage to be 100%. Goal goal = new Goal(); goal.goalType = GoalType.DAILY; goal.unitType = UnitType.IMPRESSIONS; goal.units = 100; lineItem.primaryGoal = goal; try { // Create the line item on the server. LineItem[] createdLineItems = lineItemService.createLineItems(new LineItem[] { lineItem }); foreach (LineItem createdLineItem in createdLineItems) { Console.WriteLine("A line item with ID \"{0}\", belonging to order ID \"{1}\", and " + "named \"{2}\" was created.", createdLineItem.id, createdLineItem.orderId, createdLineItem.name); } } catch (Exception e) { Console.WriteLine("Failed to create line items. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code examples. /// </summary> public void Run(AdManagerUser user) { using (ProposalLineItemService proposalLineItemService = user.GetService <ProposalLineItemService>()) using (NetworkService networkService = user.GetService <NetworkService>()) { long proposalId = long.Parse(_T("INSERT_PROPOSAL_ID_HERE")); long rateCardId = long.Parse(_T("INSERT_RATE_CARD_ID_HERE")); long productId = long.Parse(_T("INSERT_PRODUCT_ID_HERE")); // Get the root ad unit ID used to target the whole site. String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId; // 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.adUnitId = rootAdUnitId; adUnitTargeting.includeDescendants = true; inventoryTargeting.targetedAdUnits = new AdUnitTargeting[] { adUnitTargeting }; // Create targeting. Targeting targeting = new Targeting(); targeting.inventoryTargeting = inventoryTargeting; // Create a proposal line item. ProposalLineItem proposalLineItem = new ProposalLineItem(); proposalLineItem.name = "Proposal line item #" + new Random().Next(int.MaxValue); proposalLineItem.proposalId = proposalId; proposalLineItem.rateCardId = rateCardId; proposalLineItem.productId = productId; proposalLineItem.targeting = targeting; // Set the length of the proposal line item to run. proposalLineItem.startDateTime = DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(7), "America/New_York"); proposalLineItem.endDateTime = DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(30), "America/New_York"); // Set delivery specifications for the proposal line item. proposalLineItem.deliveryRateType = DeliveryRateType.EVENLY; proposalLineItem.creativeRotationType = CreativeRotationType.OPTIMIZED; // Set billing specifications for the proposal line item. proposalLineItem.billingCap = BillingCap.CAPPED_CUMULATIVE; proposalLineItem.billingSource = BillingSource.THIRD_PARTY_VOLUME; // Set pricing for the proposal line item for 1000 impressions at a CPM of $2 // for a total value of $2. proposalLineItem.goal = new Goal() { unitType = UnitType.IMPRESSIONS, units = 1000L }; proposalLineItem.netCost = new Money() { currencyCode = "USD", microAmount = 2000000L }; proposalLineItem.netRate = new Money() { currencyCode = "USD", microAmount = 2000000L }; proposalLineItem.rateType = RateType.CPM; try { // Create the proposal line item on the server. ProposalLineItem[] proposalLineItems = proposalLineItemService.createProposalLineItems(new ProposalLineItem[] { proposalLineItem }); foreach (ProposalLineItem createdProposalLineItem in proposalLineItems) { Console.WriteLine( "A proposal line item with ID \"{0}\" and name \"{1}\" was " + "created.", createdProposalLineItem.id, createdProposalLineItem.name); } } catch (Exception e) { Console.WriteLine( "Failed to create proposal line items. Exception says \"{0}\"", e.Message); } } }
/// <summary> /// Run the code examples. /// </summary> public void Run(DfpUser user) { using (ProductService productTemplateService = (ProductService)user.GetService(DfpService.v201708.ProductService)) using (NetworkService networkService = (NetworkService)user.GetService(DfpService.v201708.NetworkService)) { // Create a product. Product product = new Product(); product.name = "Non-sales programmatic product #" + new Random().Next(int.MaxValue); // Set required Marketplace information. product.productMarketplaceInfo = new ProductMarketplaceInfo() { additionalTerms = "Additional terms for the product", adExchangeEnvironment = AdExchangeEnvironment.DISPLAY }; // Set common required fields for a programmatic product. product.productType = ProductType.DFP; product.rateType = RateType.CPM; product.lineItemType = LineItemType.STANDARD; product.priority = 8; product.environmentType = EnvironmentType.BROWSER; product.rate = new Money() { currencyCode = "USD", microAmount = 6000000L }; CreativePlaceholder placeholder = new CreativePlaceholder(); placeholder.size = new Size() { width = 300, height = 250, isAspectRatio = false }; product.creativePlaceholders = new CreativePlaceholder[] { placeholder }; // Create inventory targeting to serve to run of network.. String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId; AdUnitTargeting adUnitTargeting = new AdUnitTargeting(); adUnitTargeting.adUnitId = rootAdUnitId; adUnitTargeting.includeDescendants = true; Targeting productTargeting = new Targeting(); productTargeting.inventoryTargeting = new InventoryTargeting() { targetedAdUnits = new AdUnitTargeting[] { adUnitTargeting } }; product.builtInTargeting = productTargeting; try { // Create the product on the server. Product[] products = productTemplateService.createProducts( new Product[] { product }); foreach (Product createdProduct in products) { Console.WriteLine("A programmatic product with ID \"{0}\" and name \"{1}\" " + "was created.", createdProduct.id, createdProduct.name); } } catch (Exception e) { Console.WriteLine("Failed to create products. Exception says \"{0}\"", e.Message); } } }
/// <summary> /// Run the code examples. /// </summary> public void Run(AdManagerUser user, long proposalId) { using (ProposalLineItemService proposalLineItemService = user.GetService <ProposalLineItemService>()) using (NetworkService networkService = user.GetService <NetworkService>()) { ProposalLineItem proposalLineItem = new ProposalLineItem(); proposalLineItem.name = "Programmatic proposal line item #" + new Random().Next(int.MaxValue); proposalLineItem.proposalId = proposalId; proposalLineItem.lineItemType = LineItemType.STANDARD; // Set required Marketplace information. proposalLineItem.marketplaceInfo = new ProposalLineItemMarketplaceInfo() { adExchangeEnvironment = AdExchangeEnvironment.DISPLAY }; // Get the root ad unit ID used to target the whole site. String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId; // 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.adUnitId = rootAdUnitId; adUnitTargeting.includeDescendants = true; inventoryTargeting.targetedAdUnits = new AdUnitTargeting[] { adUnitTargeting }; // Create targeting. Targeting targeting = new Targeting(); targeting.inventoryTargeting = inventoryTargeting; proposalLineItem.targeting = targeting; // Create creative placeholder. Size size = new Size() { width = 300, height = 250, isAspectRatio = false }; CreativePlaceholder creativePlaceholder = new CreativePlaceholder(); creativePlaceholder.size = size; proposalLineItem.creativePlaceholders = new CreativePlaceholder[] { creativePlaceholder }; // Set the length of the proposal line item to run. proposalLineItem.startDateTime = DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(7), "America/New_York"); proposalLineItem.endDateTime = DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(30), "America/New_York"); // Set delivery specifications for the proposal line item. proposalLineItem.deliveryRateType = DeliveryRateType.EVENLY; // Set pricing for the proposal line item for 1000 impressions at a CPM of $2 // for a total value of $2. proposalLineItem.goal = new Goal() { unitType = UnitType.IMPRESSIONS, units = 1000L }; proposalLineItem.netCost = new Money() { currencyCode = "USD", microAmount = 2000000L }; proposalLineItem.netRate = new Money() { currencyCode = "USD", microAmount = 2000000L }; proposalLineItem.rateType = RateType.CPM; try { // Create the proposal line item on the server. ProposalLineItem[] proposalLineItems = proposalLineItemService.createProposalLineItems(new ProposalLineItem[] { proposalLineItem }); foreach (ProposalLineItem createdProposalLineItem in proposalLineItems) { Console.WriteLine( "A programmatic proposal line item with ID \"{0}\" " + "and name \"{1}\" was created.", createdProposalLineItem.id, createdProposalLineItem.name); } } catch (Exception e) { Console.WriteLine( "Failed to create programmatic proposal line items. " + "Exception says \"{0}\"", e.Message); } } }
/// <summary> /// Run the code example. /// </summary> public void Run(AdManagerUser user) { using (AudienceSegmentService audienceSegmentService = user.GetService <AudienceSegmentService>()) { // Get the NetworkService. NetworkService networkService = user.GetService <NetworkService>(); long customTargetingKeyId = long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE")); long customTargetingValueId = long.Parse(_T("INSERT_CUSTOM_TARGETING_VALUE_ID_HERE")); try { // Get the root ad unit ID used to target the whole site. String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId; // 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.adUnitId = rootAdUnitId; adUnitTargeting.includeDescendants = true; inventoryTargeting.targetedAdUnits = new AdUnitTargeting[] { adUnitTargeting }; // Create the custom criteria to be used in the segment rule. // CUSTOM_TARGETING_KEY_ID == CUSTOM_TARGETING_VALUE_ID CustomCriteria customCriteria = new CustomCriteria(); customCriteria.keyId = customTargetingKeyId; customCriteria.@operator = CustomCriteriaComparisonOperator.IS; customCriteria.valueIds = new long[] { customTargetingValueId }; // Create the custom criteria expression. CustomCriteriaSet topCustomCriteriaSet = new CustomCriteriaSet(); topCustomCriteriaSet.logicalOperator = CustomCriteriaSetLogicalOperator.AND; topCustomCriteriaSet.children = new CustomCriteriaNode[] { customCriteria }; // Create the audience segment rule. FirstPartyAudienceSegmentRule rule = new FirstPartyAudienceSegmentRule(); rule.inventoryRule = inventoryTargeting; rule.customCriteriaRule = topCustomCriteriaSet; // Create an audience segment. RuleBasedFirstPartyAudienceSegment audienceSegment = new RuleBasedFirstPartyAudienceSegment(); audienceSegment.name = "Sports enthusiasts audience segment #" + this.GetTimeStamp(); audienceSegment.description = "Sports enthusiasts between the ages of 20 and 30."; audienceSegment.pageViews = 6; audienceSegment.recencyDays = 6; audienceSegment.membershipExpirationDays = 88; audienceSegment.rule = rule; // Create the audience segment on the server. AudienceSegment[] audienceSegments = audienceSegmentService.createAudienceSegments( new FirstPartyAudienceSegment[] { audienceSegment }); foreach (AudienceSegment createdAudienceSegment in audienceSegments) { Console.WriteLine( "An audience segment with ID \"{0}\", name \"{1}\", and " + "type \"{2}\" was created.", createdAudienceSegment.id, createdAudienceSegment.name, createdAudienceSegment.type); } } catch (Exception e) { Console.WriteLine("Failed to get audience segment. Exception says \"{0}\"", e.Message); } } }
/// <summary> /// Run the code examples. /// </summary> public void Run(DfpUser user) { // Get the ProductTemplateService. ProductTemplateService productTemplateService = (ProductTemplateService)user.GetService(DfpService.v201708.ProductTemplateService); // Get the NetworkService. NetworkService networkService = (NetworkService)user.GetService(DfpService.v201708.NetworkService); // Create a product template. ProductTemplate productTemplate = new ProductTemplate(); productTemplate.name = "Programmatic product template #" + new Random().Next(int.MaxValue); productTemplate.description = "This product template creates programmatic proposal line " + "items targeting all ad units with product segmentation on geo targeting."; // Set the name macro which will be used to generate the names of the products. // This will create a segmentation based on the line item type, ad unit, and location. productTemplate.nameMacro = "<line-item-type> - <ad-unit> - <template-name> - <location>"; // Set the product type so the created proposal line items will be trafficked in DFP. productTemplate.productType = ProductType.DFP; // Set required Marketplace information. productTemplate.productTemplateMarketplaceInfo = new ProductTemplateMarketplaceInfo() { adExchangeEnvironment = AdExchangeEnvironment.DISPLAY, }; // Set rate type to create CPM priced proposal line items. productTemplate.rateType = RateType.CPM; // Create the creative placeholder. CreativePlaceholder creativePlaceholder = new CreativePlaceholder(); creativePlaceholder.size = new Size() { width = 300, height = 250, isAspectRatio = false }; // Set the size of creatives that can be associated with the product template. productTemplate.creativePlaceholders = new CreativePlaceholder[] { creativePlaceholder }; // Set the type of proposal line item to be created from the product template. productTemplate.lineItemType = LineItemType.STANDARD; // Get the root ad unit ID used to target the whole site. String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId; // Create ad unit targeting for the root ad unit (i.e. the whole network). AdUnitTargeting adUnitTargeting = new AdUnitTargeting(); adUnitTargeting.adUnitId = rootAdUnitId; adUnitTargeting.includeDescendants = true; // Create geo targeting for the US. Location countryLocation = new Location(); countryLocation.id = 2840L; // Create geo targeting for Hong Kong. Location regionLocation = new Location(); regionLocation.id = 2344L; GeoTargeting geoTargeting = new GeoTargeting(); geoTargeting.targetedLocations = new Location[] { countryLocation, regionLocation }; // Add inventory and geo targeting as product segmentation. ProductSegmentation productSegmentation = new ProductSegmentation(); productSegmentation.adUnitSegments = new AdUnitTargeting[] { adUnitTargeting }; productSegmentation.geoSegment = geoTargeting; productTemplate.productSegmentation = productSegmentation; try { // Create the product template on the server. ProductTemplate[] productTemplates = productTemplateService.createProductTemplates( new ProductTemplate[] { productTemplate }); foreach (ProductTemplate createdProductTemplate in productTemplates) { Console.WriteLine("A programmatic product template with ID \"{0}\" " + "and name \"{1}\" was created.", createdProductTemplate.id, createdProductTemplate.name); } } catch (Exception e) { Console.WriteLine("Failed to create product templates. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code examples. /// </summary> public void Run(DfpUser user) { // Get the ProductTemplateService. ProductTemplateService productTemplateService = (ProductTemplateService)user.GetService(DfpService.v201705.ProductTemplateService); // Get the NetworkService. NetworkService networkService = (NetworkService)user.GetService(DfpService.v201705.NetworkService); // Create a product template. ProductTemplate productTemplate = new ProductTemplate(); productTemplate.name = "Product template #" + new Random().Next(int.MaxValue); productTemplate.description = "This product template creates standard proposal line items " + "targeting Chrome browsers with product segmentation on ad units and geo targeting."; // Set the name macro which will be used to generate the names of the products. // This will create a segmentation based on the line item type, ad unit, and location. productTemplate.nameMacro = "<line-item-type> - <ad-unit> - <template-name> - <location>"; // Set the product type so the created proposal line items will be trafficked in DFP. productTemplate.productType = ProductType.DFP; // Set rate type to create CPM priced proposal line items. productTemplate.rateType = RateType.CPM; // Optionally set the creative rotation of the product to serve one or more creatives. productTemplate.roadblockingType = RoadblockingType.ONE_OR_MORE; productTemplate.deliveryRateType = DeliveryRateType.AS_FAST_AS_POSSIBLE; // Create the master creative placeholder. CreativePlaceholder creativeMasterPlaceholder = new CreativePlaceholder(); creativeMasterPlaceholder.size = new Size() { width = 728, height = 90, isAspectRatio = false }; // Create companion creative placeholders. CreativePlaceholder companionCreativePlaceholder = new CreativePlaceholder(); companionCreativePlaceholder.size = new Size() { width = 300, height = 250, isAspectRatio = false }; // Set the size of creatives that can be associated with the product template. productTemplate.creativePlaceholders = new CreativePlaceholder[] { creativeMasterPlaceholder, companionCreativePlaceholder }; // Set the type of proposal line item to be created from the product template. productTemplate.lineItemType = LineItemType.STANDARD; // Get the root ad unit ID used to target the whole site. String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId; // Create ad unit targeting for the root ad unit (i.e. the whole network). AdUnitTargeting adUnitTargeting = new AdUnitTargeting(); adUnitTargeting.adUnitId = rootAdUnitId; adUnitTargeting.includeDescendants = true; // Create geo targeting for the US. Location countryLocation = new Location(); countryLocation.id = 2840L; // Create geo targeting for Hong Kong. Location regionLocation = new Location(); regionLocation.id = 2344L; GeoTargeting geoTargeting = new GeoTargeting(); geoTargeting.targetedLocations = new Location[] { countryLocation, regionLocation }; // Add browser targeting to Chrome on the product template distinct from product // segmentation. Browser chromeBrowser = new Browser(); chromeBrowser.id = 500072L; BrowserTargeting browserTargeting = new BrowserTargeting(); browserTargeting.browsers = new Browser[] { chromeBrowser }; TechnologyTargeting technologyTargeting = new TechnologyTargeting(); technologyTargeting.browserTargeting = browserTargeting; Targeting productTemplateTargeting = new Targeting(); productTemplateTargeting.technologyTargeting = technologyTargeting; productTemplate.builtInTargeting = productTemplateTargeting; productTemplate.customizableAttributes = new CustomizableAttributes() { allowPlacementTargetingCustomization = true }; // Add inventory and geo targeting as product segmentation. ProductSegmentation productSegmentation = new ProductSegmentation(); productSegmentation.adUnitSegments = new AdUnitTargeting[] { adUnitTargeting }; productSegmentation.geoSegment = geoTargeting; productTemplate.productSegmentation = productSegmentation; try { // Create the product template on the server. ProductTemplate[] productTemplates = productTemplateService.createProductTemplates( new ProductTemplate[] { productTemplate }); foreach (ProductTemplate createdProductTemplate in productTemplates) { Console.WriteLine("A product template with ID \"{0}\" and name \"{1}\" was created.", createdProductTemplate.id, createdProductTemplate.name); } } catch (Exception e) { Console.WriteLine("Failed to create product templates. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the LineItemService. LineItemService lineItemService = (LineItemService) user.GetService(DfpService.v201508.LineItemService); // Set the order that all created line items will belong to and the // video ad unit ID to target. long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE")); string targetedVideoAdUnitId = _T("INSERT_TARGETED_VIDEO_AD_UNIT_ID_HERE"); // Set the custom targeting value ID representing the metadata // on the content to target. This would typically be from a key representing // a "genre" and a value representing something like "comedy". The value must // be from a key in a content metadata key hierarchy. long contentCustomTargetingValueId = long.Parse(_T("INSERT_CONTENT_CUSTOM_TARGETING_VALUE_ID_HERE")); // Create content targeting. ContentMetadataKeyHierarchyTargeting contentMetadataTargeting = new ContentMetadataKeyHierarchyTargeting(); contentMetadataTargeting.customTargetingValueIds = new long[] {contentCustomTargetingValueId}; ContentTargeting contentTargeting = new ContentTargeting(); contentTargeting.targetedContentMetadata = new ContentMetadataKeyHierarchyTargeting[] {contentMetadataTargeting}; // Create inventory targeting. InventoryTargeting inventoryTargeting = new InventoryTargeting(); AdUnitTargeting adUnitTargeting = new AdUnitTargeting(); adUnitTargeting.adUnitId = targetedVideoAdUnitId; adUnitTargeting.includeDescendants = true; inventoryTargeting.targetedAdUnits = new AdUnitTargeting[] {adUnitTargeting}; // Create video position targeting. VideoPosition videoPosition = new VideoPosition(); videoPosition.positionType = VideoPositionType.PREROLL; VideoPositionTarget videoPositionTarget = new VideoPositionTarget(); videoPositionTarget.videoPosition = videoPosition; VideoPositionTargeting videoPositionTargeting = new VideoPositionTargeting(); videoPositionTargeting.targetedPositions = new VideoPositionTarget[] {videoPositionTarget}; // Create targeting. Targeting targeting = new Targeting(); targeting.contentTargeting = contentTargeting; targeting.inventoryTargeting = inventoryTargeting; targeting.videoPositionTargeting = videoPositionTargeting; // Create local line item object. LineItem lineItem = new LineItem(); lineItem.name = "Video line item - " + this.GetTimeStamp(); lineItem.orderId = orderId; lineItem.targeting = targeting; lineItem.lineItemType = LineItemType.SPONSORSHIP; lineItem.allowOverbook = true; // Set the environment type to video. lineItem.environmentType = EnvironmentType.VIDEO_PLAYER; // Set the creative rotation type to optimized. lineItem.creativeRotationType = CreativeRotationType.OPTIMIZED; // Create the master creative placeholder. CreativePlaceholder creativeMasterPlaceholder = new CreativePlaceholder(); Size size1 = new Size(); size1.width = 400; size1.height = 300; size1.isAspectRatio = false; creativeMasterPlaceholder.size = size1; // Create companion creative placeholders. CreativePlaceholder companionCreativePlaceholder1 = new CreativePlaceholder(); Size size2 = new Size(); size2.width = 300; size2.height = 250; size2.isAspectRatio = false; companionCreativePlaceholder1.size = size2; CreativePlaceholder companionCreativePlaceholder2 = new CreativePlaceholder(); Size size3 = new Size(); size3.width = 728; size3.height = 90; size3.isAspectRatio = false; companionCreativePlaceholder2.size = size3; // Set companion creative placeholders. creativeMasterPlaceholder.companions = new CreativePlaceholder[] { companionCreativePlaceholder1, companionCreativePlaceholder2}; // Set the size of creatives that can be associated with this line item. lineItem.creativePlaceholders = new CreativePlaceholder[] {creativeMasterPlaceholder}; // Set delivery of video companions to optional. lineItem.companionDeliveryOption = CompanionDeliveryOption.OPTIONAL; // Set the line item to run for one month. lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY; lineItem.endDateTime = DateTimeUtilities.FromDateTime(System.DateTime.Now.AddMonths(1), "America/New_York"); // Set the cost per day to $1. lineItem.costType = CostType.CPD; Money money = new Money(); money.currencyCode = "USD"; money.microAmount = 1000000L; lineItem.costPerUnit = money; // Set the percentage to be 100%. Goal goal = new Goal(); goal.goalType = GoalType.DAILY; goal.unitType = UnitType.IMPRESSIONS; goal.units = 100; lineItem.primaryGoal = goal; try { // Create the line item on the server. LineItem[] createdLineItems = lineItemService.createLineItems(new LineItem[] {lineItem}); foreach (LineItem createdLineItem in createdLineItems) { Console.WriteLine("A line item with ID \"{0}\", belonging to order ID \"{1}\", and " + "named \"{2}\" was created.", createdLineItem.id, createdLineItem.orderId, createdLineItem.name); } } catch (Exception e) { Console.WriteLine("Failed to create line items. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code examples. /// </summary> /// <param name="user">The DFP user object running the code examples.</param> public override void Run(DfpUser user) { // Get the ProductTemplateService. ProductTemplateService productTemplateService = (ProductTemplateService) user.GetService(DfpService.v201508.ProductTemplateService); // Get the NetworkService. NetworkService networkService = (NetworkService) user.GetService(DfpService.v201508.NetworkService); // Create a product template. ProductTemplate productTemplate = new ProductTemplate(); productTemplate.name = "Product template #" + new Random().Next(int.MaxValue); productTemplate.description = "This product template creates standard proposal line items " + "targeting Chrome browsers with product segmentation on ad units and geo targeting."; // Set the name macro which will be used to generate the names of the products. // This will create a segmentation based on the line item type, ad unit, and location. productTemplate.nameMacro = "<line-item-type> - <ad-unit> - <template-name> - <location>"; // Set the product type so the created proposal line items will be trafficked in DFP. productTemplate.productType = ProductType.DFP; // Set rate type to create CPM priced proposal line items. productTemplate.rateType = RateType.CPM; // Optionally set the creative rotation of the product to serve one or more creatives. productTemplate.roadblockingType = RoadblockingType.ONE_OR_MORE; // Create the master creative placeholder. CreativePlaceholder creativeMasterPlaceholder = new CreativePlaceholder(); creativeMasterPlaceholder.size = new Size() {width = 728, height = 90, isAspectRatio = false}; // Create companion creative placeholders. CreativePlaceholder companionCreativePlaceholder = new CreativePlaceholder(); companionCreativePlaceholder.size = new Size() {width = 300, height = 250, isAspectRatio = false}; // Set the size of creatives that can be associated with the product template. productTemplate.creativePlaceholders = new CreativePlaceholder[] {creativeMasterPlaceholder, companionCreativePlaceholder}; // Set the type of proposal line item to be created from the product template. productTemplate.lineItemType = LineItemType.STANDARD; // Get the root ad unit ID used to target the whole site. String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId; // Create ad unit targeting for the root ad unit (i.e. the whole network). AdUnitTargeting adUnitTargeting = new AdUnitTargeting(); adUnitTargeting.adUnitId = rootAdUnitId; adUnitTargeting.includeDescendants = true; // Create geo targeting for the US. Location countryLocation = new Location(); countryLocation.id = 2840L; // Create geo targeting for Hong Kong. Location regionLocation = new Location(); regionLocation.id = 2344L; GeoTargeting geoTargeting = new GeoTargeting(); geoTargeting.targetedLocations = new Location[] {countryLocation, regionLocation}; // Add browser targeting to Chrome on the product template distinct from product // segmentation. Browser chromeBrowser = new Browser(); chromeBrowser.id = 500072L; BrowserTargeting browserTargeting = new BrowserTargeting(); browserTargeting.browsers = new Browser[] {chromeBrowser}; TechnologyTargeting technologyTargeting = new TechnologyTargeting(); technologyTargeting.browserTargeting = browserTargeting; Targeting productTemplateTargeting = new Targeting(); productTemplateTargeting.technologyTargeting = technologyTargeting; productTemplate.builtInTargeting = productTemplateTargeting; // Add inventory and geo targeting as product segmentation. ProductSegmentation productSegmentation = new ProductSegmentation(); productSegmentation.adUnitSegments = new AdUnitTargeting[] {adUnitTargeting}; productSegmentation.geoSegment = geoTargeting; productTemplate.productSegmentation = productSegmentation; try { // Create the product template on the server. ProductTemplate[] productTemplates = productTemplateService.createProductTemplates( new ProductTemplate[] {productTemplate}); foreach (ProductTemplate createdProductTemplate in productTemplates) { Console.WriteLine("A product template with ID \"{0}\" and name \"{1}\" was created.", createdProductTemplate.id, createdProductTemplate.name); } } catch (Exception e) { Console.WriteLine("Failed to create product templates. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code examples. /// </summary> /// <param name="user">The DFP user object running the code examples.</param> public override void Run(DfpUser user) { // [START get_proposal_line_item_service] MOE:strip_line // Get the ProposalLineItemService. ProposalLineItemService proposalLineItemService = (ProposalLineItemService) user.GetService(DfpService.v201508.ProposalLineItemService); // [END get_proposal_line_item_service] MOE:strip_line // Get the NetworkService. NetworkService networkService = (NetworkService) user.GetService(DfpService.v201508.NetworkService); long proposalId = long.Parse(_T("INSERT_PROPOSAL_ID_HERE")); long rateCardId = long.Parse(_T("INSERT_RATE_CARD_ID_HERE")); long productId = long.Parse(_T("INSERT_PRODUCT_ID_HERE")); // [START add_targeting] MOE:strip_line // Get the root ad unit ID used to target the whole site. String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId; // 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.adUnitId = rootAdUnitId; adUnitTargeting.includeDescendants = true; inventoryTargeting.targetedAdUnits = new AdUnitTargeting[] {adUnitTargeting}; // Create targeting. Targeting targeting = new Targeting(); targeting.inventoryTargeting = inventoryTargeting; // [END add_targeting] MOE:strip_line // [START create_proposal_line_item_local] MOE:strip_line // Create a proposal line item. ProposalLineItem proposalLineItem = new ProposalLineItem(); proposalLineItem.name = "Proposal line item #" + new Random().Next(int.MaxValue); // [END create_proposal_line_item_local] MOE:strip_line // [START set_required_creation_fields] MOE:strip_line proposalLineItem.proposalId = proposalId; proposalLineItem.rateCardId = rateCardId; proposalLineItem.productId = productId; proposalLineItem.targeting = targeting; // [END set_required_creation_fields] MOE:strip_line // [START set_dates] MOE:strip_line // Set the length of the proposal line item to run. proposalLineItem.startDateTime = DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(7), "America/New_York"); proposalLineItem.endDateTime = DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(30), "America/New_York"); // [END set_dates] MOE:strip_line // [START set_delivery_info] MOE:strip_line // Set delivery specifications for the proposal line item. proposalLineItem.deliveryRateType = DeliveryRateType.EVENLY; proposalLineItem.creativeRotationType = CreativeRotationType.OPTIMIZED; // [END set_delivery_info] MOE:strip_line // [START set_billing] MOE:strip_line // Set billing specifications for the proposal line item. proposalLineItem.billingCap = BillingCap.CAPPED_CUMULATIVE; proposalLineItem.billingSource = BillingSource.THIRD_PARTY_VOLUME; // [END set_billing] MOE:strip_line // [START set_goal] MOE:strip_line // Set pricing for the proposal line item for 1000 impressions at a CPM of $2 // for a total value of $2. proposalLineItem.goal = new Goal() {unitType = UnitType.IMPRESSIONS, units = 1000L}; // [END set_goal] MOE:strip_line // [START set_costs] MOE:strip_line proposalLineItem.cost = new Money() {currencyCode = "USD", microAmount = 2000000L}; proposalLineItem.costPerUnit = new Money() {currencyCode = "USD", microAmount = 2000000L}; proposalLineItem.rateType = RateType.CPM; // [END set_costs] MOE:strip_line try { // [START create_proposal_line_item_server] MOE:strip_line // Create the proposal line item on the server. ProposalLineItem[] proposalLineItems = proposalLineItemService.createProposalLineItems( new ProposalLineItem[] {proposalLineItem}); // [END create_proposal_line_item_server] MOE:strip_line foreach (ProposalLineItem createdProposalLineItem in proposalLineItems) { Console.WriteLine("A proposal line item with ID \"{0}\" and name \"{1}\" was created.", createdProposalLineItem.id, createdProposalLineItem.name); } } catch (Exception e) { Console.WriteLine("Failed to create proposal line items. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the AudienceSegmentService. AudienceSegmentService audienceSegmentService = (AudienceSegmentService) user.GetService( DfpService.v201508.AudienceSegmentService); // Get the NetworkService. NetworkService networkService = (NetworkService) user.GetService( DfpService.v201508.NetworkService); long customTargetingKeyId = long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE")); long customTargetingValueId = long.Parse(_T("INSERT_CUSTOM_TARGETING_VALUE_ID_HERE")); try { // Get the root ad unit ID used to target the whole site. String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId; // 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.adUnitId = rootAdUnitId; adUnitTargeting.includeDescendants = true; inventoryTargeting.targetedAdUnits = new AdUnitTargeting[] {adUnitTargeting}; // Create the custom criteria to be used in the segment rule. // CUSTOM_TARGETING_KEY_ID == CUSTOM_TARGETING_VALUE_ID CustomCriteria customCriteria = new CustomCriteria(); customCriteria.keyId = customTargetingKeyId; customCriteria.@operator = CustomCriteriaComparisonOperator.IS; customCriteria.valueIds = new long[] {customTargetingValueId}; // Create the custom criteria expression. CustomCriteriaSet topCustomCriteriaSet = new CustomCriteriaSet(); topCustomCriteriaSet.logicalOperator = CustomCriteriaSetLogicalOperator.AND; topCustomCriteriaSet.children = new CustomCriteriaNode[] {customCriteria}; // Create the audience segment rule. FirstPartyAudienceSegmentRule rule = new FirstPartyAudienceSegmentRule(); rule.inventoryRule = inventoryTargeting; rule.customCriteriaRule = topCustomCriteriaSet; // Create an audience segment. RuleBasedFirstPartyAudienceSegment audienceSegment = new RuleBasedFirstPartyAudienceSegment(); audienceSegment.name = "Sports enthusiasts audience segment #" + this.GetTimeStamp(); audienceSegment.description = "Sports enthusiasts between the ages of 20 and 30."; audienceSegment.pageViews = 6; audienceSegment.recencyDays = 6; audienceSegment.membershipExpirationDays = 88; audienceSegment.rule = rule; // Create the audience segment on the server. AudienceSegment[] audienceSegments = audienceSegmentService.createAudienceSegments( new FirstPartyAudienceSegment[] {audienceSegment}); foreach (AudienceSegment createdAudienceSegment in audienceSegments) { Console.WriteLine("An audience segment with ID \"{0}\", name \"{1}\", and type \"{2}\" " + "was created.", createdAudienceSegment.id, createdAudienceSegment.name, createdAudienceSegment.type); } } catch (Exception e) { Console.WriteLine("Failed to get audience segment. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the LineItemService. LineItemService lineItemService = (LineItemService)user.GetService(DfpService.v201311.LineItemService); // Set the order that all created line items will belong to and the // video ad unit ID to target. long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE")); string targetedVideoAdUnitId = _T("INSERT_TARGETED_VIDEO_AD_UNIT_ID_HERE"); // Set the custom targeting key ID and value ID representing the metadata // on the content to target. This would typically be a key representing // a "genre" and a value representing something like "comedy". long contentCustomTargetingKeyId = long.Parse(_T("INSERT_CONTENT_CUSTOM_TARGETING_KEY_ID_HERE")); long contentCustomTargetingValueId = long.Parse(_T("INSERT_CONTENT_CUSTOM_TARGETING_VALUE_ID_HERE")); // Create custom criteria for the content metadata targeting. CustomCriteria contentCustomCriteria = new CustomCriteria(); contentCustomCriteria.keyId = contentCustomTargetingKeyId; contentCustomCriteria.valueIds = new long[] { contentCustomTargetingValueId }; contentCustomCriteria.@operator = CustomCriteriaComparisonOperator.IS; // Create custom criteria set. CustomCriteriaSet customCriteriaSet = new CustomCriteriaSet(); customCriteriaSet.children = new CustomCriteriaNode[] { contentCustomCriteria }; // Create inventory targeting. InventoryTargeting inventoryTargeting = new InventoryTargeting(); AdUnitTargeting adUnitTargeting = new AdUnitTargeting(); adUnitTargeting.adUnitId = targetedVideoAdUnitId; adUnitTargeting.includeDescendants = true; inventoryTargeting.targetedAdUnits = new AdUnitTargeting[] { adUnitTargeting }; // Create video position targeting. VideoPosition videoPosition = new VideoPosition(); videoPosition.positionType = VideoPositionType.PREROLL; VideoPositionTarget videoPositionTarget = new VideoPositionTarget(); videoPositionTarget.videoPosition = videoPosition; VideoPositionTargeting videoPositionTargeting = new VideoPositionTargeting(); videoPositionTargeting.targetedPositions = new VideoPositionTarget[] { videoPositionTarget }; // Create targeting. Targeting targeting = new Targeting(); targeting.customTargeting = customCriteriaSet; targeting.inventoryTargeting = inventoryTargeting; targeting.videoPositionTargeting = videoPositionTargeting; // Create local line item object. LineItem lineItem = new LineItem(); lineItem.name = "Video line item - " + this.GetTimeStamp(); lineItem.orderId = orderId; lineItem.targeting = targeting; lineItem.lineItemType = LineItemType.SPONSORSHIP; lineItem.allowOverbook = true; // Set the environment type to video. lineItem.environmentType = EnvironmentType.VIDEO_PLAYER; // Set the creative rotation type to optimized. lineItem.creativeRotationType = CreativeRotationType.OPTIMIZED; // Create the master creative placeholder. CreativePlaceholder creativeMasterPlaceholder = new CreativePlaceholder(); Size size1 = new Size(); size1.width = 400; size1.height = 300; size1.isAspectRatio = false; creativeMasterPlaceholder.size = size1; // Create companion creative placeholders. CreativePlaceholder companionCreativePlaceholder1 = new CreativePlaceholder(); Size size2 = new Size(); size2.width = 300; size2.height = 250; size2.isAspectRatio = false; companionCreativePlaceholder1.size = size2; CreativePlaceholder companionCreativePlaceholder2 = new CreativePlaceholder(); Size size3 = new Size(); size3.width = 728; size3.height = 90; size3.isAspectRatio = false; companionCreativePlaceholder2.size = size3; // Set companion creative placeholders. creativeMasterPlaceholder.companions = new CreativePlaceholder[] { companionCreativePlaceholder1, companionCreativePlaceholder2 }; // Set the size of creatives that can be associated with this line item. lineItem.creativePlaceholders = new CreativePlaceholder[] { creativeMasterPlaceholder }; // Set delivery of video companions to optional. lineItem.companionDeliveryOption = CompanionDeliveryOption.OPTIONAL; // Set the length of the line item to run. lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY; lineItem.endDateTime = DateTimeUtilities.FromString("20120901 00:00:00"); // Set the cost per day to $1. lineItem.costType = CostType.CPD; Money money = new Money(); money.currencyCode = "USD"; money.microAmount = 1000000L; lineItem.costPerUnit = money; // Set the percentage to be 100%. lineItem.unitsBought = 100; try { // Create the line item on the server. lineItem = lineItemService.createLineItem(lineItem); if (lineItem != null) { Console.WriteLine("A line item with ID \"{0}\", belonging to order ID \"{1}\", and " + "named \"{2}\" was created.", lineItem.id, lineItem.orderId, lineItem.name); } else { Console.WriteLine("No line item created."); } } catch (Exception ex) { Console.WriteLine("Failed to create line items. Exception says \"{0}\"", ex.Message); } }