mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-07-23 14:23:39 -04:00
Set up tracking of site search for Google Analytics
This commit is contained in:
@@ -208,8 +208,8 @@
|
||||
{% include "footer.html" %}
|
||||
</footer>
|
||||
{% endblock %}
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<!-- Search results -->
|
||||
<div class="results" role="status" aria-live="polite">
|
||||
@@ -251,13 +251,22 @@
|
||||
/* Track outbound links */
|
||||
var buttons = document.querySelectorAll('a');
|
||||
Array.prototype.map.call(buttons, function(item) {
|
||||
if (item.host != window.location.host) {
|
||||
if (item.host != document.location.host) {
|
||||
item.addEventListener('click', function() {
|
||||
var action = item.getAttribute('data-action') || 'follow';
|
||||
ga('send', 'event', 'outbound', action, item.href);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/* Register handler to log search on blur */
|
||||
var query = document.querySelector('.query');
|
||||
query.addEventListener('blur', function() {
|
||||
if (this.value) {
|
||||
var path = document.location.pathname;
|
||||
ga('send', 'pageview', path + '?q=' + this.value);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user