-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ce3f63
commit e92e667
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
docs/src/overrides/partials/integrations/analytics/plausible.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<script | ||
defer | ||
data-domain="{{ config.extra.analytics.domain }}" | ||
src="https://plausible.io/js/script.outbound-links.js" | ||
></script> | ||
|
||
<!-- Vendored from https://gitlab.com/notpushkin/material-plausible-plugin/ under the BSD 0 clause license. --> | ||
<script> | ||
window.plausible = | ||
window.plausible || | ||
function () { | ||
(window.plausible.q = window.plausible.q || []).push(arguments); | ||
}; | ||
|
||
/* Register event handlers after documented loaded */ | ||
document.addEventListener("DOMContentLoaded", function () { | ||
/* Set up search tracking */ | ||
if (document.forms.search) { | ||
var query = document.forms.search.query; | ||
query.addEventListener("blur", function () { | ||
if (this.value) | ||
plausible("Search", { props: { search_term: this.value } }); | ||
}); | ||
} | ||
|
||
/* Set up feedback, i.e. "Was this page helpful?" */ | ||
document$.subscribe(function () { | ||
var feedback = document.forms.feedback; | ||
if (typeof feedback === "undefined") return; | ||
|
||
/* Send feedback to Plausible */ | ||
for (var button of feedback.querySelectorAll("[type=submit]")) { | ||
button.addEventListener("click", function (ev) { | ||
ev.preventDefault(); | ||
|
||
var page = document.location.pathname; | ||
var value = this.getAttribute("data-md-value"); | ||
plausible(`Feedback: ${value}`); | ||
|
||
/* Disable form and show note, if given */ | ||
feedback.firstElementChild.disabled = true; | ||
var note = feedback.querySelector( | ||
".md-feedback__note [data-md-value='" + value + "']" | ||
); | ||
if (note) note.hidden = false; | ||
}); | ||
|
||
/* Show feedback */ | ||
feedback.hidden = false; | ||
} | ||
}); | ||
}); | ||
</script> |