1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-28 01:10:58 +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) mkdocs-material-3.x.x (2019-xx-xx)
* Removed Google Tag Manager and reverted to Google Analytics * 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) mkdocs-material-3.3.0 (2019-01-29)

View File

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

View File

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