Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/production/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
# Google Custom Search Engine ID. Remove or comment out to disable search.
gcs_engine_id = "008069654339966445896:nqydaxfpl7a"

# Google Analytics for Knative
# Used in layouts/partials/google_analytics_knative.html to add second tracking ID
googleAnalyticsKnative = "G-YRMNFYE32R"

# Adds a H2 section titled "Feedback" to the bottom of each doc. The responses are sent to Google Analytics as events.
# This feature depends on [services.googleAnalytics] and will be disabled if "services.googleAnalytics.id" is not set.
# If you want this feature, but occasionally need to remove the "Feedback" section from a single page,
Expand Down
53 changes: 53 additions & 0 deletions layouts/partials/google_analytics_knative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!-- custom copy of https://github.com/gohugoio/hugo/blob/ba16a14c6e884e309380610331aff78213f84751/tpl/tplimpl/embedded/templates/google_analytics.html -->
{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
<!-- Modified the following line to use parameter at config/production/params.toml -->
{{- if not $pc.Disable }}{{ with .Site.Params.GoogleAnalyticsKnative -}}
{{ if hasPrefix . "G-"}}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
<script>
{{ template "__ga_js_set_doNotTrack" $ }}
if (!doNotTrack) {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ . }}', { 'anonymize_ip': {{- $pc.AnonymizeIP -}} });
}
</script>
{{ else if hasPrefix . "UA-" }}
<script type="application/javascript">
{{ template "__ga_js_set_doNotTrack" $ }}
if (!doNotTrack) {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
{{- if $pc.UseSessionStorage }}
if (window.sessionStorage) {
var GA_SESSION_STORAGE_KEY = 'ga:clientId';
ga('create', '{{ . }}', {
'storage': 'none',
'clientId': sessionStorage.getItem(GA_SESSION_STORAGE_KEY)
});
ga(function(tracker) {
sessionStorage.setItem(GA_SESSION_STORAGE_KEY, tracker.get('clientId'));
});
}
{{ else }}
ga('create', '{{ . }}', 'auto');
{{ end -}}
{{ if $pc.AnonymizeIP }}ga('set', 'anonymizeIp', true);{{ end }}
ga('send', 'pageview');
}
</script>
{{- end -}}
{{- end }}{{- end -}}

{{- define "__ga_js_set_doNotTrack" -}}{{/* This is also used in the async version. */}}
{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
{{- if not $pc.RespectDoNotTrack -}}
var doNotTrack = false;
{{- else -}}
var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);
var doNotTrack = (dnt == "1" || dnt == "yes");
{{- end -}}
{{- end -}}
4 changes: 4 additions & 0 deletions layouts/partials/hooks/head-end.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<meta name="google-site-verification" content="knbzameE514X1-2MyT4a18Bzc49Jbzdd7NipLte_9A8" />
<!-- Webmaster Central ownership verification using "HTML tag" method -->
<!-- https://www.google.com/webmasters/verification/details?hl=en&siteUrl=http://knative.dev/ -->

{{ template "_internal/google_analytics.html" . }}
{{ partial "google_analytics_knative.html" . }}

<script src="/js/cookie-consent.js"></script>
<script src="/js/script.js"></script>