Adjusted analytics implementation

This commit is contained in:
squidfunk 2020-07-23 10:23:32 +02:00
parent 98d1c354df
commit 6295251c24
3 changed files with 33 additions and 1 deletions

View File

@ -51,3 +51,17 @@
</a>
</aside>
{% endblock %}
{% block analytics %}
{{ super() }}
<script>
document.addEventListener("DOMContentLoaded", function() {
document.body.addEventListener("click", ev => {
if (ev.target instanceof HTMLElement) {
var el = ev.target.closest("a[href^=http]")
if (el)
ga('send', 'event', 'outbound', 'click', el.href)
}
})
})
</script>
{% endblock %}

View File

@ -60,9 +60,9 @@ theme:
font:
text: Roboto
code: Roboto Mono
favicon: assets/favicon.png
icon:
logo: logo
favicon: assets/favicon.png
# Plugins
plugins:

View File

@ -91,3 +91,21 @@
</a>
</aside>
{% endblock %}
<!-- Analytics -->
{% block analytics %}
{{ super() }}
<!-- Track external links -->
<script>
document.addEventListener("DOMContentLoaded", function() {
document.body.addEventListener("click", ev => {
if (ev.target instanceof HTMLElement) {
var el = ev.target.closest("a[href^=http]")
if (el)
ga('send', 'event', 'outbound', 'click', el.href)
}
})
})
</script>
{% endblock %}