Connect to Matomo Web Analytics Reporting API | Read-only mirror of https://github.com/statistikZH/statZHmatomo — Kanton Zürich. Issues & pull requests at the source.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Corinna Grobe 92d0f117b9
Merge pull request #17 from statistikZH/#16
change idSite of webzh-dk server from 4 to 13
2023-09-28 17:16:51 +02:00
.github Remove listviewer dependency 2020-11-25 14:33:40 +01:00
man Add license, contributing and CoC 2020-11-25 13:35:39 +01:00
R change idSite of webzh-dk server from 4 to 13 2023-09-28 13:34:15 +02:00
vignettes Update installation guidance 2020-11-25 15:43:59 +01:00
.gitignore Add github Actions to deploy 2020-11-25 13:47:37 +01:00
.Rbuildignore Add github Actions to deploy 2020-11-25 13:47:37 +01:00
_pkgdown.yml Build pkgdown website 2020-07-31 10:30:23 +02:00
CodeOfConduct.md Add license, contributing and CoC 2020-11-25 13:35:39 +01:00
CONTRIBUTING.md Add license, contributing and CoC 2020-11-25 13:35:39 +01:00
DESCRIPTION Add lifecycle badges to package 2020-11-25 11:50:51 +01:00
KtZuerichLogo.png Add license, contributing and CoC 2020-11-25 13:35:39 +01:00
LICENSE Add MIT license 2020-07-30 11:49:27 +02:00
LICENSE.md Add MIT license 2020-07-30 11:49:27 +02:00
LICENSE_code Add license, contributing and CoC 2020-11-25 13:35:39 +01:00
NAMESPACE function name changed to set_matomo_server 2020-10-12 15:41:39 +02:00
README.md Merge branch 'main' of https://github.com/statistikZH/statZHmatomo into main 2020-11-25 15:46:06 +01:00
README.Rmd Merge branch 'main' of https://github.com/statistikZH/statZHmatomo into main 2020-11-25 15:46:06 +01:00
statZHmatomo.Rproj Initial commit 2020-07-30 10:49:26 +02:00

statZHmatomo

Lifecycle:
experimental

Project description

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().

Installation

# install.packages("devtools")
devtools::install_github("statistikZH/statZHmatomo")

Proxy Error?

Follow these steps:

  1. In RStudio click “Tools -> Global Options”
  2. Open pane “Git/SVN”
  3. Under SSH RSA key, click “Create RSA Key…”
  4. Passphrase is optional, click “Create”
  5. Click “Close” on the opened window
  6. Click “Apply” followed by “OK”

Try again:

devtools::install_github("statistikZH/statZHmatomo")

Prerequisites

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:

  1. Install R Package {usethis} by executing install.packages("usethis") in R Console.

  2. Execute usethis::edit_r_environ() in R Console.

  3. 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”

  4. Save .Renviron file via “File -> Save” or “Ctrl / Cmd + S”

  5. Restart R via “Session -> Restart R” or “Ctrl / Cmd + Shift + Enter”

Example

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

Contributors

Contact

Christian Ruiz
christian.ruiz@statistik.ji.zh.ch
+41 (0)43 259 7500

License

Copyright (c) <2019> <Statistisches Amt Kanton Zürich>

Richtlinien für Beiträge

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.