The goal of statZHmatomo is to provide functions for access to the Matomo Reporting API.
Currently, the package supports:
The package currently contains two function: read_matomo_data()
and set_matomo_server()
.
# install.packages("devtools")
devtools::install_github("statistikZH/statZHmatomo")
Proxy Error?
Follow these steps:
Try again:
devtools::install_github("statistikZH/statZHmatomo")
Your Matomo API Token needs to be added to the .Renviron
file before the functions can be used. The token is then called via Sys.getenv("token")
. This ensures that tokens are do not need to be pasted into scripts.
To add your token, follow these steps:
Install R Package {usethis} by executing install.packages("usethis")
in R Console.
Execute usethis::edit_r_environ()
in R Console.
Replace YOUR_TOKEN with your token. One line per token the following names:
# ZHweb Datenkataliog Matomo token
token_webzh-dk = “YOUR_TOKEN”
# opendata.swiss Matomo token
token_openzh = “YOUR_TOKEN”
# ZHWeb Token
token_webzh = “YOUR_TOKEN”
Save .Renviron
file via “File -> Save” or “Ctrl / Cmd + S”
Restart R via “Session -> Restart R” or “Ctrl / Cmd + Shift + Enter”
This is a basic example using the API module ‘Action’ and the API action ‘getPageUrls’. More detailed information is available in the vignette “Getting started”.
# Load packages
library(statZHmatomo)
library(magrittr)
# Establish connection to one of the three servers
con_webzhdk <- set_matomo_server(server = "webzh-dk")
# Store data for yesterday (preset) as object dat
dat <- read_matomo_data(connection = con_webzhdk,
apiModule = "Actions",
apiAction = "getPageUrls"
)
# Call object dat and produce a table with the first 8 variables
dat %>%
tibble::as_tibble() %>%
janitor::clean_names() %>%
dplyr::select(1:8) %>%
knitr::kable()
label | nb_visits | nb_hits | sum_time_spent | nb_hits_following_search | nb_hits_with_time_generation | min_time_generation | max_time_generation |
---|---|---|---|---|---|---|---|
openZH | 220 | 253 | 26957 | 221 | 241 | 0.001 | 9.455 |
search | 35 | 48 | 3384 | 15 | 48 | 0.007 | 2.183 |
data | 17 | 21 | 1551 | 6 | 21 | 0.005 | 0.495 |
de | 11 | 13 | 514 | 6 | 13 | 0.001 | 0.218 |
ogd | 3 | 3 | 0 | 2 | 3 | 0.193 | 1.499 |
Christian Ruiz
christian.ruiz@statistik.ji.zh.ch
+41 (0)43 259 7500
Wir begrüßen Beiträge. Bitte lesen Sie unsere CONTRIBUTING.md Datei, wenn sie daran interessiert sind. Hier finden Sie Informationen die zeigen wie Sie beitragen können.
Bitte beachten Sie, dass dieses Projekt mit einem Verhaltenskodex veröffentlicht wird. Mit Ihrer Teilnahme an diesem Projekt erklären Sie sich mit dessen Bedingungen einverstanden.