MyNixOS website logo
Description

Access 'Piwik Pro' Website Statistics.

Run Queries against the API of 'Piwik Pro' <https://developers.piwik.pro/en/latest/custom_reports/http_api/http_api.html>. The result is a tibble.

piwikproR

R package for accessing data from Piwik PRO via API.

CRAN status CRAN RStudio mirror downloads CRAN RStudio mirror downloads R-CMD-check

PIWIK PRO is a tool to measure traffic of a website. They offer an API for fetching all metrics and dimensions so you can use them in your own program.

This R-Package uses the API to fetch the data from PIWIK PRO using R-code. You get the data as tibble (or as a data.frame). So it's easy to analyze the data with the whole power of R.

Installation

CRAN Version

The package is now available on CRAN. So you can install it by running

install.packages("piwikproR")

Development Version

Using devtools it's easy to install piwikproR:

devtools::install_github("dfv-ms/piwikproR")

Usage

Load the library

library(piwikproR)

Credentials for API, token

First you need to setup an access to the API. See here: [https://developers.piwik.pro/en/latest/platform/getting_started.html#create-api-credentials-and-an-access-token]

Let's say you put them into a list:

piwik_pro_credentials <- list(
  client_id = "my_client_id",
  client_secret = "my_client_secret",
  url = "https://my_site.piwik.pro"
 )

Using these credential you can fetch a token

token <- get_login_token(piwik_pro_credentials)

Website id

Set the website_id and the date range.

website_id <- 'my_website_id'
start.date <- "2021-04-01"
end.date <- "2021-04-30"

Defining the columns to be fetched

Now we define the columns we want to fetch. Here's an example:

We want to fetch the date, the url (only the path without the hostname) and the page_views:

columns <- tibble::tribble(
  ~column, ~transformation,
  "timestamp", "",
  "event_url", "to_path",
  "page_views", "",
)

Filters

We're only interested in -- let's say -- Desktop requests. So let's set a filter:

filters <- tibble::tribble(
 ~column, ~operator, ~value,
 "device_type", "eq", 0
)
filters <- build_filter(filters, "and")

Fetching the data

query <- build_query(lubridate::ymd(start.date), lubridate::ymd(end.date), website_id,
                    filters = filters,
                    columns, max_lines = 0
)
data <- send_query(query, token, caching = TRUE, fetch_by_day = FALSE)

Metrics and Dimensions Documentation

PIWIK PRO offers a great documentation of all metrics and dimensions starting here [https://developers.piwik.pro/en/latest/custom_reports/index.html]

Developing

I'm using unit tests to test my code. But these tests run against a special website_id whose data is not publicly available. So I put all those sensitive data into a private package piwikproRTests. If this package is not available all tests are skipped.

Issues

If you find a bug or if you have a feature request feel free and open an issue

Documentation

Further documentation can be found here: https://PiwikProR.rstats-tips.net/index.html

Thanks

dfv media group

Thanks to my employer dfv media group for the permission to publish this package as open source.

Metadata

Version

0.4.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows