From 46d06c1c1df6a371cbdb35ecbe2db2e0871997c3 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Sat, 27 Aug 2022 11:39:17 +0200 Subject: [PATCH] Fixed feedback widget not shown when using instant loading --- .../integrations/analytics/google.html | 4 +-- .../integrations/analytics/google.html | 34 +++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/material/partials/integrations/analytics/google.html b/material/partials/integrations/analytics/google.html index e35fd4eb2..b7ea49478 100644 --- a/material/partials/integrations/analytics/google.html +++ b/material/partials/integrations/analytics/google.html @@ -5,7 +5,7 @@ {% set property = config.extra.analytics.property | d("", true) %} {% endif %} {% if property.startswith("G-") %} - + {% elif property.startswith("UA-") %} - + {% endif %} diff --git a/src/partials/integrations/analytics/google.html b/src/partials/integrations/analytics/google.html index 41174b7b9..8a55ff06b 100644 --- a/src/partials/integrations/analytics/google.html +++ b/src/partials/integrations/analytics/google.html @@ -49,8 +49,12 @@ } /* Set up feedback, i.e. "Was this page helpful?" */ - if (document.forms.feedback) { + document$.subscribe(function() { var feedback = document.forms.feedback + if (typeof feedback === "undefined") + return + + /* Send feedback to Google Analytics */ for (var button of feedback.querySelectorAll("[type=submit]")) { button.addEventListener("click", function(ev) { ev.preventDefault() @@ -72,15 +76,14 @@ /* Show feedback */ feedback.hidden = false } - } + }) /* Send page view on location change */ - if (typeof location$ !== "undefined") - location$.subscribe(function(url) { - gtag("config", "{{ property }}", { - page_path: url.pathname - }) + location$.subscribe(function(url) { + gtag("config", "{{ property }}", { + page_path: url.pathname }) + }) }) /* Create script tag */ @@ -123,10 +126,14 @@ } /* Set up feedback, i.e. "Was this page helpful?" */ - if (document.forms.feedback) { + document$.subscribe(function() { var feedback = document.forms.feedback + if (typeof feedback === "undefined") + return + + /* Send feedback to Google Analytics */ for (var button of feedback.querySelectorAll("[type=submit]")) { - button.addEventListener("click", function(ev) { + button.addEventListener("click", function (ev) { ev.preventDefault() /* Retrieve and send data */ @@ -146,13 +153,12 @@ /* Show feedback */ feedback.hidden = false } - } + }) /* Send page view on location change */ - if (typeof location$ !== "undefined") - location$.subscribe(function(url) { - ga("send", "pageview", url.pathname) - }) + location$.subscribe(function(url) { + ga("send", "pageview", url.pathname) + }) }) /* Create script tag */