Reminder: v201611 will be sunset on November 30, 2017.

DFP Sales Manager Product Templates and Products

This guide explains ‘what a product is,’ and walks you through the creation of a Product object via the ProductTemplate object in the API.

Primer

Products in DFP Sales Manager are created by sales teams to represent segments of inventory they want to sell. From an entity perspective, they are proposals of line items, i.e. templates for creating ProposalLineItem objects. They are automatically generated in the background after creating product templates. These define the default values for proposal line item fields such as name, product type, and rate type, as well as the targeting presets - specifying which targeting will be set by default and which targeting fields are customizable. Creating proposal line items relies on the combination of RateCard and Product objects (once activated).

Creating Products

To create products, start by creating your ProductTemplate object locally, defining it with a name and optionally a description to differentiate it from other product templates in your catalog:

Java

  // Create a product template.
  ProductTemplate productTemplate = new ProductTemplate();
  productTemplate.setName("Product template #" + new Random().nextInt(Integer.MAX_VALUE));
  productTemplate.setDescription("This product template creates standard proposal line items "
      + "targeting Chrome browsers with product segmentation on ad units and geo targeting.");
    

Python

  # Initialize appropriate service.
  product_template_service = client.GetService(
      'ProductTemplateService', version='v201708')

  # Create a product template.
  product_template = {
      'name': ('Product template #%d' % uuid.uuid4()),
      'description': ('This product template creates standard proposal line '
                      'items targeting Chrome browsers with product '
                      'segmentation on ad units and geo targeting.'),
      ...
    

PHP

    $productTemplateService =
        $dfpServices->get($session, ProductTemplateService::class);

    $productTemplate = new ProductTemplate();
    $productTemplate->setName('Product template #' . uniqid());
    $productTemplate->setDescription('This product template creates standard '
        . 'proposal line items targeting Chrome browsers with product '
        . 'segmentation on ad units and geo targeting.');
    

C#

  // Get the ProductTemplateService.
  ProductTemplateService productTemplateService =
      (ProductTemplateService) user.GetService(DfpService.v201708.ProductTemplateService);

  // 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.";
    

From there, you can set the name macro. This field generates the names of the products created and will use the product segmentation specified to create multiple products from a single product template.

Java

  // 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.setNameMacro("<line-item-type> - <ad-unit> - <template-name> - <location>");
    

Python

      ...
      'nameMacro': ('<line-item-type> - <ad-unit> - '
                    '<template-name> - <location>'),
      ...
    

PHP

    // 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->setNameMacro(
        '<line-item-type> - <ad-unit> - <template-name> - <location>');
    

C#

  // 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>";
    

The following fields are relevant to the trafficking specifications on proposal line items such as line item type, product type, rate, as well as the creative and creative delivery settings:

Java

  // Set the product type so the created proposal line items will be trafficked in DFP.
  productTemplate.setProductType(ProductType.DFP);
  
  // Set rate type to create CPM priced proposal line items.
  productTemplate.setRateType(RateType.CPM);
  productTemplate.setDeliveryRateType(DeliveryRateType.AS_FAST_AS_POSSIBLE);
  
  // Optionally set the creative rotation of the product to serve one or more creatives.
  productTemplate.setRoadblockingType(RoadblockingType.ONE_OR_MORE);
  
  // Create the master creative placeholder.
  CreativePlaceholder creativeMasterPlaceholder = new CreativePlaceholder();
  creativeMasterPlaceholder.setSize(new Size(728, 90, false));

  // Create companion creative placeholders.
  CreativePlaceholder companionCreativePlaceholder = new CreativePlaceholder();
  companionCreativePlaceholder.setSize(new Size(300, 250, false));

  // Set the size of creatives that can be associated with the product template.
  productTemplate.setCreativePlaceholders(
      new CreativePlaceholder[] {creativeMasterPlaceholder, companionCreativePlaceholder});
  
  // Set the type of proposal line item to be created from the product template.
  productTemplate.setLineItemType(LineItemType.STANDARD);
    

Python

      ...
      'productType': 'DFP',
      'rateType': 'CPM',
      'roadblockingType': 'ONE_OR_MORE',
      'deliveryRateType': 'AS_FAST_AS_POSSIBLE',
      'creativePlaceholders': [
          {
              'size': {
                  'width': '728',
                  'height': '90'
              }
          },
          {
              'size': {
                  'width': '300',
                  'height': '250'
              }
          }
      ],
      'lineItemType': 'STANDARD',
      ...
    

PHP

    // Set the product type so the created proposal line items will be
    // trafficked in DFP.
    $productTemplate->setProductType(ProductType::DFP);

    // Set rate type to create CPM priced proposal line items.
    $productTemplate->setRateType(RateType::CPM);
    $productTemplate->setDeliveryRateType(
        DeliveryRateType::AS_FAST_AS_POSSIBLE);

    // Optionally set the creative rotation of the product to serve one or more
    // creatives.
    $productTemplate->setRoadblockingType(RoadblockingType::ONE_OR_MORE);

    // Set the size of creatives that can be associated with the product
    // template.
    $creativePlaceholder1 = new CreativePlaceholder();
    $size = new Size();
    $size->setWidth(728);
    $size->setHeight(90);
    $size->setIsAspectRatio(false);
    $creativePlaceholder1->setSize($size);
    $creativePlaceholder2 = new CreativePlaceholder();
    $size = new Size();
    $size->setWidth(300);
    $size->setHeight(250);
    $size->setIsAspectRatio(false);
    $creativePlaceholder2->setSize($size);
    $productTemplate->setCreativePlaceholders(
        [$creativePlaceholder1, $creativePlaceholder2]);

    // Set the type of proposal line item to be created from the product
    // template.
    $productTemplate->setLineItemType(LineItemType::STANDARD);
    

C#

  // 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;
    

You can then define targeting defaults for your products which will be inherited by the proposal line items created from your product. Similarly to proposal line items, you can directly add targeting onto the product template. This is done through the ProductTemplateTargeting object.

Java

  // Get the root ad unit ID used to target the whole site.
  String rootAdUnitId = networkService.getCurrentNetwork().getEffectiveRootAdUnitId();

  // Create ad unit targeting for the root ad unit (i.e. the whole network).
  AdUnitTargeting adUnitTargeting = new AdUnitTargeting();
  adUnitTargeting.setAdUnitId(rootAdUnitId);
  adUnitTargeting.setIncludeDescendants(true);
  
  // Create geo targeting for the US.
  Location countryLocation = new Location();
  countryLocation.setId(2840L);
  
  // Create geo targeting for Hong Kong.
  Location regionLocation = new Location();
  regionLocation.setId(2344L);

  GeoTargeting geoTargeting = new GeoTargeting();
  geoTargeting.setTargetedLocations(new Location[] {countryLocation, regionLocation});

  // Add browser targeting to Chrome on the product template distinct from product segmentation.
  Browser chromeBrowser = new Browser();
  chromeBrowser.setId(500072L);
  
  BrowserTargeting browserTargeting = new BrowserTargeting();
  browserTargeting.setBrowsers(new Browser[] {chromeBrowser});
  
  TechnologyTargeting technologyTargeting = new TechnologyTargeting();
  technologyTargeting.setBrowserTargeting(browserTargeting);
  
  Targeting productTemplateTargeting = new Targeting();
  productTemplateTargeting.setTechnologyTargeting(technologyTargeting);
  
  productTemplate.setBuiltInTargeting(productTemplateTargeting);
    

Python

      ...
      'customizableAttributes': {
          'allowPlacementTargetingCustomization': True,
      },
      'builtInTargeting': {
          'technologyTargeting': {
              # Set browser targeting to Chrome.
              'browserTargeting': {
                  {
                      'browsers': [
                          {
                              'id': '500072'
                          }
                      ]
                  }
              }
          }
      },
      ...
    

PHP

    // Add browser targeting to Chrome on the product template distinct from
    // product segmentation.
    $targeting = new Targeting();
    $technologyTargeting = new TechnologyTargeting();
    $browserTargeting = new BrowserTargeting();
    $browser = new Browser();
    $browser->setId(500072);
    $browserTargeting->setBrowsers([$browser]);
    $technologyTargeting->setBrowserTargeting($browserTargeting);
    $targeting->setTechnologyTargeting($technologyTargeting);
    $productTemplate->setBuiltInTargeting($targeting);

    // Allow placement targeting to be customized on the proposal line item.
    $customizableAttributes = new CustomizableAttributes();
    $customizableAttributes->setAllowPlacementTargetingCustomization(true);
    $productTemplate->setCustomizableAttributes($customizableAttributes);

    // Add inventory and geo targeting as product segmentation.
    $productSegmentation = new ProductSegmentation();
    // Create ad unit targeting for the root ad unit (i.e. the whole network).
    $adUnitTargeting = new AdUnitTargeting();
    $adUnitTargeting->setAdUnitId(
        $networkService->getCurrentNetwork()->getEffectiveRootAdUnitId());
    $adUnitTargeting->setIncludeDescendants(true);
    $productSegmentation->setAdUnitSegments([$adUnitTargeting]);
    // Create geo targeting for the US and Hong Kong.
    $geoTargeting = new GeoTargeting();
    $location1 = new Location();
    $location1->setId(2840); // US
    $location2 = new Location();
    $location2->setId(2344); // Hong Kong
    $geoTargeting->setTargetedLocations([$location1, $location2]);
    

C#

  // 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
  };
    

Product segmentation allows you to create multiple products with a shared set of proposal line item settings by making combinations of multiple targeting options. In the above section, you added multiple locations for the GeoTargeting object. By adding this as a segmentation on the product template, it creates two products, one targeting the US and one targeting Hong Kong.

Java

  // Add inventory and geo targeting as product segmentation.
  ProductSegmentation productSegmentation = new ProductSegmentation();
  productSegmentation.setAdUnitSegments(new AdUnitTargeting[] {adUnitTargeting});
  productSegmentation.setGeoSegment(geoTargeting);
  
  productTemplate.setProductSegmentation(productSegmentation);
    

Python

      ...
      'productSegmentation': {
          'geoSegment': {
              'targetedLocations': [
                  {'id': '2840',
                   'displayName': 'US'},
                  {'id': '2344',
                   'displayName': 'Hong Kong'}
              ]
          },
          'adUnitSegments': [{
              'adUnitId': (network_service.getCurrentNetwork()[
                  'effectiveRootAdUnitId']),
              'includeDescendants': 'true'
          }]
      }
      ...
    

PHP

    $productSegmentation->setGeoSegment($geoTargeting);
    $productTemplate->setProductSegmentation($productSegmentation);
    

C#

  // Add inventory and geo targeting as product segmentation.
  ProductSegmentation productSegmentation = new ProductSegmentation();
  productSegmentation.adUnitSegments = new AdUnitTargeting[] {adUnitTargeting};
  productSegmentation.geoSegment = geoTargeting;

  productTemplate.productSegmentation = productSegmentation;
    

Once these fields have been set, creating new ProductTemplate objects is done by invoking createProductTemplates on an array of product templates:

Java

  // Create the product template on the server.
  ProductTemplate[] productTemplates =
      productTemplateService.createProductTemplates(new ProductTemplate[] {productTemplate});
    

Python

  # Create product templates on the server.
  product_templates = product_template_service.createProductTemplates(
      [product_template])
    

PHP

    // Create the product template on the server.
    $results =
        $productTemplateService->createProductTemplates([$productTemplate]);
    

C#

  // Create the product template on the server.
  ProductTemplate[] productTemplates = productTemplateService.createProductTemplates(
      new ProductTemplate[] {productTemplate});
    

The product template will be created with an INACTIVE status as will the corresponding products.

Activating Product Templates

You need to activate your product template before you can use the products created from it. To do so, use the ActivateProductTemplates action:

Java

    // Create a statement to select a product template.
    StatementBuilder statementBuilder = new StatementBuilder()
        .where("WHERE id = :id")
        .orderBy("id ASC")
        .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
        .withBindVariableValue("id", productTemplateId);

      // Create action.
      com.google.api.ads.dfp.axis.v201708.ActivateProductTemplates action =
          new com.google.api.ads.dfp.axis.v201708.ActivateProductTemplates();

      // Perform action.
      UpdateResult result =
          productTemplateService.performProductTemplateAction(
              action, statementBuilder.toStatement());
    

Python

  # Create query.
  statement = (dfp.StatementBuilder()
               .Where('id = :id')
               .WithBindVariable('id', long(product_template_id))
               .Limit(1))

      # Perform action.
      result = product_template_service.performProductTemplateAction(
          {'xsi_type': 'ActivateProductTemplates'}, statement.ToStatement())
    

PHP

    // Create a statement to select the product templates to activate.
    $pageSize = StatementBuilder::SUGGESTED_PAGE_LIMIT;
    $statementBuilder = (new StatementBuilder())
        ->where('id = :id')
        ->orderBy('id ASC')
        ->limit($pageSize)
        ->withBindVariableValue('id', $productTemplateId);

      // Create and perform action.
      $action = new ActivateProductTemplatesAction();
      $result = $productTemplateService->performProductTemplateAction($action,
          $statementBuilder->toStatement());
    

C#

  // Create statement to select a product template by ID.
  StatementBuilder statementBuilder = new StatementBuilder()
      .Where("id = :id")
      .OrderBy("id ASC")
      .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
      .AddValue("id", productTemplateId);

  // Create action.
  Google.Api.Ads.Dfp.v201708.ActivateProductTemplates action =
      new Google.Api.Ads.Dfp.v201708.ActivateProductTemplates();

  // Perform action.
  UpdateResult result = productTemplateService.performProductTemplateAction(action,
      statementBuilder.ToStatement());
    

This activates the product template as well as the products. They are now ready to be used to create proposal line items.

Fetching Products

After creating a new ProductTemplate object, you can get the created products back by querying against the ID returned by the product template.

Java

  // Create a statement to select products.
  StatementBuilder statementBuilder = new StatementBuilder()
      .where("productTemplateId = :productTemplateId")
      .orderBy("id ASC")
      .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
      .withBindVariableValue("productTemplateId", productTemplateId);

    ProductPage page =
        productService.getProductsByStatement(statementBuilder.toStatement());
    

Python

  # Create a statement to select products.
  statement = (dfp.StatementBuilder()
               .Where('productTemplateId = :productTemplateId')
               .WithBindVariable('productTemplateId', product_template_id))

    response = product_service.getProductsByStatement(statement.ToStatement())
    

PHP

    // Create a statement to select products.
    $pageSize = StatementBuilder::SUGGESTED_PAGE_LIMIT;
    $statementBuilder = (new StatementBuilder())
        ->where('productTemplateId = :productTemplateId')
        ->orderBy('id ASC')
        ->limit($pageSize)
        ->withBindVariableValue('productTemplateId', $productTemplateId);

      $page = $productService->getProductsByStatement(
          $statementBuilder->toStatement());
    

C#

  // Create a statement to select products.
  int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
  StatementBuilder statementBuilder = new StatementBuilder()
      .Where("productTemplateId = :productTemplateId")
      .OrderBy("id ASC")
      .Limit(pageSize)
      .AddValue("productTemplateId", productTemplateId);

ProductPage page = productService.getProductsByStatement(
    statementBuilder.ToStatement());
    

Syncing Products Locally

If you are attempting to build a local catalog of all products, you could do so by selecting all products on the first time query with a statement similar to:

Java

  StatementBuilder statementBuilder = new StatementBuilder()
      .orderBy("id ASC")
      .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    

Python

  statement = dfp.FilterStatement('ORDER BY id ASC')
    

PHP

  $statementBuilder->OrderBy('id ASC')
      ->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    

C#

  StatementBuilder statementBuilder = new StatementBuilder()
      .OrderBy("id ASC")
      .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    

and on subsequent fetches, filtering using the lastModifiedDateTime property on the Product object. By passing in the date since the last sync to the lastModifiedDateTime variable, you will only pull products that have changed, greatly increasing the speed of your fetches.

Java

  StatementBuilder statementBuilder = new StatementBuilder()
      .where("lastModifiedDateTime > :lastModifiedDateTime")
      .orderBy("id ASC")
      .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
      .withBindVariable("lastModifiedDateTime", lastSyncDateTime);
    

Python

  values = [{
      'key': 'dateTimeString',
      'value': {
          'xsi_type': 'TextValue',
          'value': lastSyncDateTime.strftime('%Y-%m-%dT%H:%M:%S')
      }
  }, {
      'key': 'orderId',
      'value': {
          'xsi_type': 'NumberValue',
          'value': order_id
      }
  }]
  query = 'WHERE lastModifiedDateTime >= :dateTimeString AND orderId = :orderId'
  statement = dfp.FilterStatement(query, values)
    

PHP

  $statementBuilder->Where('lastModifiedDateTime >= :lastModifiedDateTime')
      ->OrderBy('id ASC')
      ->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT)
      ->WithBindVariableValue(
          'lastModifiedDateTime',
          DateTimeUtils::ToDfpDateTime(lastSyncDateTime)
      );
    

C#

   StatementBuilder statementBuilder = new StatementBuilder()
       .Where("lastModifiedDateTime > :lastModifiedDateTime")
       .OrderBy("id ASC")
       .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
       .AddValue("lastModifiedDateTime", lastSyncDateTime);
    

By adding all the products in your network to a local version of your "catalog," you can reuse them without making additional calls to the API.

Next Steps

Enviar comentarios sobre…

DoubleClick for Publishers
DoubleClick for Publishers
¿Necesitas ayuda? Visita nuestra página de asistencia.