| 1 | {{ with site.Config.Services.GoogleAnalytics.ID }} |
| 2 | <script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script> |
| 3 | <script> |
| 4 | window.dataLayer = window.dataLayer || []; |
| 5 | function gtag(){dataLayer.push(arguments);} |
| 6 | gtag('js', new Date()); |
| 7 | |
| 8 | {{ $site := site.BaseURL | replaceRE "^https?://(www\\.)?([^/]+).*" "$2" }} |
| 9 | gtag('config', '{{ . }}', {'anonymize_ip': true, 'dimension1': '{{ $site }}', 'dimension2': '{{ getenv "BRANCH" }}'}); |
| 10 | |
| 11 | /** |
| 12 | * Function that tracks a click on an outbound link in Analytics. |
| 13 | * Setting the transport method to 'beacon' lets the hit be sent |
| 14 | * using 'navigator.sendBeacon' in browser that support it. |
| 15 | */ |
| 16 | var trackOutboundLink = function(id, url) { |
| 17 | gtag('event', 'click', { |
| 18 | 'event_category': 'outbound', |
| 19 | 'event_label': id, |
| 20 | 'transport_type': 'beacon' |
| 21 | }); |
| 22 | } |
| 23 | |
| 24 | </script> |
| 25 | {{ end }} |