feat: Dynamically inject analytics into head of sites
All checks were successful
Build Docker / Build SLDs Image (push) Successful in 19s
Build Docker / Build Main Image (push) Successful in 21s

This commit is contained in:
Nathan Woodburn 2023-12-13 15:04:28 +11:00
parent bb10db2f00
commit 09ef9857d9
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -142,6 +142,27 @@ def get_template(template,hide_addresses=False):
except:
pass
# If <!-- Matomo --> comment doesn't exist, add tracking to end of head
if 'Matomo' not in str(soup):
head = soup.find("head")
head.append(BeautifulSoup("""
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://analytics.woodburn.au/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '7']);
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 -->
""", 'html.parser'))
return str(soup)
def calculate_contrast_ratio(color1, color2):