Skip to contents

Get data from Google Ads API

Usage

gads_get_report(
  resource = "campaign",
  fields = c("campaign.id", "campaign.name", "customer.id", "customer.descriptive_name",
    "campaign.status", "segments.date", "metrics.all_conversions", "metrics.clicks",
    "metrics.cost_micros", "metrics.ctr", "metrics.impressions",
    "metrics.interaction_rate", "metrics.interactions", "metrics.invalid_clicks"),
  where = NULL,
  order_by = NULL,
  limit = NULL,
  parameters = NULL,
  date_from = Sys.Date() - 15,
  date_to = Sys.Date() - 1,
  during = c(NA, "TODAY", "YESTERDAY", "LAST_7_DAYS", "LAST_BUSINESS_WEEK", "THIS_MONTH",
    "LAST_MONTH", "LAST_14_DAYS", "LAST_30_DAYS", "THIS_WEEK_SUN_TODAY",
    "THIS_WEEK_MON_TODAY", "LAST_WEEK_SUN_SAT", "LAST_WEEK_MON_SUN"),
  customer_id = getOption("gads.customer.id"),
  login_customer_id = getOption("gads.login.customer.id"),
  include_resource_name = FALSE,
  gaql_query = NULL,
  cl = NULL,
  verbose = TRUE
)

Arguments

resource

Report type, you can get list of all acessible resource using gads_get_metadata. For more information see link with list of all resources

fields

character vector, list of report fields, all report has own fields list. You can get list of accesible resource fields using gads_get_fields for example see field list of campaign report.

where

Filter, for example you can filter campaigns by status where = "campaign.status = 'ENABLED'".

order_by

Sorting, character vectors of fields and sorting directions, for example order_by = c("campaign.name DESC", "metrics.clicks").

limit

Maximun rows in report

parameters

Query parameters, for example parameters = "include_drafts=true".

date_from

Beginning of date range. Format: 2018-01-01

date_to

End of date rage. Format: 2018-01-10

during

Predefined date range. See documentation for more details.

customer_id

Google Ads client customer 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")

login_customer_id

Google Ads manager customer id

include_resource_name

Get resource names fields in report

gaql_query

GAQL Query, you can make it in gads_get_metadata. For more information see Query Builder. If you use gaql_query, you don't need set other query parameters like resource, fields, where, dates etc.

cl

A cluster object created by makeCluster, or an integer to indicate number of child-processes (integer values are ignored on Windows) for parallel evaluations (see Details on performance).

verbose

Console log output

Value

tibble with the Google Ads Data.

Examples

if (FALSE) {
# set client id
gads_set_login_customer_id('xxx-xxx-xxxx')

# set manager id if you work under MCC
gads_set_customer_id('xxx-xxx-xxxx')

# default paramas is campaign performance report
campaign_stat <- gads_get_report()


# you can load data from several client accounts at once
# from the same Google Ads MCC
# client ids
accounts <- c('xxx-xxx-xxxx', 'yyy-yyy-yyyy')
# loading data
multi_rep <- gads_get_report(
    date_from = as.Date('2021-06-10'),
    date_to = as.Date('2021-06-17'),
    customer_id = accounts
)

# ------------------
# using more arguments for other reports
group_report <- gads_get_report(
customer_id = 4732519773,
resource    = "ad_group",
fields = c("ad_group.campaign",
           "ad_group.id",
           "ad_group.name",
           "ad_group.status",
           "metrics.clicks",
           "metrics.cost_micros"),
date_from   = "2021-06-10",
date_to     = "2021-06-17",
where       = "ad_group.status = 'ENABLED'",
order_by    = c("metrics.clicks DESC", "metrics.cost_micros"),
limit       = 30000
)

# ------------------
# parallel loading mode
# note: you must using login_customer_id agrument in parallel mode
# because oprions gads_set_login_customer_id() does't work in parallel mode loading
library(parallel)

# make core cluster
cl <- makeCluster(4)

# loading data
multi_rep <- gads_get_report(
  date_from         = as.Date('2021-06-10'),
  date_to           = as.Date('2021-06-17'),
  customer_id       = c('111-111-1111',
                        '222-222-2222',
                        '333-333-3333',
                        '444-444-4444',
                        '555-555-5555'),
  login_customer_id = "999-999-9999",
  cl                = cl
)

# stop cluster
stopCluster(cl)
}