Skip to content

Commit

Permalink
Add plausible analytics (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron authored Apr 18, 2024
1 parent 3ce3f63 commit e92e667
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ edit_uri: "blob/main/docs/src/"
site_url: "https://developmentseed.org/titiler/"

extra:
analytics:
provider: plausible
domain: developmentseed.org/titiler

feedback:
title: Was this page helpful?
ratings:
- icon: material/emoticon-happy-outline
name: This page was helpful
data: good
note: Thanks for your feedback!

- icon: material/emoticon-sad-outline
name: This page could be improved
data: bad
note: Thanks for your feedback!
social:
- icon: "fontawesome/brands/github"
link: "https://github.com/developmentseed"
Expand Down
53 changes: 53 additions & 0 deletions docs/src/overrides/partials/integrations/analytics/plausible.html
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>

0 comments on commit e92e667

Please sign in to comment.