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.
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)
-
takes in
options
:- everything required to create order
- we will build this format: https://github.com/spanishdict/node-google-dfp-wrapper/blob/master/fixtures/input/order.json
- advertiser id - static generic advertiser
- trafficker id
- partner id?
- everything required to create line item
- we will build this format: https://github.com/spanishdict/node-google-dfp-wrapper/blob/master/fixtures/input/line-item.json
- cpm
- campaign start and end
- geoTargeting
- inventoryTargeting
- customTargeting
- custom criteria key value pairs
- everything required to create creatives
- we will build this format: https://github.com/spanishdict/node-google-dfp-wrapper/blob/master/fixtures/input/creative.json
- sizes
- assets or snippets
- everything required to create order
-
returns a Promise
- if there's any error, it will be rejected
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"))
}
})
}