Skip to content

Instantly share code, notes, and snippets.

@rhoboat
Last active March 28, 2017 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhoboat/41ad8e4549c4ad0d1232831eee451276 to your computer and use it in GitHub Desktop.
Save rhoboat/41ad8e4549c4ad0d1232831eee451276 to your computer and use it in GitHub Desktop.

DFP Service

Node library we can use: https://github.com/spanishdict/node-google-dfp-wrapper

  • I read through the tests and the code, and it seems straightforward to use. It has implemented everything we need for creating orders, line items, creatives, and associations. It also has some steps for authentication. The tests and fixtures offer examples of how to use the code as well.

Create a Delivery

To create an order, line items, and creatives, we call the Create method on the Delivery module in the DFPService. Alternatively we can just have a CreateDelivery method exported on DFPService.

const delivery = require(‘node-dfp-service’).delivery
delivery.create(options)
  .then(handleSuccess)
  .catch(handleFailure)

or

const dfpService = require('node-dfp-service')
dfpService.createDelivery(options)
  .then(handleSuccess)
  .catch(handleFailure)

Internals

Creating a delivery will

  • use a generic advertiser
  • create a new order, yielding an order id
    • if error, retry up to 3 times
  • create a new line item on the order
    • containing all the required criteria
    • if error, retry up to 3 times
  • create new creatives for each specified creative, yielding creative ids
    • may need to create creative template (TODO)
    • if error, retry up to 3 times
  • associate the line with all creative ids
    • if error, retry up to 3 times

Example of steps

createOrder([..., advertiserID, ...])
  .then( Promise.all(createLineItem, createCreatives) )
  .then(associateLineItemCreatives)

Example function

function createOrder (args, retries = 3) {
  return new Promise((resolve, reject) => {
    if (retries) {
      dfpLib.createOrder(args)
        .then(resolve)
        .catch(() => {
          createOrder(args, retries--)
        })
    }
    else {
      reject(new Error("[dfp service] create order failed"))
    }
  })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment