Compiled using DFP API version: v201905

rdfp allows you to use the DoubleClick for Publishers API from R (recently renamed to Google Ad Manager). Manage inventory, create orders, pull reports, and more!

Installation

If you encounter a clear bug, please file a minimal reproducible example on GitHub.

Vignettes

The README below outlines the package functionality, but review the vignettes for more detailed examples on usage.

Usage

All functions start with dfp_ so that you can easily identify DFP-specific operations and use tab completion in RStudio. Most rdfp functions will return a tbl_df or list parsed from the XML returned in the SOAP response.

Load Package and Set API Version

Google releases 4 versions of the DFP API each year and deprecates versions older than one year, so there is a lot that’s regularly changing in this package. rdfp is periodically compiled against a recent version of the API. If you would like to use an older or newer API version that what is the package default, then just specify it as an option.

Authenticate

To authenticate you will first need to specify the network_code of the DFP instance you would like to connect to. This is the only required option that the user must specify when using the rdfp package. After setting the network_code all you need to do is run dfp_auth(). If you already have a cached .httr-oauth-rdfp file in the current working directory, then the token will be loaded and refreshed if necessary. Otherwise, your browswer will pop open and you will interactively authenticate.

The package has other options like a client_id and client_secret where you can connect using your own Google Client instead of the package default. Using your own client requires you to first set one up in the Google Developers Console.

Run a Report

Below is an example of how to make a simple report request.

# In order to run a report you must specify how the report should be structured 
# by specifying a reportQuery inside a reportJob. All of the dimensions, columns, 
# date range options, etc. are documented at:
# https://developers.google.com/ad-manager/api/reference/v201905/ReportService.ReportQuery
request_data <- list(reportJob=list(reportQuery=list(dimensions='MONTH_AND_YEAR', 
                                                     dimensions='AD_UNIT_ID',
                                                     adUnitView='FLAT',
                                                     columns = 'AD_SERVER_IMPRESSIONS', 
                                                     columns = 'AD_SERVER_CLICKS',
                                                     dateRangeType='LAST_WEEK'
                                                     )))

# a convenience function has been provided to you to manage the report process workflow
# if you would like more control, see the example below which moves through each step in the process
report_data <- dfp_full_report_wrapper(request_data)
report_data[,c('Dimension.MONTH_AND_YEAR', 'Dimension.AD_UNIT_ID', 'Column.AD_SERVER_CLICKS')]
#> # A tibble: 18 x 3
#>    Dimension.MONTH_AND_YEAR Dimension.AD_UNIT_ID Column.AD_SERVER_CLICKS
#>    <chr>                                   <dbl>                   <dbl>
#>  1 2019-05                           21677451947                     936
#>  2 2019-05                           21677451950                     173
#>  3 2019-05                           21677553898                    5447
#>  4 2019-05                           21677553901                     102
#>  5 2019-05                           21677553904                    4304
#>  6 2019-05                           21677451953                    2264
#>  7 2019-05                           21677553910                      44
#>  8 2019-05                           21677553913                    2637
#>  9 2019-05                           21677554012                      69
#> 10 2019-06                           21677451947                     431
#> 11 2019-06                           21677451950                      66
#> 12 2019-06                           21677553898                    1740
#> 13 2019-06                           21677553901                      43
#> 14 2019-06                           21677553904                    1895
#> 15 2019-06                           21677451953                     865
#> 16 2019-06                           21677553910                      20
#> 17 2019-06                           21677553913                    1146
#> 18 2019-06                           21677554012                      34

Credits

This application uses other open source software components. The authentication components are mostly verbatim copies of the routines established in the googlesheets package (https://github.com/jennybc/googlesheets). We acknowledge and are grateful to these developers for their contributions to open source.

More Information

Google provides support for client libraries here, but unfortunately, R is not a supported language. Google’s client libraries directly reference the production WSDLs to interact with the API, but this package makes SOAP requests best formatted to match the WSDL standards. This articulation is not perfect and continued progress will be made to bring functionality up to par with the client libraries.

Most all operations supported by the DFP API are available via this package. It is strongly recommended that you use the DFP API Reference when using this package. Details on formatting, attributes, and methods are all better explained by Google’s documentation.

Top