Move matomo code to seperate script to ease implementing Content-Security-Policy header.
This commit is contained in:
parent
c6e71c2a88
commit
91106240a9
2 changed files with 16 additions and 12 deletions
13
assets/js/tracking.js
Normal file
13
assets/js/tracking.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* @file
|
||||
* A JavaScript file for matomo analytic tracking.
|
||||
*/
|
||||
|
||||
var idSite = {{ .Site.Params.piwikSiteID }};
|
||||
var matomoTrackingApiUrl = 'https://{{ .Site.Params.piwikTrackerUrl }}/matomo.php';
|
||||
|
||||
var _paq = window._paq || [];
|
||||
_paq.push(['setTrackerUrl', matomoTrackingApiUrl]);
|
||||
_paq.push(['setSiteId', idSite]);
|
||||
_paq.push(['trackPageView']);
|
||||
_paq.push(['enableLinkTracking']);
|
||||
|
|
@ -1,14 +1,5 @@
|
|||
{{ if and .Site.Params.piwikTrackerUrl .Site.Params.piwikSiteID -}}
|
||||
<script>
|
||||
var _paq = window._paq || [];
|
||||
_paq.push(['trackPageView']);
|
||||
_paq.push(['enableLinkTracking']);
|
||||
(function() {
|
||||
var u="https://{{ .Site.Params.piwikTrackerUrl }}/";
|
||||
_paq.push(['setTrackerUrl', u+'matomo.php']);
|
||||
_paq.push(['setSiteId', '{{ .Site.Params.piwikSiteID }}']);
|
||||
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
||||
g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
|
||||
})();
|
||||
</script>
|
||||
{{ $script := resources.Get "js/tracking.js" | resources.ExecuteAsTemplate "js/tracking.js" . | minify | fingerprint -}}
|
||||
<script src="{{ $script.RelPermalink }}"></script>
|
||||
<script defer src="https://{{ .Site.Params.piwikTrackerUrl }}/matomo.js"></script>
|
||||
{{ end -}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue