In this guide you will learn how to get your data from Google Ads into R. To do so, we will use windsor.ai API key. Windsor.ai is a product that allows you to integrate all your marketing data from different sources such as Google Ads but also Facebook, twitter, Instagram, etc. We will use this product as it does not have any limitation when it comes to volume of data queried by means of API call requests. Then, we will further analyse and plot the data to get some interesting insights.
All you need before starting getting your data is to create and account in windsor.ai and get an API key and install the googleadsR package. So, let’s proceed!
First of all, let’s get you a windsor.ai API, in case you do not have one. This process is extremely straightforward and will only take you a few minutes. All you need to do is to sign-in here. Then, by following these four steps you will have access to your API key:
access to your Google Ads data
get windsor.ai API for Google Ads
Okey, now you are ready to open your R project and start extracting and loading your google Ads data from windsor.ai.
CAREFUL! This is your personal API key to your data, so make sure you do not make it public. I recommend you to paste it in a safe space with restricted access.
Before downloading your data, you will need to have the R functions that allows you to connect R with windsor.ai via API. There are several ways to do that, but here we will use the googleadsR package. Then, you will need to install googleadsR and load it.
remotes::install_github("https://github.com/pablosanchezmart/googleadsR")
## Skipping install of 'googleadsR' from a github remote, the SHA1 (b160b912) has not changed since last install.
## Use `force = TRUE` to force installation
library(googleadsR)
Once googleadsR is installed and loaded, you can use the function windsor_fetch_googleAds to get your Google Ads data. You will need to paste your API. Then, there are several arguments of the function that control the data that is imported to your R project environment. Let’s have a look at the arguments of the function:
Once you include your API key, the following code will download Google Ads marketing data regarding clicks and time spend for each campaign for the last 30 days.
my_data_googleads_last30d <-
windsor_fetch_googleAds(
api_key = "your API key",
date_preset = "last_30d",
fields = c("campaign", "clicks", "spend")
)
This is how the data looks like:
| campaign | clicks | spend |
|---|---|---|
| BigQuery Integration | 29 | 23.62 |
| Google Data Studio Integration | 58 | 62.73 |
| Google Sheets Integration | 20 | 27.71 |
| Google Sheets Integration - chosen countries | 1 | 2.04 |
| Leads-Performance Max-Test | 18 | 18.59 |
| Leads-Performance Max-Test - chosen countries | 14 | 7.23 |
Now you are ready to further visualize, analyze our data to produce reports on your marketing data. Next, we will see some examples on how to do that.
A good way to assess the distribution of our data in a visual way is by means of density plots. By plotting a density plot for the number of clicks, you will see how your marketing data looks like regarding specific variables. We will plot it for the number of clicks. Let’s get rid of the campaigns with zeros and see how the number of clicks distribute.
my_data_googleads_last30d_noZeros <- my_data_googleads_last30d %>%
filter(clicks != 0)
ggplot(data = my_data_googleads_last30d_noZeros) +
geom_density(aes(clicks)) +
theme_minimal()
We see that we have most of the campaigns with a low number of clicks and a low number of campaigns with a high number of clicks. Let’s focus now on those with the highest number of clicks. Let’s see which are the 10 campaigns with the highest number of clicks.
my_data_googleads_last30d_campaing <- my_data_googleads_last30d %>%
filter(clicks > 0) %>%
group_by(campaign) %>%
summarise(n_clicks = sum(clicks), spend = round(sum(spend), 2))
top_10 <- my_data_googleads_last30d_campaing %>%
arrange(desc(n_clicks)) %>%
slice_head(n = 10)
knitr::kable(top_10[, c(1:2)])
| campaign | n_clicks |
|---|---|
| Retargeting Campaign | 583 |
| pmax test | 276 |
| Powerbi Integration | 225 |
| Snowflake Integration | 135 |
| Sales-Search-7 | 114 |
| competitors | 77 |
| Google Data Studio Integration | 58 |
| Tableau Integration | 40 |
| BigQuery Integration | 29 |
| Search - Power BI and Salesforce - Brazil l B&B | 28 |
We can easily plot this results to better assess the number of clicks per campaign by using bar plots.
ggplot(top_10, aes(x = n_clicks, y = campaign)) +
geom_col() +
xlab("Number of Clicks") + ylab("Campaign") +
theme_minimal()
We could also include another variable to colour the bars to have a higher information in the bar plot. Let’s add, for instance, the variable “spend” represented as the colour bar.
ggplot(top_10, aes(x = n_clicks, y = campaign, fill = spend)) +
geom_col() +
xlab("Number of Clicks") + ylab("Campaign")
We can see, for instance, that even if Snowflake integration campaign is not the one with the highest number of clicks, it presents a high number of time spent.
We may be also interested in those campaigns with the lowest number of clicks, as they are not performed as we would like. Let’s list all the campaigns with lower than 5 clicks for the last month.
knitr::kable(my_data_googleads_last30d %>%
filter(clicks < 5) %>%
select(campaign)
)
| campaign |
|---|
| Google Sheets Integration - chosen countries |
| Powerbi Integration - chosen countries |
| Templates Campaign |
| powerbi US |
Finally, we can perform some statistical analyses to get some objective insights. For instance, let’s see if there is a relationship among the time spent and the number of clicks in our data for all campaigns. First of all, we can plot the relationship between spend and number of clicks per campaign as a scatterplot and visualize the tendency.
ggplot(my_data_googleads_last30d, aes(x = clicks, y = spend)) +
geom_point() +
geom_smooth(method = "lm") +
xlab("Number of clicks") + ylab("Time spent") + theme_minimal()
## `geom_smooth()` using formula 'y ~ x'
Then, we can calculate the correlation between these two variables.
round(cor(my_data_googleads_last30d_campaing$n_clicks, my_data_googleads_last30d_campaing$spend), 2)
## [1] 0.28
lmod <- lm(n_clicks ~ spend, my_data_googleads_last30d_campaing)
summary(lmod)
##
## Call:
## lm(formula = n_clicks ~ spend, data = my_data_googleads_last30d_campaing)
##
## Residuals:
## Min 1Q Median 3Q Max
## -108.46 -60.98 -48.57 -17.07 494.42
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 61.9534 35.1327 1.763 0.0948 .
## spend 0.2968 0.2357 1.259 0.2240
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 138.2 on 18 degrees of freedom
## Multiple R-squared: 0.08098, Adjusted R-squared: 0.02992
## F-statistic: 1.586 on 1 and 18 DF, p-value: 0.224
The correlation is not very high, and the linear model is not significant. So, even if there is a weak tendency of those campaigns having a higher number of clicks to present a higher time spend, this effect is not strong.
You may be also interested in other kind of analyses such as for instance, comparing different campaigns to see which one performs better and if this difference is statistically significant, whether one campaign performed better during a specific month or whether there is any time dependence in your results (for instance, better results during summer). If so, do not hesitate to leave your comments and we can further discuss these issues or any other question you may have.