Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/gohugoioTheme2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'layouts/partials/gtag.html')
-rw-r--r--layouts/partials/gtag.html25
1 files changed, 25 insertions, 0 deletions
diff --git a/layouts/partials/gtag.html b/layouts/partials/gtag.html
new file mode 100644
index 0000000..fe9f4d2
--- /dev/null
+++ b/layouts/partials/gtag.html
@@ -0,0 +1,25 @@
+{{ with .Site.GoogleAnalytics }}
+<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());
+
+ {{ $site := $.Site.BaseURL | replaceRE "^https?://(www\\.)?([^/]+).*" "$2" }}
+ gtag('config', '{{ . }}', {'anonymize_ip': true, 'dimension1': '{{ $site }}', 'dimension2': '{{ getenv "BRANCH" }}'});
+
+/**
+* Function that tracks a click on an outbound link in Analytics.
+* Setting the transport method to 'beacon' lets the hit be sent
+* using 'navigator.sendBeacon' in browser that support it.
+*/
+var trackOutboundLink = function(id, url) {
+ gtag('event', 'click', {
+ 'event_category': 'outbound',
+ 'event_label': id,
+ 'transport_type': 'beacon'
+ });
+}
+
+</script>
+{{ end }}