-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitial_script.R
49 lines (42 loc) · 1.7 KB
/
initial_script.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
library(searchConsoleR)
library(googleAnalyticsR)
## authentication with both GA and SC
options(googleAuthR.scopes.selected =
c("https://www.googleapis.com/auth/webmasters",
"https://www.googleapis.com/auth/analytics",
"https://www.googleapis.com/auth/analytics.readonly"))
googleAuthR::gar_auth()
## replace with your GA ID
ga_id <- 80379883
## date range to fetch
start <- as.character(Sys.Date() - 93)
end <- "2017-10-01"
## Using new GA v4 API
## GAv4 filters
google_seo <-
filter_clause_ga4(list(dim_filter("medium",
"EXACT",
"organic"),
dim_filter("source",
"EXACT",
"google")),
operator = "AND")
## Getting the GA data
gadata <-
google_analytics_4(ga_id,
date_range = c(start,end),
metrics = c("sessions",
"transactions",
"transactionRevenue"),
dimensions = c("landingPagePath"),
dim_filters = google_seo,
order = order_type("transactions",
sort_order = "DESC",
orderType = "VALUE"),
max = 20000)
## Getting the Search Console data
## The development version >0.2.0.9000 lets you get more than 5000 rows
scdata <- search_analytics("https://www.build.com",
startDate = start, endDate = end,
dimensions = c("page","query"),
rowLimit = 20000)