mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Fixed feedback widget not shown when using instant loading
This commit is contained in:
parent
86378edb60
commit
46d06c1c1d
@ -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 %}
|
||||
|
@ -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,10 +76,9 @@
|
||||
/* 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
|
||||
@ -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,10 +153,9 @@
|
||||
/* Show feedback */
|
||||
feedback.hidden = false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
/* Send page view on location change */
|
||||
if (typeof location$ !== "undefined")
|
||||
location$.subscribe(function(url) {
|
||||
ga("send", "pageview", url.pathname)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user