1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-24 07:30:12 +01:00

Fixed feedback widget not shown when using instant loading

This commit is contained in:
squidfunk 2022-08-27 11:39:17 +02:00
parent 86378edb60
commit 46d06c1c1d
2 changed files with 22 additions and 16 deletions

View File

@ -5,7 +5,7 @@
{% set property = config.extra.analytics.property | d("", true) %}
{% endif %}
{% if property.startswith("G-") %}
<script id="__analytics">function __md_analytics(){function n(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],n("js",new Date),n("config","{{ property }}"),document.addEventListener("DOMContentLoaded",function(){if(document.forms.search&&document.forms.search.query.addEventListener("blur",function(){this.value&&n("event","search",{search_term:this.value})}),document.forms.feedback){var e,a=document.forms.feedback;for(e of a.querySelectorAll("[type=submit]"))e.addEventListener("click",function(e){e.preventDefault();var t=document.location.pathname,e=this.getAttribute("data-md-value");n("event","feedback",{page:t,data:e}),a.firstElementChild.disabled=!0;e=a.querySelector(".md-feedback__note [data-md-value='"+e+"']");e&&(e.hidden=!1)}),a.hidden=!1}"undefined"!=typeof location$&&location$.subscribe(function(e){n("config","{{ property }}",{page_path:e.pathname})})});var e=document.createElement("script");e.async=!0,e.src="https://www.googletagmanager.com/gtag/js?id={{ property }}",document.getElementById("__analytics").insertAdjacentElement("afterEnd",e)}</script>
<script id="__analytics">function __md_analytics(){function n(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],n("js",new Date),n("config","{{ property }}"),document.addEventListener("DOMContentLoaded",function(){document.forms.search&&document.forms.search.query.addEventListener("blur",function(){this.value&&n("event","search",{search_term:this.value})}),document$.subscribe(function(){var a=document.forms.feedback;if(void 0!==a)for(var e of a.querySelectorAll("[type=submit]"))e.addEventListener("click",function(e){e.preventDefault();var t=document.location.pathname,e=this.getAttribute("data-md-value");n("event","feedback",{page:t,data:e}),a.firstElementChild.disabled=!0;e=a.querySelector(".md-feedback__note [data-md-value='"+e+"']");e&&(e.hidden=!1)}),a.hidden=!1}),location$.subscribe(function(e){n("config","{{ property }}",{page_path:e.pathname})})});var e=document.createElement("script");e.async=!0,e.src="https://www.googletagmanager.com/gtag/js?id={{ property }}",document.getElementById("__analytics").insertAdjacentElement("afterEnd",e)}</script>
{% elif property.startswith("UA-") %}
<script id="__analytics">function __md_analytics(){window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","{{ property }}","auto"),ga("set","anonymizeIp",!0),ga("send","pageview"),document.addEventListener("DOMContentLoaded",function(){if(document.forms.search&&document.forms.search.query.addEventListener("blur",function(){var e;this.value&&(e=document.location.pathname,ga("send","pageview",e+"?q="+this.value))}),document.forms.feedback){var e,a=document.forms.feedback;for(e of a.querySelectorAll("[type=submit]"))e.addEventListener("click",function(e){e.preventDefault();var t=document.location.pathname,e=this.getAttribute("data-md-value");ga("send","event","feedback","click",t,e),a.firstElementChild.disabled=!0;e=a.querySelector(".md-feedback__note [data-md-value='"+e+"']");e&&(e.hidden=!1)}),a.hidden=!1}"undefined"!=typeof location$&&location$.subscribe(function(e){ga("send","pageview",e.pathname)})});var e=document.createElement("script");e.async=!0,e.src="https://www.google-analytics.com/analytics.js",document.getElementById("__analytics").insertAdjacentElement("afterEnd",e)}</script>
<script id="__analytics">function __md_analytics(){window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","{{ property }}","auto"),ga("set","anonymizeIp",!0),ga("send","pageview"),document.addEventListener("DOMContentLoaded",function(){document.forms.search&&document.forms.search.query.addEventListener("blur",function(){var e;this.value&&(e=document.location.pathname,ga("send","pageview",e+"?q="+this.value))}),document$.subscribe(function(){var a=document.forms.feedback;if(void 0!==a)for(var e of a.querySelectorAll("[type=submit]"))e.addEventListener("click",function(e){e.preventDefault();var t=document.location.pathname,e=this.getAttribute("data-md-value");ga("send","event","feedback","click",t,e),a.firstElementChild.disabled=!0;e=a.querySelector(".md-feedback__note [data-md-value='"+e+"']");e&&(e.hidden=!1)}),a.hidden=!1}),location$.subscribe(function(e){ga("send","pageview",e.pathname)})});var e=document.createElement("script");e.async=!0,e.src="https://www.google-analytics.com/analytics.js",document.getElementById("__analytics").insertAdjacentElement("afterEnd",e)}</script>
{% endif %}

View File

@ -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 */