The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Basic work with googleadsR

Goal

The goal here is to outline in a couple of paragraphs and few lines of code some simple ways in which we can use the Windsor.ai API and R package googleadsR to gain insights into marketing campaign performance in Google Ads. The nice thing about Windsor.ai is that you can have all of your marketing channels aggregating in a single place and then access all data at once using this package. In this case, however, the package is focused on getting data from Google Ads campaigns. Of course, once the data is in R you can do much more than the examples below, and work on analysis, predictions or dashboards.

Getting data from Google ads into R

After we create an account at Windsor.ai and obtain an API key, collecting our data from Windsor to R is as easy as:

library(googleadsR)
my_data_googleads <- 
  fetch_googleads(
  api_key = "your api key")
)

Lets take a look at the data we just downloaded to get a better idea about the structure and type of information included.

str(my_data_googleads)
#> 'data.frame':    1676 obs. of  6 variables:
#>  $ campaign    : chr  "(ID)<00_mat>[id-cat]{eb}: mattress" "(ID)<00_mat>[emma mattress]{eb}: emma mattress" "Kampanja #1" "Myyntipäälliköksi Iponille" ...
#>  $ clicks      : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ spend       : chr  "0" "0" "0" "0" ...
#>  $ medium      : chr  "Unknown" "Unknown" "Unknown" "Unknown" ...
#>  $ source      : chr  "google" "google" "google" "google" ...
#>  $ googlesheets: chr  "'spreadsheet_id'" "'spreadsheet_id'" "'spreadsheet_id'" "'spreadsheet_id'" ...

Analyzing our Google ad campaign data

First, lets try to find the campaigns with most clicks. To do this, we’ll filter only those rows that have clicks, then group the dataset by campaign (campaign column) and sum up the click count per campaign.

library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.2.2
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.2.2

top_10 <- 
  my_data_googleads %>% 
  filter(clicks > 0) %>% 
  group_by(campaign) %>% 
  summarise(n_clicks = sum(clicks)) %>% 
  ungroup %>% 
  arrange(desc(n_clicks)) %>% 
  slice_head(n = 10)

knitr::kable(top_10)
campaign n_clicks
AO_Smart_Shopping_Running_Jogging 56670
city_display_awareness_hyd_april_2021 54711
AO_Dynamic_Remarketing_Cart_Abandoners 54089
AO_Dynamic_Remarketing_Cart_Abandoners_Website 39969
AO_Smart_Shopping_Yoga 27551
AO_Search_Brand_Exact 24535
AO_UAC_app_install 21958
AO_UAC_app_install_Hyd 20155
AO_Shopping_Cycling 18852
AO_UAC_app_install_chennai 16905

Thereafter we can quickly visualize our data using ggplot2

ggplot(top_10, aes(x = n_clicks, y = campaign)) +
  geom_col()

We can apply the same type of data manipulation and plotting to check the spend values.

my_data_googleads %>%
  filter(clicks > 0) %>%
  group_by(campaign) %>%
  summarise(sum_spend = sum(as.numeric(spend))) %>%
  ungroup %>%
  arrange(desc(sum_spend)) %>%
  slice_head(n = 10) %>%
  ggplot(aes(x = sum_spend, y = campaign)) +
  geom_col()

Finally, for a direct comparison, we can aggregate both the clicks and spending per ad campaign and plot them jointly:

library(tidyr)

my_data_googleads %>%
  filter(clicks > 0) %>%
  group_by(campaign) %>%
  summarise(n_clicks = sum(clicks), sum_spend = sum(as.numeric(spend))) %>%
  arrange(desc(sum_spend)) %>%
  slice_head(n = 10) %>%
  pivot_longer(cols = c("n_clicks", "sum_spend"), names_to = "aggreg", values_to = "values") %>%  
  ggplot(aes(x = values, y = campaign, fill = aggreg)) +
  geom_col() +
  facet_wrap("aggreg", ncol = 2) + 
  theme(legend.position="bottom")

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.