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)
* 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 up tracking of outgoing links and actions for Google Analytics
mkdocs-material-0.1.1 (2016-02-11)

View File

@ -155,9 +155,20 @@
m.parentNode.insertBefore(a,m)
})(window, document,
'script', '//www.google-analytics.com/analytics.js', 'ga');
/* General initialization */
ga('create', '{{ google_analytics[0] }}', '{{ google_analytics[1] }}');
ga('set', 'anonymizeIp', true);
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>
{% endif %}
</body>

View File

@ -239,9 +239,21 @@
})(window, document,
'script', '//www.google-analytics.com/analytics.js', 'ga');
/* General initialization */
ga('create', '{{ google_analytics[0] }}', '{{ google_analytics[1] }}');
ga('set', 'anonymizeIp', true);
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>
{% endif %}
</body>