Skip to content

banboo-data/r4googleads

Repository files navigation

r4googleads -
R Client Library for Google's Ads Interface

CRAN status CRAN monthly downloads Lifecycle: stable R-CMD-check

Buy Me A Coffee

Welcome to the source code repository of the {r4googleads} package. {r4googleads} helps you to implement your advertising performance analytics in R and increase your efficiency, make your reports reproducible and flexible enough to managing even large, complex Google Ads accounts and campaigns.

If you came for the user documentation and howto, please visit {r4googleads}' our pkgdown documentation site.

The {r4googleads} package uses Google Ads' application programming interface to conveniently load data from Google Ads into an R environment. The Google Ads API suceeds Google's Adwords API and consequently, {r4googleads} suceeds its popular predecessor R package {RAdwords}.

Installation

To install the latest stable version of {r4googleads} from R's official Comprehensive R Archive Network (CRAN) run

install.packages("r4googleads")

or install the latest development release from GitHub using the {remotes} R package. (the below example code assumes the {remotes} package has been installed previously.)

remotes::install_github("banboo-data/r4googleads")

Basic Example - Load Data

library(r4googleads)

To specify which data you want to load into your R session you can use Google's own SQL reminiscant query language. The above link helps you to find out about available reports and to validate your queries online.

g_query <- "SELECT
                campaign.name, 
                campaign.status,
                segments.device, 
                metrics.impressions,
                metrics.clicks, 
                metrics.ctr,
                metrics.average_cpc, 
                metrics.cost_micros
              FROM campaign
              WHERE segments.date DURING LAST_30_DAYS
              AND metrics.impressions > 0
              PARAMETERS include_drafts=true"

The next step is to create a service object that contains the query string, your Google Ads Account ID and the API version you want to use. The example goes on to use one of our 3 constructors to create different service objects: googleAdsSearch, googleAdsFields, listAccessibleCustomers.

query_service <- googleAdsSearch(
  aid = '***-****-***', # Google Ads Account ID
  query = g_query,
  api_version = 'v9'
  )

the resulting service query object can be passed on to the query_google_ads functions which sends the service object to Google's actual API service. Note, that a MCC ID is needed here. The handler inside query_google_ads processes the service object depending on its class and starts the corresponding request.

d <- query_google_ads(
  mcc_id = '***-***-****', # Google Ads My Client Center ID
  google_auth = google_auth,
  service = query_service,
  raw_data = F
)

To learn more about creating and using our service objects visit the {r4googleads} pkgdown documentation site.

Releases

No releases published

Packages

No packages published

Languages