stevenmmortimer / rdfp Goto Github PK
View Code? Open in Web Editor NEWThis R package connects the DoubleClick for Publishers API from R
Home Page: https://stevenmmortimer.github.io/rdfp/
License: Other
This R package connects the DoubleClick for Publishers API from R
Home Page: https://stevenmmortimer.github.io/rdfp/
License: Other
I'm trying to use a more recent version of the Google Ad Manager API access some recently addded metrics/features but options(rdfp.version = "v202202")
is the only version of the API that works. Using "v202205" or greater results in this unmarshalling error
Error: Unmarshalling Error: cvc-complex-type.2.4.a: Invalid content was found starting with element '{"https://www.google.com/apis/ads/publisher/v202205":timeZoneType}'. One of '{"https://www.google.com/apis/ads/publisher/v202205":statement, "https://www.google.com/apis/ads/publisher/v202205":reportCurrency}' is expected.
library(rdfp)
dfp_auth()
options(rdfp.network_code = "xxxx")
#options(rdfp.version = "v202202")
options(rdfp.version = "v202205")
#options(rdfp.version = "v202208")
#options(rdfp.version = "v202211")
query <- list(reportJob = list(reportQuery =
list(dimensions = "DATE",
adUnitView = "FLAT",
columns = "AD_SERVER_IMPRESSIONS",
startDate = list(year = 2023, month = 01, day = 01),
endDate = list(year = 2023, month = 01, day = 02),
dateRangeType = "CUSTOM_DATE", #must be done after start/end date
timeZoneType = "PUBLISHER")))
dfp_full_report_wrapper(query, max_tries = 1000) # This results in error unless options(rdfp.version = "v202202") is used
Not sure what else to do. I've always been able to keep up with APi version updates until this one. Let me know if you need any further details. Appreciate the help
-Emeka
When v201808 is released, recompile the functions and reset the default version to v201808
Please see my code below to forecast avilability:
sample_line <- list()
sample_line$startDateTimeType <- 'IMMEDIATELY'
sample_line$endDateTime <- date2DFPDateTimeObj(Sys.Date() + 10, daytime='end')
sample_line$lineItemType <- 'SPONSORSHIP'
sample_line$costType<-'CPM'
sample_line$creativePlaceholders$size <- list(width=300, height=600, isAspectRatio='false')
sample_line$creativePlaceholders$expectedCreativeCount <- 3
sample_line$creativePlaceholders$creativeSizeType <- 'PIXEL'
sample_line$primaryGoal <- list(goalType='DAILY', unitType='IMPRESSIONS', units=100)
sample_line$creativeRotationType <- 'OPTIMIZED'
sample_line$roadblockingType<- 'AS_MANY_AS_POSSIBLE'
device_targets<-as.list(c(30000,30001,30002,30003))
device_targets <- lapply(device_targets, FUN=function(x){list(id=x)})
names(device_targets) <- rep('targetedDeviceCategories', length(device_targets))
sample_line$targeting <- list(inventoryTargeting=list(targetedAdUnits=list(adUnitId=20378992807,
includeDescendants="true")),
technologyTargeting=list(deviceCategoryTargeting=device_targets))
forecast_request <- list(lineItem=list(lineItem=sample_line),
forecastOptions=list(includeTargetingCriteriaBreakdown='true',
includeContendingLineItems='false'))
this_result <- dfp_getAvailabilityForecast(forecast_request, as_df=FALSE)
The function dfp_getAvailabilityForecast returns an error when using the following attributes in the lineitem type: creativeRotationType, roadblockingType
V201702 contains those attributes for the LineItem type (https://developers.google.com/doubleclick-publishers/docs/reference/v201702/ForecastService.LineItem). Could you please help me with this?
Hi Steven!
Great peace of work with rdfp! :) I'm tried to figure out something weird tht is hapening. I do have the following code:
request_data <- list(reportJob=list(reportQuery=list(#dimensions='DATE',
#dimensions='AD_EXCHANGE_DFP_AD_UNIT',
#dimensions = 'AD_EXCHANGE_DEVICE_CATEGORY',
dimensions = 'AD_EXCHANGE_INVENTORY_SIZE',
#dimensions = 'AD_EXCHANGE_COUNTRY_NAME',
columns='AD_EXCHANGE_AD_REQUESTS',
columns='AD_EXCHANGE_MATCHED_REQUESTS',
columns = 'AD_EXCHANGE_IMPRESSIONS',
columns='AD_EXCHANGE_ESTIMATED_REVENUE',
columns='AD_EXCHANGE_ACTIVE_VIEW_MEASURED_IMPRESSIONS',
columns='AD_EXCHANGE_ACTIVE_VIEW_VIEWED_IMPRESSIONS',
dateRangeType='YESTERDAY',
adxReportCurrency = 'MXN'
)))
# the result is a list and most importantly the ID is included for checking its status
dfp_runReportJob_result <- dfp_runReportJob(request_data)
dfp_runReportJob_result$id
All is good but when getting the dataframe, the revenue metric doesn't make any sense. I compare the data within Google Ad Manager UI and it seems that what is missing is a dot (".").
Do you have any idea what this may be happening?
Thanks!
Hi, Steven!
At first, thank you very much for creating this great package! I have one question for which I could not find any answer myself. I am trying to delete some values from key value and I don't know how. Is there any easy way to modify dfp_createCustomTargetingValues
function and force it to delete values?
Thanks
Marta
First, thanks a lot for this package.
I'm getting the following error when running your reporting example (the expanded one):
> report_dat <- dfp_report_url_to_dataframe(report_url=dfp_getReportDownloadURL_result,
+ exportFormat='CSV_DUMP')
Error in curl_download(url = report_url, destfile = temp_destination) :
Argument 'url' must be string.
It seems that by that stage the dfp_getReportDownloadURL_result is a dataframe and not a string.
I'm noob in R, so maybe I'm doing something wrong.
Thanks!
Hi,
This is my query-
request_data <- list(reportJob =
list(reportQuery =
list(dimensions = 'MONTH_AND_YEAR',
dimensions = 'floorTest (floortest)', #customDimension created in DFP
dimensions = 'AD_UNIT_NAME',
dimensions = 'ADVERTISER_NAME',
dimensions = "PLACEMENT_NAME",
dimensions = "COUNTRY_NAME",
dimensions = "DEVICE_CATEGORY_NAME",
dimensions = 'LINE_ITEM_NAME',
adUnitView = 'FLAT',
columns = 'TOTAL_LINE_ITEM_LEVEL_CPM_AND_CPC_REVENUE',
columns = "TOTAL_LINE_ITEM_LEVEL_IMPRESSIONS",
columns = 'TOTAL_UNFILLED_IMPRESSIONS',
columns = 'TOTAL_CPM_AND_CPM_IMPRESSIONS',
startDate=list(year=2019, month=7, day=1),
endDate=list(year=2019, month=7, day=1),
dateRangeType='CUSTOM_DATE')))
report_data <- dfp_full_report_wrapper(request_data)
When the data is pulled, the data frame has the columns- "Dimension.MONTH_AND_YEAR", "Dimension.AD_UNIT_NAME", "Dimension.ADVERTISER_NAME", "Dimension.PLACEMENT_NAME", "Dimension.COUNTRY_NAME", "Dimension.DEVICE_CATEGORY_NAME", "Dimension.LINE_ITEM_NAME", "Dimension.AD_UNIT_ID", "Dimension.ADVERTISER_ID", "Dimension.PLACEMENT_ID", "Dimension.COUNTRY_CRITERIA_ID", "Dimension.DEVICE_CATEGORY_ID", "Dimension.LINE_ITEM_ID", "Column.TOTAL_LINE_ITEM_LEVEL_CPM_AND_CPC_REVENUE"
, "Column.TOTAL_LINE_ITEM_LEVEL_IMPRESSIONS"
The column which is missing is floorTest (floortest) which is a custom dimension created in DFP.
What should be done to get the data from the custom dimension?
Thanks,
Hi.
How to work with AD_EXCHANGE metric and dimentions?
I get an error when I try to load data
ReportError.COLUMNS_NOT_SUPPORTED_FOR_REQUESTED_DIMENSIONS
request_data <- list(reportJob=list(reportQuery=list(dimensions='AD_EXCHANGE_DATE',
dimensions='AD_EXCHANGE_URL',
dimensions='AD_EXCHANGE_SITE_NAME',
dimensions='AD_EXCHANGE_PRODUCT_CODE',
adUnitView='FLAT',
columns = 'AD_EXCHANGE_AD_REQUESTS',
columns = 'AD_EXCHANGE_MATCHED_REQUESTS',
columns = 'AD_EXCHANGE_COVERAGE',
columns = 'AD_EXCHANGE_CLICKS',
columns = 'AD_EXCHANGE_AD_REQUEST_CTR',
columns = 'AD_EXCHANGE_AD_CTR',
columns = 'AD_EXCHANGE_CPC',
columns = 'AD_EXCHANGE_MATCHED_ECPM',
columns = 'AD_EXCHANGE_ESTIMATED_REVENUE',
columns = 'AD_EXCHANGE_IMPRESSIONS',
dateRangeType='YESTERDAY'
)))
Hi Steven
You package helps me a lot! I have quick question regarding function "dfp_full_report_wrapper". Am I able to apply any filter Statement within this function or is any other function in rdfp I can use to do the same thing? The purpose is to pull a report from Google AdManager. My query is as below but it took so long to query. I wish i could add a filter statement like "WHERE CUSTOM_CRITERIA LIKE %keyword% ".
Thanks a lot!
A <- list(
reportJob=list(
reportQuery=list(
dimensions= 'DATE',
dimensions= 'CUSTOM_CRITERIA',
dimensions= 'CREATIVE_SIZE_DELIVERED',
dimensions= 'LINE_ITEM_TYPE',
dimensions= 'LINE_ITEM_NAME',
columns= 'AD_SERVER_CPM_AND_CPC_REVENUE',
columns= 'AD_SERVER_IMPRESSIONS',
startDate= list(year=2019, month=09, day=07),
endDate= list(year=2019, month=12, day=04),
dateRangeType='CUSTOM_DATE')
))
A <- dfp_full_report_wrapper(A,
max_tries = Inf,
check_interval = 3)
Hi all, when I run the .R script from command line I see this error:
"Failed to create local cache ('.httr-oauth')"
Then when I request the report data in R gui (dfp_full_report_wrapper), I see this error:
Error: Refresh token not available
Here is the code I use:
library("rdfp")
library(magrittr)
library(formattable)
options(rdfp.network_code = "xxxxxxx",
rdfp.application_name = "MyAppDFP",
rdfp.client_id = "xxxxxxxxx-yyyyy.apps.googleusercontent.com",
rdfp.client_secret = "xxxxxx",
rdfp.httr_oauth_cache = TRUE)
dfp_auth()
today <- Sys.Date()
yesterday_day = format(as.Date(today-1,format="%Y-%m-%d"), "%d")
yesterday_month = format(as.Date(today-1,format="%Y-%m-%d"), "%m")
request_data <- list(reportJob=list(reportQuery=list(dimensions='AD_EXCHANGE_TAG_NAME',
adUnitView='TOP LEVEL',
columns='AD_EXCHANGE_REQUESTS',
columns="AD_EXCHANGE_MATCHED_QUERIES",
columns="AD_EXCHANGE_COVERAGE",
columns="AD_EXCHANGE_CLICKS",
columns="AD_EXCHANGE_MATCHED_QUERIES_CTR",
columns="AD_EXCHANGE_CPC_REVENUE",
columns="AD_EXCHANGE_REQUEST_ECPM",
columns="AD_EXCHANGE_ESTIMATED_REVENUE",
startDate=list(year=2017, month=yesterday_month, day=yesterday_day),
endDate=list(year=2017, month=yesterday_month, day=yesterday_day),
dateRangeType='CUSTOM_DATE')))
report_data_yesterday <- dfp_full_report_wrapper(request_data)
I would like to use in batch mode, with rdfp.httr_oauth_cache = FALSE
works.
Any suggestions would be really appreciated.
thanks in advance
C.
Hi Steven,
rdfp is great piece of work! :)
is it possible to auth with service account flow?
https://developers.google.com/doubleclick-publishers/docs/authentication#service
thanks,
lukas
Hi @ReportMort I see the same issue get by another user on stackoverflow.
I can pull queries from r studio if I create them manually, however I would like to be able to pull saved queries.
When the report in DFP UI has just one dimension works good, more than 1 dimensions the script has this error:
faultstring: [NotNullError.NULL @ reportJob.reportQuery]
errorString: NA
reason: NA
Error: api fault: [NotNullError.NULL @ reportJob.reportQuery]NANA
We are encountering below error after we updating to latest "rdfp" version: 0.1.3
Error: Unmarshalling Error: cvc-complex-type.2.4.a: Invalid content was found starting with element '{"https://www.google.com/apis/ads/publisher/v201811":timeZoneID}'. One of '{"https://www.google.com/apis/ads/publisher/v201811":timeZoneId}' is expected.
We are using the below two functions and encountering the error when we are calling the function "request_county_90day_inventory" with an input value.
Kindly help with some guidance.
`constructLineItem <- function(startDate,
endDate,
deliveryRateType,
frequencyCaps,
lineItemType,
priority,
costType,
creativePlaceholders,
primaryGoal,
targeting){
final <- list()
final$startDateTime$date <- list(year=as.integer(format(startDate, '%Y')),
month=as.integer(format(startDate, '%m')),
day=as.integer(format(startDate, '%d')))
final$startDateTime$hour=23
final$startDateTime$minute=59
final$startDateTime$second=59
final$startDateTime$timeZoneID="America/New_York"
final$endDateTime$date <- list(year=as.integer(format(endDate, '%Y')),
month=as.integer(format(endDate, '%m')),
day=as.integer(format(endDate, '%d')))
final$endDateTime$hour=23
final$endDateTime$minute=59
final$endDateTime$second=59
final$endDateTime$timeZoneID="America/New_York"
if(!is.null(deliveryRateType))
final$deliveryRateType <- deliveryRateType
if(is.null(frequencyCaps$maxImpressions) ||
is.null(frequencyCaps$numTimeUnits) ||
is.na(frequencyCaps$maxImpressions) ||
is.na(frequencyCaps$numTimeUnits)){
frequencyCaps <- NULL
}
if(!is.null(frequencyCaps))
final$frequencyCaps <- frequencyCaps
if(!is.null(lineItemType))
final$lineItemType <- lineItemType
if(!is.null(priority))
final$priority <- priority
if(!is.null(costType))
final$costType <- costType
split_size <- strsplit(creativePlaceholders, 'x')
final$creativePlaceholders$size <- list(width=as.integer(split_size[[1]][1]),
height=as.integer(split_size[[1]][2]),
isAspectRatio='false')
final$creativePlaceholders$expectedCreativeCount <- 1
final$creativePlaceholders$creativeSizeType <- 'PIXEL'
if(!is.null(primaryGoal))
final$primaryGoal <- primaryGoal
if(!is.null(targeting))
final$targeting <- targeting
finalfinal <- list(lineItem=final)
return(finalfinal)
}`
`request_county_90day_inventory <- function(targeted_counties){
t <- constructInventoryTargetingList(adUnitId=******************
criterias=list('695056'=******************
'695686'=******************
'604806'=******************))
hypothetical_line_item <- constructLineItem(startDate=Sys.Date() + 1,
endDate=Sys.Date() + 91,
deliveryRateType='EVENLY',
frequencyCaps=list(maxImpressions=NULL,
numTimeUnits=NULL,
timeUnit=NULL),
lineItemType='STANDARD',
priority=6,
costType='CPM',
creativePlaceholders='320x150',
primaryGoal=list(goalType='LIFETIME',
unitType='IMPRESSIONS',
units=1000),
targeting=t)
request_data <- list(lineItem=hypothetical_line_item,
forecastOptions=list(includeTargetingCriteriaBreakdown='true',
includeContendingLineItems='false'))
r <- dfp_getAvailabilityForecast(request_data, as_df = FALSE)
breakdowns <- r[[1]][c(names(r[[1]]) %in% 'targetingCriteriaBreakdowns')]
avails <- ldply(head(tail(breakdowns,-1),-1), .fun=function(x){
return(as.data.frame(x))
}, .id=NULL)
avails <- avails %>%
mutate(ImpressionsTotal=as.integer(matchedUnits),
ImpressionsAvailable=as.integer(availableUnits),
ImpressionsBooked=as.integer(ImpressionsTotal-ImpressionsAvailable)) %>%
select(targetingCriteriaName, ImpressionsBooked, ImpressionsAvailable)
return(avails)
}`
request_county_90day_inventory(******************)
Hi,
I got the below notice about DFP deprecating an API which i think relates to the app i created for this package to use.
Just wanted to make you aware of this in case not on your radar.
I'm just assuming at some stage users of your package would just need to update once you switch to the new api maybe. Or maybe its more complicated then that?
Seems like a while yet before they turn it off.
Here is the blog post http://googleadsdeveloper.blogspot.ie/2016/10/sunset-of-dfp-api-v201508-and-v201511.html
Would be happy to help test or anything if i can be of any use. Love the package makes dealing with DFP so much easier.
Cheers,
Andy
The function does not use the check_interval variable internally.
See line 256 in https://github.com/StevenMMortimer/rdfp/blob/master/R/dfp_utils.R: "Sys.sleep(3)" , it should be Sys.sleep(check_interval)
Currently the function dfp_date_to_list()
has an argument for the timezone that defaults to America/New_York
. It would be nice if this used the timezone of the object passed in if it has one. A better default might be the system default timezone if one is not provided.
TODO: Look at feasibility for getting the complete list of timezone ids and mapping them to R equivalents.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.