Skip to content

Commit 4dbae30

Browse files
committed
Support the Umami web analytics
Signed-off-by: JmPotato <ghzpotato@gmail.com>
1 parent ec78e03 commit 4dbae30

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ theme = "light"
5353
# google = "G-XXXXXXXXXX"
5454
# https://plausible.io
5555
# plausible = "data.domain"
56+
# https://umami.is
57+
# umami = "8d3fde60-xxxx-xxxx-xxxx-b89e7cic209c"
5658

5759
[twitter_card]
5860
enabled = false

src/config.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,21 @@ impl Object for Giscus {
101101
pub struct Analytics {
102102
google: Option<String>,
103103
plausible: Option<String>,
104+
umami: Option<String>,
104105
}
105106

106107
impl Object for Analytics {
107108
fn get_value(self: &Arc<Self>, key: &Value) -> Option<Value> {
108109
match key.as_str()? {
109110
"google" => Some(Value::from(self.google.clone())),
110111
"plausible" => Some(Value::from(self.plausible.clone())),
112+
"umami" => Some(Value::from(self.umami.clone())),
111113
_ => None,
112114
}
113115
}
114116

115117
fn enumerate(self: &Arc<Self>) -> Enumerator {
116-
Enumerator::Str(&["google", "plausible"])
118+
Enumerator::Str(&["google", "plausible", "umami"])
117119
}
118120
}
119121

@@ -168,6 +170,9 @@ impl Config {
168170
if let Ok(plausible_domain) = std::env::var("PLAUSIBLE_DOMAIN") {
169171
self.analytics.plausible = Some(plausible_domain);
170172
}
173+
if let Ok(umami_id) = std::env::var("UMAMI_ID") {
174+
self.analytics.umami = Some(umami_id);
175+
}
171176
Ok(())
172177
}
173178

templates/layout.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
{% if config.analytics.plausible %}
2323
<script defer data-domain='{{ config.analytics.plausible }}' src="https://plausible.io/js/script.js"></script>
2424
{% endif %}
25+
{% if config.analytics.umami %}
26+
<script defer src="https://cloud.umami.is/script.js" data-website-id="{{ config.analytics.umami }}"></script>
27+
{% endif %}
2528
{% block head %}{% endblock %}
2629
</head>
2730

0 commit comments

Comments
 (0)