Skip to content

Commit

Permalink
Add matomo (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
darioalessandro authored Sep 1, 2024
1 parent 95e9420 commit 0fdb32e
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 10 deletions.
26 changes: 26 additions & 0 deletions helm/matomo/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
mariadb:
enabled: true
auth:
rootPassword: YOUR_ROOT_PASSWORD
database: matomo
username: matomo
password: YOUR_MATOMO_PASSWORD

service:
type: NodePort
port: 80
nodePorts:
http: 32000
https: 32443

ingress:
enabled: true
hostname: matomo.videocall.rs
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/ssl-redirect: "true"
tls:
- hosts:
- matomo.videocall.rs
secretName: matomo-tls

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

17 changes: 16 additions & 1 deletion leptos-website/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ pub fn App() -> impl IntoView {
<Route path="" view=Home ssr=SsrMode::Async/>
</Routes>
</Router>
<script defer data-domain="leptos.dev" src="https://plausible.io/js/script.js"></script>
<!-- Matomo -->
<script>
"var _paq = window._paq = window._paq || [];
_paq.push([\"setDocumentTitle\", document.domain + \"/\" + document.title]);
_paq.push([\"setCookieDomain\", \"*.videocall.rs\"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=\"//matomo.videocall.rs/\";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
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);
})();"
</script>
<!-- End Matomo Code -->
}
}
37 changes: 37 additions & 0 deletions yew-ui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions yew-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ gloo = "0.8.0"
urlencoding = "2.1.2"
getrandom = { version = "0.2.10", features = ["js"] }
wasm-bindgen-futures = "0.4.30"
enum-display = "0.1.4"

[dependencies.web-sys]
version = "0.3.60"
Expand Down
17 changes: 17 additions & 0 deletions yew-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,22 @@
<link data-trunk rel="copy-dir" href="./assets" />
<link data-trunk rel="css" href="./static/tailwind.css" />
<link data-trunk rel="css" href="./static/style.css" />
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(["setCookieDomain", "*.videocall.rs"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//matomo.videocall.rs/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
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);
})();
</script>
<!-- End Matomo Code -->
</head>
</html>
47 changes: 47 additions & 0 deletions yew-ui/src/components/matomo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use gloo_utils::window;
use js_sys::Array;
use js_sys::Reflect;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsValue;
use web_sys::js_sys;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = window)]
static _PAQ: Array;
}

pub struct MatomoTracker {}

impl MatomoTracker {
pub fn new() -> Self {
Self {}
}

pub fn push(&self, args: &JsValue) {
let method: js_sys::Function = js_sys::Reflect::get(&_PAQ, &"push".into()).unwrap().into();
let _ = method.call1(&JsValue::NULL, args);
}

pub fn track_page_view(&self, title: &str, url: &str) {
if !Reflect::has(&window(), &"_paq".into()).unwrap_or(false) {
return;
}
// Create an array with commands
let array = js_sys::Array::new();

array.push(&JsValue::from_str("setCustomUrl"));
array.push(&JsValue::from_str(url));
self.push(&array.into());

let array = js_sys::Array::new();
array.push(&JsValue::from_str("setDocumentTitle"));
array.push(&JsValue::from_str(title));
self.push(&array.into());

let array = js_sys::Array::new();
array.push(&JsValue::from_str("trackPageView"));
// Call the push method with the command array
self.push(&array.into());
}
}
1 change: 1 addition & 0 deletions yew-ui/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod attendants;
pub mod device_selector;
pub mod host;
pub mod icons;
pub mod matomo;
pub mod top_bar;

mod canvas_generator;
Expand Down
10 changes: 6 additions & 4 deletions yew-ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use log::info;
use yew::prelude::*;
#[macro_use]
extern crate lazy_static;
use components::{attendants::AttendantsComponent, top_bar::TopBar};
use components::{attendants::AttendantsComponent, matomo::MatomoTracker, top_bar::TopBar};
use enum_display::EnumDisplay;
use gloo_utils::window;
use yew_router::prelude::*;

use pages::home::Home;
use yew_router::prelude::*;

use crate::constants::ENABLE_OAUTH;

#[derive(Clone, Routable, PartialEq)]
#[derive(Clone, Routable, PartialEq, Debug, EnumDisplay)]
enum Route {
#[at("/")]
Home,
Expand All @@ -39,6 +39,8 @@ enum Route {
}

fn switch(routes: Route) -> Html {
let matomo = MatomoTracker::new();
matomo.track_page_view(&routes.to_string(), &routes.to_string());
match routes {
Route::Home => html! { <Home /> },
Route::Login => html! { <Login/> },
Expand Down

0 comments on commit 0fdb32e

Please sign in to comment.