gtm-test-site/themes/papercss-hugo-theme/ga.html
2024-01-23 17:47:24 +03:00

31 lines
987 B
HTML

{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
{{- if not $pc.Disable }}{{ with .Site.Config.Services.GoogleAnalytics.ID -}}
{{ if hasPrefix . "G-"}}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ . }}', {
'anonymize_ip': {{- $pc.AnonymizeIP -}},
'user_properties': {
'analyticsCookieId': getAnalyticsCookieId()
}
});
function getAnalyticsCookieId() {
var cookie = {};
document.cookie.split(';').forEach(function (el) {
var splitCookie = el.split('=');
var key = splitCookie[0].trim();
var value = splitCookie[1];
cookie[key] = value;
});
if ('undefined' === typeof cookie['_ga']) { return '' };
return cookie['_ga'].substring(6);
}
</script>
{{- end }}{{ end -}}
{{- end -}}