tabi/templates/partials/analytics.html
2025-11-22 18:59:37 +01:00

47 lines
2 KiB
HTML

{% set analytics_service = config.extra.analytics.service %}
{% set analytics_id = config.extra.analytics.id | default(value="") %}
{% set self_hosted_url = config.extra.analytics.self_hosted_url | default(value="") %}
{% if analytics_service == "goatcounter" %}
{# Prevent non-demo sites from using the demo analytics account #}
{% if self_hosted_url == "https://tabi-stats.osc.garden" and config.base_url == "https://welpo.github.io/tabi" or self_hosted_url != "https://tabi-stats.osc.garden" %}
<script async
{% if self_hosted_url %}
data-goatcounter="{{ self_hosted_url ~ '/count' }}"
src="{{ self_hosted_url ~ '/count.js' }}"
{% else %}
data-goatcounter="https://{{ analytics_id }}.goatcounter.com/count"
src="https://gc.zgo.at/count.js"
{% endif %}
></script>
{% endif %}
{% elif analytics_service == "umami" %}
<script async defer
{% if self_hosted_url %}
data-website-id="{{ analytics_id }}"
src="{{ self_hosted_url ~ '/script.js' }}"
{% else %}
data-website-id="{{ analytics_id }}"
src="https://cloud.umami.is/script.js"
{% endif %}
{% if config.extra.analytics.do_not_track %}data-do-not-track="true"{% endif %}>
</script>
{% elif analytics_service == "plausible" %}
{% if analytics_id is matching("^pa-[^\.]+$") %}
{# Use new script available in Plausible 3.1.0 or later #}
<script async src="{% if self_hosted_url %}{{ self_hosted_url ~ '/js/' }}{% else %}https://plausible.io/js/{% endif %}{{ analytics_id }}.js"></script>
<script>
window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};
plausible.init()
</script>
{% else %}
<script
defer
data-domain="{{ analytics_id }}"
src="{% if self_hosted_url %}{{ self_hosted_url ~ '/js/plausible.js' }}{% else %}https://plausible.io/js/script.js{% endif %}"
></script>
{% endif %}
{% endif %}