Ad Trafficking Setup with rdfp

Steven M. Mortimer

2018-03-29

First, we load rdfp and specify the DFP network we would like to connect to. Then we authenticate by using dfp_auth(). Any existing cached token would be used or we will be prompted to authenticate via the browser.

library(rdfp)
options(rdfp.network_code = 123456789)
dfp_auth()

Setup Custom Labels for Items

Custom labels are helpful for “tagging” DFP items with metadata that can later be used frequency capping, doing competitive exclusion or other specific actions. See the following link for Google’s explanation on their uses: (https://support.google.com/admanager/answer/190565?hl=en&ref_topic=30224)

# this creates a label called "Auto - Competitive Exclusion" that we can add
# to any line item or order that we might want to use to prevent from clashing 
# where two different car advertisers ads should not be shown at once.
request_data <- data.frame(name="Auto - Competitive Exclusion",
                           description=paste0("A label to prevent two different car ",
                                              "companies from showing ads together"),
                           types='COMPETITIVE_EXCLUSION')
request_data <- list('labels'=hypothetical_label)
result <- dfp_createLabels(request_data)

Setup Custom Fields for Items

Custom fields are helpful for “tagging” DFP items with metadata that can later be used filtering or reporting. See the following link for Google’s explanation on their uses: (https://support.google.com/admanager/answer/2694303?hl=en)

# this creates an extra field on the CREATIVE entity type that denotes the time of 
# day that the creative typically runs. First we create the field, then populate
# with potential options since it is a dropdown field.
request_data <- data.frame(name='Timing',
                           description='The time of day that this creative usually runs.', 
                           entityType='CREATIVE',
                           dataType='DROP_DOWN',
                           visibility='FULL')
dfp_createCustomFields_result <- dfp_createCustomFields(request_data)

request_data <- data.frame(customFieldId=rep(dfp_createCustomFields_result$id, 3),
                           displayName=c('Morning', 'Afternoon', 'Evening'))
dfp_createCustomFieldOptions_result <- dfp_createCustomFieldOptions(request_data)

Setup Custom Targeting Keys and Values

DFP allows traffickers to create custom tags to better target line items on their site. For example, a certain section of the site or search term used by a visitor can be encoded as custom targeting keys and values that can later be used when creating orders and line items, and evaluating potential inventory. See the following link for Google’s explanation on their uses: (https://support.google.com/admanager/answer/188092?hl=en)

# create the key
unique_numb <- as.integer(runif(1,1,100000))
request_data <- list(keys=list(name=paste0('Test', unique_numb), 
                               displayName=paste0('TestKey', unique_numb), 
                               type='FREEFORM'))
dfp_createCustomTargetingKeys_result <- dfp_createCustomTargetingKeys(request_data)
dfp_createCustomTargetingKeys_result
#> # A tibble: 1 x 6
#>         id name      displayName  type     status reportableType
#>      <dbl> <chr>     <chr>        <chr>    <chr>  <chr>         
#> 1 11895547 Test80740 TestKey80740 FREEFORM ACTIVE OFF

# create the values
request_data <- data.frame(customTargetingKeyId=rep(dfp_createCustomTargetingKeys_result$id,2),
                           name=c('TestValue1','TestValue2'), 
                           displayName=c('TestValue1','TestValue2'), 
                           matchType=rep('EXACT', 2))
dfp_createCustomTargetingValues_result <- dfp_createCustomTargetingValues(request_data)
dfp_createCustomTargetingValues_result
#> # A tibble: 2 x 6
#>   customTargetingKeyId           id name       displayName matchType status
#>                  <dbl>        <dbl> <chr>      <chr>       <chr>     <chr> 
#> 1             11895547 448122443557 TestValue1 TestValue1  EXACT     ACTIVE
#> 2             11895547 448122632838 TestValue2 TestValue2  EXACT     ACTIVE