1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-23 23:21:00 +01:00

Fixed loading method for Google Analytics

This commit is contained in:
squidfunk 2019-02-12 18:11:40 +01:00
parent a27372eee3
commit 1b45a24113
3 changed files with 23 additions and 18 deletions

View File

@ -1,6 +1,7 @@
mkdocs-material-3.x.x (2019-xx-xx)
* Removed Google Tag Manager and reverted to Google Analytics
* Removed blocks in partials - Jinja doesn't support them
mkdocs-material-3.3.0 (2019-01-29)

View File

@ -1,22 +1,24 @@
{% set analytics = config.google_analytics %}
<script>
(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");
window.ga = window.ga || function() {
(ga.q = ga.q || []).push(arguments)
}
ga.l = +new Date
/* Setup integration and send page view */
ga("create", "{{ analytics[0] }}", "{{ analytics[1] }}");
ga("send", "pageview");
ga("create", "{{ analytics[0] }}", "{{ analytics[1] }}")
ga("set", "anonymizeIp", true)
ga("send", "pageview")
/* Register handler to log search on blur */
document.addEventListener("DOMContentLoaded", () => {
if (document.forms.search) {
var query = document.forms.search.query;
var query = document.forms.search.query
query.addEventListener("blur", function() {
if (this.value) {
var path = document.location.pathname;
ga("send", "pageview", path + "?q=" + this.value);
ga("send", "pageview", path + "?q=" + this.value)
}
});
})
}
})
</script>
<script async src="https://www.google-analytics.com/analytics.js"></script>

View File

@ -23,25 +23,27 @@
<!-- Google Analytics integration -->
{% set analytics = config.google_analytics %}
<script>
(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");
window.ga = window.ga || function() {
(ga.q = ga.q || []).push(arguments)
}
ga.l = +new Date
/* Setup integration and send page view */
ga("create", "{{ analytics[0] }}", "{{ analytics[1] }}");
ga("send", "pageview");
ga("create", "{{ analytics[0] }}", "{{ analytics[1] }}")
ga("set", "anonymizeIp", true)
ga("send", "pageview")
/* Register handler to log search on blur */
document.addEventListener("DOMContentLoaded", () => {
if (document.forms.search) {
var query = document.forms.search.query;
var query = document.forms.search.query
query.addEventListener("blur", function() {
if (this.value) {
var path = document.location.pathname;
ga("send", "pageview", path + "?q=" + this.value);
ga("send", "pageview", path + "?q=" + this.value)
}
});
})
}
})
</script>
<script async src="https://www.google-analytics.com/analytics.js"></script>