mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-05 14:14:41 +00:00
BREAKING CHANGE Module paths moved to `github.com/HugoBlox/kit` with new names: - core `blox-tailwind` → `blox` - analytics → `analytics` - netlify → `integrations/netlify` - slides (reveal) → `slides` Update go.mod, module.yaml/params, scripts, tests, and v0.11 migration guide accordingly.
43 lines
1.3 KiB
HTML
43 lines
1.3 KiB
HTML
{{ $ga := site.Params.hugoblox.analytics.google.measurement_id | default "" }}
|
|
|
|
{{ if hugo.IsProduction | and $ga }}
|
|
|
|
{{ $gtag_config := cond (site.Params.hugoblox.privacy.anonymize_analytics | default true) "{ 'anonymize_ip': true }" "{}" }}
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id={{$ga}}"></script>
|
|
<script>
|
|
window.dataLayer = window.dataLayer || [];
|
|
|
|
function gtag() {
|
|
dataLayer.push(arguments);
|
|
}
|
|
|
|
function trackOutboundLink(url, target) {
|
|
gtag('event', 'click', {
|
|
'event_category': 'outbound',
|
|
'event_label': url,
|
|
'transport_type': 'beacon',
|
|
'event_callback': function () {
|
|
if (target !== '_blank') {
|
|
document.location = url;
|
|
}
|
|
}
|
|
});
|
|
console.debug("Outbound link clicked: " + url);
|
|
}
|
|
|
|
function onClickCallback(event) {
|
|
if ((event.target.tagName !== 'A') || (event.target.host === window.location.host)) {
|
|
return;
|
|
}
|
|
trackOutboundLink(event.target, event.target.getAttribute('target')); // Send GA event.
|
|
}
|
|
|
|
gtag('js', new Date());
|
|
gtag('config', '{{$ga}}', {{$gtag_config|safeJS}});
|
|
gtag('set', {'cookie_flags': 'SameSite=None;Secure'});
|
|
|
|
// Outbound link tracking.
|
|
document.addEventListener('click', onClickCallback, false);
|
|
</script>
|
|
{{ end }}
|