-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial support for Matomo data collection via Paella player (#1099)
This add the ability to configure Paella to send statistical data to a Matomo instance. Closes #1038 There is additional support planned, with Tobira sending events to Matomo as well. But this is not part of this PR. See the added docs and commit messages for more information.
- Loading branch information
Showing
16 changed files
with
224 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use hyper::Uri; | ||
|
||
use crate::prelude::*; | ||
|
||
|
||
#[derive(Debug, confique::Config)] | ||
pub(crate) struct MatomoConfig { | ||
/// URL of your Matomo server. Example: "https://matomo.myuni.edu/matomo/". | ||
/// | ||
/// Note: Adding `matomo.js` to the URL configured here should result in a | ||
/// URL to a publicly accessible JS file. | ||
#[config(deserialize_with = deserialize_server)] | ||
pub(crate) server: Option<Uri>, | ||
|
||
/// Matomo site ID, e.g. `side_id = "1"` | ||
pub(crate) site_id: Option<String>, | ||
} | ||
|
||
impl MatomoConfig { | ||
/// Returns the JS code for initializing the Matomo tracking or `None` if | ||
/// Matomo is not configured. | ||
pub(crate) fn js_code(&self) -> Option<String> { | ||
let (Some(server), Some(site_id)) = (&self.server, &self.site_id) else { | ||
return None; | ||
}; | ||
|
||
let out = format!(r#" | ||
// Matomo tracking code | ||
var _paq = window._paq = window._paq || []; | ||
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */ | ||
_paq.push(['trackPageView']); | ||
_paq.push(['enableLinkTracking']); | ||
(function() {{ | ||
var u="{server}"; | ||
_paq.push(['setTrackerUrl', u+'matomo.php']); | ||
_paq.push(['setSiteId', '{site_id}']); | ||
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; | ||
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); | ||
}})(); | ||
"#); | ||
|
||
// Fix indentation, super duper important. | ||
Some(out.replace("\n ", "\n ")) | ||
} | ||
} | ||
|
||
fn deserialize_server<'de, D>(deserializer: D) -> Result<Uri, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
use serde::{Deserialize, de::Error}; | ||
|
||
let uri: Uri = String::deserialize(deserializer)? | ||
.parse() | ||
.map_err(|e| D::Error::custom(format!("invalid URL: {e}")))?; | ||
|
||
Ok(uri) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::prelude::*; | ||
|
||
#[derive(Debug, confique::Config)] | ||
pub(crate) struct PlayerConfig { | ||
/// Additional Paella plugin configuration (JSON object). This is merged | ||
/// into the `plugins` object in the Tobira-internal Paella config. | ||
/// Warning: this could break Paella if used incorrectly. This is mostly | ||
/// intended to configure user tracking, e.g.: | ||
/// | ||
/// ``` | ||
/// paella_plugin_config = """{ | ||
/// "es.upv.paella.userEventTracker": { ... }, | ||
/// "es.upv.paella.matomo.userTrackingDataPlugin": { ... } | ||
/// }""" | ||
/// ``` | ||
#[config(default = "{}", deserialize_with = deserialize_paella_plugin_config)] | ||
pub paella_plugin_config: serde_json::Map<String, serde_json::Value>, | ||
} | ||
|
||
fn deserialize_paella_plugin_config<'de, D>( | ||
deserializer: D, | ||
) -> Result<serde_json::Map<String, serde_json::Value>, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
use serde::{Deserialize, de::Error}; | ||
|
||
let s = String::deserialize(deserializer)?; | ||
serde_json::from_str(&s) | ||
.map_err(|e| D::Error::custom(format!("invalid JSON object: {e}"))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
sidebar_position: 11 | ||
--- | ||
|
||
# Matomo | ||
|
||
To collect statistical data about Tobira usage, you can use [Matomo](https://matomo.org/). | ||
Tobira's Matomo integration is still very basic and currently only allows you to configure the Paella player to send events. | ||
Tobira itself does not yet send any data. | ||
|
||
## Privacy, GDPR and consent | ||
|
||
Before collecting any data, you have to understand the legal situation of doing so. | ||
There are two resources on this topic by Matomo: | ||
- [Lawful basis for processing personal data under GDPR with Matomo](https://matomo.org/blog/2018/04/lawful-basis-for-processing-personal-data-under-gdpr-with-matomo/) | ||
- [How to not process any personally identifiable information (PII) with Matomo, and what it means for you](https://matomo.org/blog/2018/04/how-to-not-process-any-personal-data-with-matomo-and-what-it-means-for-you/) | ||
|
||
The best way to comply with the law is to make sure the data you collect is no "personal data"/"personally identifiable information". | ||
If you must, you can instead comply with the law by asking for the user's consent. | ||
To do that, check the `general.initial_consent` value in configuration file. | ||
|
||
|
||
## Configuration | ||
|
||
First, you have to tell Tobira about your Matomo server so that the correct tracking code can be loaded. | ||
|
||
```toml | ||
[matomo] | ||
server = "https://matomo.test.tobira.ethz.ch/matomo/" | ||
site_id = "1" | ||
``` | ||
|
||
This alone won't make anything interesting happen though, as Tobira itself does not yet send any events to Matomo itself. | ||
In order to get anything out of this, you have to configure Paella to do so. | ||
|
||
```toml | ||
[player] | ||
paella_plugin_config = """{ | ||
"es.upv.paella.userEventTracker": { | ||
"enabled": true, | ||
"context": "userTracking" | ||
}, | ||
"es.upv.paella.matomo.userTrackingDataPlugin": { | ||
"enabled": true, | ||
"context": ["userTracking"], | ||
"matomoGlobalLoaded": true, | ||
"events": { | ||
"category": "PaellaPlayer", | ||
"action": "${event}", | ||
"name": "${videoId}" | ||
} | ||
} | ||
}""" | ||
``` | ||
|
||
See [the Paella docs](https://github.com/polimediaupv/paella-user-tracking?tab=readme-ov-file#matomo-user-tracking-data-plugin) for more information on configuring this. | ||
Note though that `matomoGlobalLoaded` should be `true`. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ const query = graphql` | |
title | ||
created | ||
isLive | ||
opencastId | ||
syncedData { | ||
updated | ||
startTime | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare module "paella-user-tracking" { | ||
export default function (): __WebpackModuleApi.RequireContext; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters