mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-07-23 22:33:42 -04:00
Set up tracking of site search for Google Analytics
This commit is contained in:
@@ -253,7 +253,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
/* Close search and jump to anchor when on same page */
|
||||
var parts = link.href.split('#');
|
||||
if (parts[0] == window.location.href.split('#')[0]) {
|
||||
if (parts[0] == document.location.href.split('#')[0]) {
|
||||
link.addEventListener('click', function(e) {
|
||||
document.body.classList.remove('toggle-search');
|
||||
document.body.classList.remove('locked');
|
||||
|
||||
@@ -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