Set up usage statistics (record views, downloads, etc.).
Enables the collection and aggregation of usage events, such as how
many times a record was viewed or a file was downloaded, so this
data can later be shown to users and curators.
Parameters:
| Name |
Type |
Description |
Default |
enable
|
bool
|
Set to False to turn off collecting new usage
statistics events (for example on a staging/test instance).
Defaults to True.
|
True
|
count_preview_downloads
|
bool
|
Whether a file fetched by the in-page
file previewer counts as a download. True (the default,
same as upstream InvenioRDM) counts it; with False, as on
Zenodo, merely opening a record page that previews a file no
longer inflates the download numbers.
|
True
|
Invenio configuration variables set:
STATS_REGISTER_RECEIVERS - the enable argument above.
RDM_STATS_EXCLUDE_PREVIEW_FILE_DOWNLOAD_EVENTS - the inverse of
count_preview_downloads.
STATS_EVENTS, STATS_AGGREGATIONS, STATS_QUERIES,
STATS_PERMISSION_FACTORY - always set to invenio-app-rdm's
defaults, regardless of enable.
Example
config.configure_stats()
# or on a test instance:
config.configure_stats(enable=False)
Source code in oarepo_config/stats.py
| def configure_stats(
enable: bool = True,
count_preview_downloads: bool = True,
) -> None:
"""Set up usage statistics (record views, downloads, etc.).
Enables the collection and aggregation of usage events, such as how
many times a record was viewed or a file was downloaded, so this
data can later be shown to users and curators.
Args:
enable: Set to `False` to turn off collecting new usage
statistics events (for example on a staging/test instance).
Defaults to `True`.
count_preview_downloads: Whether a file fetched by the in-page
file previewer counts as a download. `True` (the default,
same as upstream InvenioRDM) counts it; with `False`, as on
Zenodo, merely opening a record page that previews a file no
longer inflates the download numbers.
Invenio configuration variables set:
* `STATS_REGISTER_RECEIVERS` - the `enable` argument above.
* `RDM_STATS_EXCLUDE_PREVIEW_FILE_DOWNLOAD_EVENTS` - the inverse of
`count_preview_downloads`.
* `STATS_EVENTS`, `STATS_AGGREGATIONS`, `STATS_QUERIES`,
`STATS_PERMISSION_FACTORY` - always set to `invenio-app-rdm`'s
defaults, regardless of `enable`.
Example:
```python
config.configure_stats()
# or on a test instance:
config.configure_stats(enable=False)
```
"""
STATS_REGISTER_RECEIVERS = enable
from invenio_app_rdm.config import (
STATS_AGGREGATIONS,
STATS_EVENTS,
STATS_PERMISSION_FACTORY,
STATS_QUERIES,
)
set_constants_in_caller(
{
"STATS_REGISTER_RECEIVERS": STATS_REGISTER_RECEIVERS,
"RDM_STATS_EXCLUDE_PREVIEW_FILE_DOWNLOAD_EVENTS": not count_preview_downloads,
"STATS_EVENTS": STATS_EVENTS,
"STATS_AGGREGATIONS": STATS_AGGREGATIONS,
"STATS_QUERIES": STATS_QUERIES,
"STATS_PERMISSION_FACTORY": STATS_PERMISSION_FACTORY,
}
)
|