Title: | Loading Google Adwords Data into R |
---|---|
Description: | Aims at loading Google Adwords data into R. Adwords is an online advertising service that enables advertisers to display advertising copy to web users (see <https://developers.google.com/adwords/> for more information). Therefore the package implements three main features. First, the package provides an authentication process for R with the Google Adwords API (see <https://developers.google.com/adwords/api/> for more information) via OAUTH2. Second, the package offers an interface to apply the Adwords query language in R and query the Adwords API with ad-hoc reports. Third, the received data are transformed into suitable data formats for further data processing and data analysis. |
Authors: | Johannes Burkhardt <[email protected]>, Matthias Bannert <[email protected]> |
Maintainer: | Johannes Burkhardt <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.20 |
Built: | 2025-02-15 04:54:45 UTC |
Source: | https://github.com/jburkhardt/radwords |
Converts the default display names into nicer or more practical names.
changeNames(data)
changeNames(data)
data |
Transformed dataframe |
New column names of dataframe.
This function starts the authentication process with Google. Note that this functions needs user interaction.
doAuth(save = T)
doAuth(save = T)
save |
logical denotes whether authentication information should be saved on disk. Defaults to TRUE. |
getAuth authenticates the R app at the Google authentication server using OAUTH2 and receives the client token.
Usually you need not to run getAuth() explicitly since the whole authentication process is managed by doAuth
.
getAuth()
getAuth()
Client token from Google authentication server. Dataframe with the credential information which is cached in working space and optionally saved as RData file in current working directory.
getData posts the Adwords Query Language (awql) Statement which is generated with statement
.
The data are retrieved from the Adwords API as a dataframe.
getData(clientCustomerId, google_auth, statement, apiVersion = "201809", transformation = TRUE, changeNames = TRUE, includeZeroImpressions = FALSE, verbose = FALSE)
getData(clientCustomerId, google_auth, statement, apiVersion = "201809", transformation = TRUE, changeNames = TRUE, includeZeroImpressions = FALSE, verbose = FALSE)
clientCustomerId |
Adwords Account Id; supports a single account id: "xxx-xxx-xxxx" or a vector of ids from the same Google Ads MCC: c("xxx-xxx-xxxx", "xxx-xxx-xxxx") |
google_auth |
list of authentication |
statement |
awql statement generated with |
apiVersion |
supports 201809, 201806, 201802 defaults to 201806. |
transformation |
If TRUE, data will be transformed with |
changeNames |
If TRUE, the display names of the transformed data are converted into more nicer/practical names. Requires transformation = TRUE |
includeZeroImpressions |
If TRUE zero impressions will be included. Defaults to FALSE. |
verbose |
Defaults to FALSE. If TRUE, the curl connection output will be printed. |
Dataframe with the Adwords Data.
loadToken loads the access token using credentials provided by getAuth
. Execution of function is possible only once per authentication process.
Usually you need not to run loadToken() explicitly since the whole authentication process is managed by doAuth
.
loadToken(credlist)
loadToken(credlist)
credlist |
list of credentials |
Access token with corresponding time stamp.
metrics provides an overview of all available metrics/attributes for a specified report type.
metrics(report = "ACCOUNT_PERFORMANCE_REPORT", apiVersion = "201809")
metrics(report = "ACCOUNT_PERFORMANCE_REPORT", apiVersion = "201809")
report |
Report type |
apiVersion |
Supports 201809, 201806, 201802. Defaults to 201809. |
List of available metrics/attributes.
The aim of RAdwords is loading Google Adwords data into R. Therefore the
package implements three main features.
First, the package provides an authentication process for R with the Adwords API via OAUTH2.
Second, the package offers an interface to apply the Adwords query language in R and query the Adwords API with ad-hoc reports.
Third, the received data are transformed into suitable data format for further data processing
and data analysis.
Requirements:
In order to access the Adwords API you have to set up a Google API project for native apps. The Google API project provides a Client Id and Client Secret which is necessary for the authentication. Moreover you need to have a Adwords MCC (My Client Center) with an Adwords developer token.
Authentication:doAuth
manages the complete authentication process. Meaning doAuth
authenticates the R app for the first time, loads the access token or refreshes the access token if expired. Hence, you only run doAuth() to authenticate whether it is your initial R Session or a later instance.
What's happening in details?
Once the API projects for native application is set up, getAuth
is able to authenticate the R app with the credentials (Client Id, Client Secret) from the Google API project. The Google authentication server returns a client token, which later is used by loadToken
to receive the access token. If the access token is expired after one hour, it can be updated with refreshToken
. The access token in combination with the Adwords developer token enables a connection with the Adwords API.
Create Statement:statement
creates the Adwords Query Language Statement.
Receiving Data:getData
queries the data from the Adwords API and transforms the data into an R dataframe.
Johannes Burkhardt <[email protected]>
Matthias Bannert <[email protected]>
https://github.com/jburkhardt/RAdwords
## Not run: Authentication: google_auth <- doAuth() Create Statement: body <- statement(select = c('Clicks','AveragePosition','Cost','Ctr'), report = "ACCOUNT_PERFORMANCE_REPORT", start = "2018-01-01", end = "2018-01-10") Query Adwords API and load data as dataframe: data <- getData(clientCustomerId = 'xxx-xxx-xxxx', #use Adwords Account Id (MCC Id will not work) google_auth = google_auth, statement = body) Get available report types: reports() Get available metrics/attributes of specific report type: metrics(report = 'ACCOUNT_PERFORMANCE_REPORT') ## End(Not run)
## Not run: Authentication: google_auth <- doAuth() Create Statement: body <- statement(select = c('Clicks','AveragePosition','Cost','Ctr'), report = "ACCOUNT_PERFORMANCE_REPORT", start = "2018-01-01", end = "2018-01-10") Query Adwords API and load data as dataframe: data <- getData(clientCustomerId = 'xxx-xxx-xxxx', #use Adwords Account Id (MCC Id will not work) google_auth = google_auth, statement = body) Get available report types: reports() Get available metrics/attributes of specific report type: metrics(report = 'ACCOUNT_PERFORMANCE_REPORT') ## End(Not run)
refreshToken returns a new valid access token. The access token deprecates after one hour and has to updated with the refresh token.
Usually you need not to run refreshToken() explicitly since the whole authentication process is managed by doAuth
.
refreshToken(google_auth)
refreshToken(google_auth)
google_auth |
list of credentials and access token |
New access token with corresponding time stamp.
reports provides an overview of all available Adwords report types. The report type is specified in statement
.
reports(apiVersion = "201809")
reports(apiVersion = "201809")
apiVersion |
Supports 201809, 201806 and 201802. Defaults to 201809. |
Available report types.
Generates and builds the Adwords Query Language Statement for querying the Adwords API.
statement(select = c("AccountDescriptiveName", "AccountId", "Impressions", "Clicks", "Cost", "Date"), report = "ACCOUNT_PERFORMANCE_REPORT", where, start = "2018-01-01", end = "2018-01-10", apiVersion = "201809", compress = TRUE)
statement(select = c("AccountDescriptiveName", "AccountId", "Impressions", "Clicks", "Cost", "Date"), report = "ACCOUNT_PERFORMANCE_REPORT", where, start = "2018-01-01", end = "2018-01-10", apiVersion = "201809", compress = TRUE)
select |
Attributes |
report |
Report type |
where |
Condition list, e.g. "CampaignName STARTS_WITH 'A' AND Clicks > 100", multiple conditions can be only combined with AND Operators: = | != | > | >= | < | <= | IN | NOT_IN | STARTS_WITH | STARTS_WITH_IGNORE_CASE | CONTAINS | CONTAINS_IGNORE_CASE | DOES_NOT_CONTAIN | DOES_NOT_CONTAIN_IGNORE_CASE |
start |
Beginning of date range. Format: 2018-01-01 |
end |
End of date rage. Format: 2018-01-10 |
apiVersion |
Adwords API Version, supports 201809, 201806, 201802 defaults to 201809. |
compress |
TRUE / FALSE, Gzipped data download if TRUE |
The statement neccessary for the getData
function.
body <- statement(select=c('CampaignName','Clicks','Cost','Ctr'), report="CAMPAIGN_PERFORMANCE_REPORT", where="CampaignName STARTS_WITH 'A' AND Clicks > 100", start="2018-01-20", end="2018-01-21") body <- statement(select=c('Criteria','Clicks','Cost','Ctr'), report="KEYWORDS_PERFORMANCE_REPORT", where="Clicks > 100", start="2018-01-20", end="2018-01-21") body <- statement(select=c('Clicks','AveragePosition','Cost','Ctr'), report="ACCOUNT_PERFORMANCE_REPORT", start="2018-01-20", end="2018-01-21")
body <- statement(select=c('CampaignName','Clicks','Cost','Ctr'), report="CAMPAIGN_PERFORMANCE_REPORT", where="CampaignName STARTS_WITH 'A' AND Clicks > 100", start="2018-01-20", end="2018-01-21") body <- statement(select=c('Criteria','Clicks','Cost','Ctr'), report="KEYWORDS_PERFORMANCE_REPORT", where="Clicks > 100", start="2018-01-20", end="2018-01-21") body <- statement(select=c('Clicks','AveragePosition','Cost','Ctr'), report="ACCOUNT_PERFORMANCE_REPORT", start="2018-01-20", end="2018-01-21")
Transforms the csv data file received from the Adwords API into a dataframe. Moreover the variables are converted into suitable formats.
The function is used inside getData
and parameters are set automatically.
transformData(data, report = reportType, apiVersion = "201809")
transformData(data, report = reportType, apiVersion = "201809")
data |
Raw csv data from Adwords API. |
report |
Report type. |
apiVersion |
set automatically by |
Dataframe with the Adwords Data.