Set up tracking of outgoing links and actions for Google Analytics

This commit is contained in:
squidfunk 2016-02-16 13:11:43 +01:00
parent 863e1482dc
commit cec4f1885b
3 changed files with 28 additions and 2 deletions

View File

@ -1,6 +1,9 @@
mkdocs-material-0.x.x (2016-xx-xx) mkdocs-material-0.x.x (2016-xx-xx)
* Fixed webfont delivery problem when hosted in subdirectories
* Added option to configure fonts in mkdocs.yml with fallbacks
* Set download link to latest version if available * Set download link to latest version if available
* Set up tracking of outgoing links and actions for Google Analytics
mkdocs-material-0.1.1 (2016-02-11) mkdocs-material-0.1.1 (2016-02-11)

View File

@ -154,10 +154,21 @@
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g; m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;
m.parentNode.insertBefore(a,m) m.parentNode.insertBefore(a,m)
})(window, document, })(window, document,
'script', '//www.google-analytics.com/analytics.js','ga'); 'script', '//www.google-analytics.com/analytics.js', 'ga');
/* General initialization */
ga('create', '{{ google_analytics[0] }}', '{{ google_analytics[1] }}'); ga('create', '{{ google_analytics[0] }}', '{{ google_analytics[1] }}');
ga('set', 'anonymizeIp', true); ga('set', 'anonymizeIp', true);
ga('send', 'pageview'); ga('send', 'pageview');
/* Track outbound links */
var buttons = document.querySelectorAll('a');
Array.prototype.map.call(buttons, function(item) {
if (item.host != window.location.host) {
item.addEventListener('click', function() {
var action = item.getAttribute('data-action') || 'follow';
ga('send', 'event', 'outbound', action, item.href);
});
}
});
</script> </script>
{% endif %} {% endif %}
</body> </body>

View File

@ -237,11 +237,23 @@
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g; m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;
m.parentNode.insertBefore(a,m) m.parentNode.insertBefore(a,m)
})(window, document, })(window, document,
'script', '//www.google-analytics.com/analytics.js','ga'); 'script', '//www.google-analytics.com/analytics.js', 'ga');
/* General initialization */
ga('create', '{{ google_analytics[0] }}', '{{ google_analytics[1] }}'); ga('create', '{{ google_analytics[0] }}', '{{ google_analytics[1] }}');
ga('set', 'anonymizeIp', true); ga('set', 'anonymizeIp', true);
ga('send', 'pageview'); ga('send', 'pageview');
/* Track outbound links */
var buttons = document.querySelectorAll('a');
Array.prototype.map.call(buttons, function(item) {
if (item.host != window.location.host) {
item.addEventListener('click', function() {
var action = item.getAttribute('data-action') || 'follow';
ga('send', 'event', 'outbound', action, item.href);
});
}
});
</script> </script>
{% endif %} {% endif %}
</body> </body>