From 4e04a2ffa91ba9e877d2ab1b06c1dfdf85be0154 Mon Sep 17 00:00:00 2001 From: kagarmoe Date: Tue, 24 Nov 2020 17:09:05 -0800 Subject: [PATCH 1/2] Use GA 4 Signed-off-by: kagarmoe --- config.toml | 1 - themes/docs-new/assets/js/feedback.js | 8 ++++---- themes/docs-new/layouts/_default/data-api.html | 2 +- themes/docs-new/layouts/partials/gtag.html | 11 +++++++++++ themes/docs-new/layouts/partials/head.html | 6 +++--- 5 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 themes/docs-new/layouts/partials/gtag.html diff --git a/config.toml b/config.toml index d67f16ead1..9710b8d379 100644 --- a/config.toml +++ b/config.toml @@ -4,7 +4,6 @@ title = "Chef Web Docs" theme = "docs-new" enableGitInfo = true pluralizeListTitles = false -googleAnalytics = "G-2L57JLVKNZ" # We do redirects via Netlify's _redirects file, generated by Hugo (see "outputs" below). disableAliases = true diff --git a/themes/docs-new/assets/js/feedback.js b/themes/docs-new/assets/js/feedback.js index ad151b68a8..f1bc935033 100644 --- a/themes/docs-new/assets/js/feedback.js +++ b/themes/docs-new/assets/js/feedback.js @@ -16,7 +16,7 @@ function thanksFeedback(button){ const sendFeedback = (value) => { - if (typeof ga !== 'function') return; + if (typeof gtag !== 'function') return; const args = { command: 'send', hitType: 'event', @@ -25,8 +25,8 @@ const sendFeedback = (value) => { label: window.location.pathname, value: value }; - ga(args.command, args.hitType, args.category, args.action, args.label, args.value); - //console.log(args.command, args.hitType, args.category, args.action, args.label, args.value) + gtag(args.command, args.hitType, args.category, args.action, args.label, args.value); + console.log(args.command, args.hitType, args.category, args.action, args.label, args.value) }; @@ -40,4 +40,4 @@ noButton.addEventListener('click', () => { thanksFeedback(noButton); disableButtons(); sendFeedback(0); -}); \ No newline at end of file +}); diff --git a/themes/docs-new/layouts/_default/data-api.html b/themes/docs-new/layouts/_default/data-api.html index 03c9303bb8..61541bc37a 100644 --- a/themes/docs-new/layouts/_default/data-api.html +++ b/themes/docs-new/layouts/_default/data-api.html @@ -8,7 +8,7 @@ {{ if eq (getenv "HUGO_ENV") "production" }} - {{ template "_internal/google_analytics.html" . }} + {{ partial "gtag.html" . }} {{ end }} diff --git a/themes/docs-new/layouts/partials/gtag.html b/themes/docs-new/layouts/partials/gtag.html new file mode 100644 index 0000000000..1c221af99e --- /dev/null +++ b/themes/docs-new/layouts/partials/gtag.html @@ -0,0 +1,11 @@ +{{ with .Site.GoogleAnalytics }} + + + +{{ end }} diff --git a/themes/docs-new/layouts/partials/head.html b/themes/docs-new/layouts/partials/head.html index 098a8505e1..9491712625 100644 --- a/themes/docs-new/layouts/partials/head.html +++ b/themes/docs-new/layouts/partials/head.html @@ -1,4 +1,7 @@ + {{ if eq (getenv "HUGO_ENV") "production" }} + {{ partial "gtag.html" . }} + {{ end }} @@ -8,7 +11,4 @@ {{ $options := (dict "includePaths" (slice "node_modules")) }} {{ $style := resources.Get "sass/main.scss" | resources.ToCSS $options }} - {{ if eq (getenv "HUGO_ENV") "production" }} - {{ template "_internal/google_analytics.html" . }} - {{ end }} From 74b81eb4e1612898d558d4bbf5cbb08d78f6b869 Mon Sep 17 00:00:00 2001 From: kagarmoe Date: Tue, 24 Nov 2020 17:31:01 -0800 Subject: [PATCH 2/2] remove the send method from feedback Signed-off-by: kagarmoe --- themes/docs-new/assets/js/feedback.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/themes/docs-new/assets/js/feedback.js b/themes/docs-new/assets/js/feedback.js index f1bc935033..0dba3aa58f 100644 --- a/themes/docs-new/assets/js/feedback.js +++ b/themes/docs-new/assets/js/feedback.js @@ -16,17 +16,16 @@ function thanksFeedback(button){ const sendFeedback = (value) => { - if (typeof gtag !== 'function') return; + if (typeof ga !== 'function') return; const args = { - command: 'send', hitType: 'event', category: 'Feedback Buttons', action: 'click', label: window.location.pathname, value: value }; - gtag(args.command, args.hitType, args.category, args.action, args.label, args.value); - console.log(args.command, args.hitType, args.category, args.action, args.label, args.value) + ga(args.command, args.hitType, args.category, args.action, args.label, args.value); + //console.log(args.command, args.hitType, args.category, args.action, args.label, args.value) };