| Title: | Access Plausible Analytics API |
|---|---|
| Description: | Access Plausible Analytics API. |
| Authors: | Giorgio Comai [aut, cre] (ORCID: <https://orcid.org/0000-0002-0515-9542>) |
| Maintainer: | Giorgio Comai <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.7.9003 |
| Built: | 2026-05-13 08:59:48 UTC |
| Source: | https://github.com/giocomai/plausibler |
Creates a curl handler object with API keys (used internally)
pa_create_handler()pa_create_handler()
A curl handler object
pa_set( base_url = "https://plausible.io/", site_id = "example.com", key = "actual_key_here" ) pa_create_handler()pa_set( base_url = "https://plausible.io/", site_id = "example.com", key = "actual_key_here" ) pa_create_handler()
For details, consult the official documentation.
pa_get(endpoint, parameters = NULL, filters = NULL, full_url = NULL)pa_get(endpoint, parameters = NULL, filters = NULL, full_url = NULL)
endpoint |
Endpoint as described in the official documentation, e.g. "/api/v1/stats/timeseries". |
parameters |
A named list with parameters (see example). If you want to
run more complex queries you can leave this |
filters |
Optional, defaults to |
full_url |
Defaults to |
A data frame (a tibble) with results.
## Not run: pa_get( endpoint = "/api/v1/stats/timeseries", parameters = list(period = "6mo") ) # Same as above, but with full_url: # N.B. You still need to set the key with pa_set(). Replace $SITE_ID with your domain pa_get(full_url = "https://plausible.io/api/v1/stats/timeseries?site_id=$SITE_ID&period=6mo") ## End(Not run)## Not run: pa_get( endpoint = "/api/v1/stats/timeseries", parameters = list(period = "6mo") ) # Same as above, but with full_url: # N.B. You still need to set the key with pa_set(). Replace $SITE_ID with your domain pa_get(full_url = "https://plausible.io/api/v1/stats/timeseries?site_id=$SITE_ID&period=6mo") ## End(Not run)
Get aggregated stats for a given website
pa_get_aggregate(period = "30d", metrics = "visits")pa_get_aggregate(period = "30d", metrics = "visits")
period |
Period to include in the analysis, defaults to "30d". See examples as well as the the official documentation for valid values: https://plausible.io/docs/stats-api#time-dimensions |
metrics |
Defaults to "visits". See official documentation on metrics of API version 1 for more details. |
A data frame.
## Not run: pa_get_aggregate(period = "6mo") ## End(Not run)## Not run: pa_get_aggregate(period = "6mo") ## End(Not run)
Get a breakdown of stats by a given property
pa_get_breakdown( period = "30d", property = "event:page", metrics = "visitors", limit = 100, filters = NULL )pa_get_breakdown( period = "30d", property = "event:page", metrics = "visitors", limit = 100, filters = NULL )
period |
Period to include in the analysis, defaults to "30d". See examples as well as the time-dimensions section of the official documentation for valid values. |
property |
Property to break down the stats by. For a full list of available properties, see the properties section of the official documentation. |
metrics |
Default to "visitors". Can be set, for example, to
|
limit |
Limit the number of results. Maximum value is 1000. Defaults to 100. If you want to get more than 1000 results, you can make multiple requests and paginate the results by specifying the page parameter (e.g. make the same request with page=1, then page=2, etc) |
filters |
Optional, defaults to NULL. If given, it must be given in the form "visit:browser==Firefox;visit:country==FR", or as a named vector (see examples). Use ";" to separate multiple filtering criteria. For details, see the API documentation on filtering for reference. |
A data frame.
## Not run: pa_get_breakdown(period = "30d", property = "event:page") ## With filters, e.g. to see all referrers to the given url: pa_get_breakdown( period = "30d", property = "visit:referrer", filters = list(`event:page` = "/berlin/") ) ## End(Not run)## Not run: pa_get_breakdown(period = "30d", property = "event:page") ## With filters, e.g. to see all referrers to the given url: pa_get_breakdown( period = "30d", property = "visit:referrer", filters = list(`event:page` = "/berlin/") ) ## End(Not run)
This facilitates caching daily stats.
pa_get_breakdown_by_date( property = "event:page", metric = "visitors", start_date = Sys.Date() - 8, end_date = Sys.Date() - 1, limit = 1000, cache = TRUE, wait = 0.1 )pa_get_breakdown_by_date( property = "event:page", metric = "visitors", start_date = Sys.Date() - 8, end_date = Sys.Date() - 1, limit = 1000, cache = TRUE, wait = 0.1 )
start_date |
Earliest day to include in the output. Defaults to 8 days
ago in order to include the last full week of data. Date is expected in the
format |
end_date |
Most recent day to include in the output. Defaults to
yesterday in order to include the last full week of data. Date is expected
in the format |
limit |
Defaults to 1000, to reduce the need for pagination, which is currently not supported. |
cache |
Defaults to |
wait |
Numeric, defaults to 0.1. As this function is likely to make a high number of requests to the API, a small pause is added between each request to reduce load on the servers. description |
However, the same data can mostly be retrieved more efficiently using the
timeseries endpoint, setting the optional interval parameter to date (not
yet integrated in the pa_get_timeseries() function).
A data frame with three columns: date, property, and metric.
## Not run: pa_get_breakdown_by_date() pa_get_breakdown_by_date(property = "visit:source") ## End(Not run)## Not run: pa_get_breakdown_by_date() pa_get_breakdown_by_date(property = "visit:source") ## End(Not run)
Get aggregated stats for a given page
pa_get_page_aggregate(page, period = "30d", limit = 100)pa_get_page_aggregate(page, period = "30d", limit = 100)
period |
Period to include in the analysis, defaults to "30d". See examples as well as the the official documentation for valid time periods values. |
limit |
Limit the number of results. Defaults to 100. |
A data frame.
## Not run: pa_get_page_aggregate(period = "6mo", page = "/") ## End(Not run)## Not run: pa_get_page_aggregate(period = "6mo", page = "/") ## End(Not run)
Get stats for a given page by time period
pa_get_page_timeseries(page, period = "30d", limit = 100)pa_get_page_timeseries(page, period = "30d", limit = 100)
period |
Period to include in the analysis, defaults to "30d". See examples as well as the the official documentation for valid time periods values. |
limit |
Limit the number of results. Defaults to 100. |
A data frame.
## Not run: pa_get_page_timeseries(period = "6mo", page = "/") ## End(Not run)## Not run: pa_get_page_timeseries(period = "6mo", page = "/") ## End(Not run)
This facilitates an operation that is not natively supported by the API.
pa_get_properties_by_date( property1 = "visit:source", property2 = "event:page", start_date = Sys.Date() - 8, end_date = Sys.Date() - 1, property1_to_exclude = character(), limit = 1000, cache = TRUE, only_cached = FALSE, wait = 0.1 )pa_get_properties_by_date( property1 = "visit:source", property2 = "event:page", start_date = Sys.Date() - 8, end_date = Sys.Date() - 1, property1_to_exclude = character(), limit = 1000, cache = TRUE, only_cached = FALSE, wait = 0.1 )
start_date |
Earliest day to include in the output. Defaults to 8 days
ago in order to include the last full week of data. Date is expected in the
format |
end_date |
Most recent day to include in the output. Defaults to
yesterday in order to include the last full week of data. Date is expected
in the format |
property1_to_exclude |
Character vector. Useful to remove irrelevant
iterations. For example, "Direct / None" should mostly be excluded when
using |
limit |
Defaults to 1000, to reduce the need for pagination, which is currently not supported. |
cache |
Defaults to |
only_cached |
Defaults to |
wait |
Numeric, defaults to 0.1. As this function is likely to make a high number of requests to the API, a small pause is added between each request to reduce load on the servers. description |
For example, this allows to retrieve visit:source for each event:page for
each date. As this is not supported by the API, it achieves this result via
repeated calls to the API: first it retrieves all visitors for property1
(e.g. for all visit:source) for a given date, then it iterates through each
of them, and, relying on filters, queries one by one for each item resulting
from this query (e.g. each visit:source found on a given date).
See the relevant discussion on Plausible's repository.
A data frame with four columns: date, property1, property2, and
visitors.
## Not run: pa_get_properties_by_date() pa_get_properties_by_date(property1 = "visit:referrer") ## End(Not run)## Not run: pa_get_properties_by_date() pa_get_properties_by_date(property1 = "visit:referrer") ## End(Not run)
It allows to override specific settings, without changing environment variables.
pa_get_settings(base_url = NULL, site_id = NULL, key = NULL)pa_get_settings(base_url = NULL, site_id = NULL, key = NULL)
base_url |
The base URL of the Plausible instance. Set to https://plausible.io/ - or to your own domain for self-hosted Plausible. |
site_id |
Corresponds to the domain of your website. |
key |
A character string used for authentication. Can be retrieved from the user settings in Plausible Analytics. |
A list (invisibly).
pa_set( base_url = "https://plausible.io/", site_id = "example.com", key = "actual_key_here" ) pa_get_settings() ## It allows to override specific settings, without changing environment variables pa_get_settings(site_id = "notexample.com")pa_set( base_url = "https://plausible.io/", site_id = "example.com", key = "actual_key_here" ) pa_get_settings() ## It allows to override specific settings, without changing environment variables pa_get_settings(site_id = "notexample.com")
Get time series
pa_get_timeseries(period = "30d")pa_get_timeseries(period = "30d")
period |
Period to include in the analysis, defaults to "30d". See examples as well as the the official documentation for valid time periods values. |
A data frame.
## Not run: pa_get_timeseries(period = "6mo") pa_get_timeseries(period = "30d") pa_get_timeseries(period = "custom&date=2021-06-01,2021-06-07") ## End(Not run)## Not run: pa_get_timeseries(period = "6mo") pa_get_timeseries(period = "30d") pa_get_timeseries(period = "custom&date=2021-06-01,2021-06-07") ## End(Not run)
Get most visited pages for a given period
pa_get_top_pages(period = "30d", limit = 100)pa_get_top_pages(period = "30d", limit = 100)
period |
Period to include in the analysis, defaults to |
limit |
Limit the number of results. Defaults to 100. |
A data frame.
## Not run: pa_get_top_pages(period = "6mo") ## End(Not run)## Not run: pa_get_top_pages(period = "6mo") ## End(Not run)
Set API key for the current session
pa_set(base_url = NULL, site_id = NULL, key = NULL)pa_set(base_url = NULL, site_id = NULL, key = NULL)
base_url |
The base URL of the Plausible instance. Set to https://plausible.io/ - or to your own domain for self-hosted Plausible. |
site_id |
Corresponds to the domain of your website. |
key |
A character string used for authentication. Can be retrieved from the user settings in Plausible Analytics. |
Invisibly returns input as list.
pa_set( base_url = "https://plausible.io/", site_id = "example.com", key = "actual_key_here" )pa_set( base_url = "https://plausible.io/", site_id = "example.com", key = "actual_key_here" )
Transform API response from list to data frame
pa2_df(response_l, long = FALSE)pa2_df(response_l, long = FALSE)
response_l |
A list based on a Plausible API v2 response, typically
retrieved with |
long |
Logical, defaults to FALSE. If FALSE, the default, the value for each metric is returned in its own column. If TRUE, the data frame is returned in the long format. |
A data frame.
## Not run: pa2_get( date_range = "7d", metrics = c("visits", "pageviews"), dimensions = c("time:day"), pagination = list(limit = 10) ) |> pa2_df(long = TRUE) pa2_get( date_range = "7d", metrics = c("visits", "pageviews"), dimensions = c("time:day"), pagination = list(limit = 10) ) |> pa2_df(long = FALSE) ## End(Not run)## Not run: pa2_get( date_range = "7d", metrics = c("visits", "pageviews"), dimensions = c("time:day"), pagination = list(limit = 10) ) |> pa2_df(long = TRUE) pa2_get( date_range = "7d", metrics = c("visits", "pageviews"), dimensions = c("time:day"), pagination = list(limit = 10) ) |> pa2_df(long = FALSE) ## End(Not run)
For details, consult the official documentation.
pa2_get( date_range = "30d", metrics = "visits", dimensions = NULL, filters = NULL, order_by = NULL, include = NULL, pagination = NULL, site_id = NULL )pa2_get( date_range = "30d", metrics = "visits", dimensions = NULL, filters = NULL, order_by = NULL, include = NULL, pagination = NULL, site_id = NULL )
date_range |
A character vector of length 1, or a list of two dates or
times. Valid values include: |
metrics |
Defaults to "visits". See official documentation on metrics in API version 2 for more details. |
dimensions |
Optional, defaults to |
filters |
Optional, defaults to |
order_by |
Optional, defaults to |
include |
Optional, defaults to |
pagination |
Optional, defaults to |
site_id |
Corresponds to the domain of your website. |
A named list, with three elements: results, meta, and query.
## Not run: pa2_get( date_range = "30d", metrics = "visits" ) pa2_get( date_range = "7d", metrics = c("visits", "visitors"), dimensions = c("time:day", "event:page"), include = list(total_rows = TRUE) ) ## Customise number of results and explore pagination pa2_get( date_range = "7d", metrics = c("visits", "visitors"), dimensions = c("time:day", "event:page"), include = list(total_rows = TRUE), pagination = list(limit = 10, offset = 0) # increase offset to get following pages ) ## Date range between dates pa2_get( date_range = list(Sys.Date() - 8, Sys.Date() - 1), metrics = c("visits", "visitors"), dimensions = c("time:day", "event:page") ) ## Notice that filters require nested lists, even if they are simple pa2_get( date_range = list(Sys.Date() - 2, Sys.Date() - 1), metrics = c("visits", "visitors"), dimensions = c("time:day", "event:page"), include = list(total_rows = TRUE), filters = list( list( "is_not", "visit:country_name", list( "China" ) ) ) ) ## End(Not run)## Not run: pa2_get( date_range = "30d", metrics = "visits" ) pa2_get( date_range = "7d", metrics = c("visits", "visitors"), dimensions = c("time:day", "event:page"), include = list(total_rows = TRUE) ) ## Customise number of results and explore pagination pa2_get( date_range = "7d", metrics = c("visits", "visitors"), dimensions = c("time:day", "event:page"), include = list(total_rows = TRUE), pagination = list(limit = 10, offset = 0) # increase offset to get following pages ) ## Date range between dates pa2_get( date_range = list(Sys.Date() - 8, Sys.Date() - 1), metrics = c("visits", "visitors"), dimensions = c("time:day", "event:page") ) ## Notice that filters require nested lists, even if they are simple pa2_get( date_range = list(Sys.Date() - 2, Sys.Date() - 1), metrics = c("visits", "visitors"), dimensions = c("time:day", "event:page"), include = list(total_rows = TRUE), filters = list( list( "is_not", "visit:country_name", list( "China" ) ) ) ) ## End(Not run)