mirror of
https://github.com/privacyguides/privacyguides.org.git
synced 2025-07-02 17:42:39 +00:00
Bring back feedback buttons (#2481)
Signed-off-by: Daniel Gray <dngray@privacyguides.org>
This commit is contained in:
51
theme/assets/javascripts/feedback.js
Normal file
51
theme/assets/javascripts/feedback.js
Normal file
@ -0,0 +1,51 @@
|
||||
var feedback = document.forms.feedback
|
||||
feedback.hidden = false
|
||||
|
||||
feedback.addEventListener("submit", function(ev) {
|
||||
ev.preventDefault()
|
||||
|
||||
var data = ev.submitter.getAttribute("data-md-value")
|
||||
|
||||
if (data == 1) {
|
||||
var umamiEventName = "feedback-positive"
|
||||
} else if (data == 0) {
|
||||
var umamiEventName = "feedback-negative"
|
||||
}
|
||||
|
||||
var umamiEvent = {
|
||||
payload: {
|
||||
hostname: window.location.hostname,
|
||||
language: navigator.language,
|
||||
referrer: document.referrer,
|
||||
screen: `${window.screen.width}x${window.screen.height}`,
|
||||
url: window.location.pathname,
|
||||
website: '30b92047-7cbb-4800-9815-2e075a293e0a',
|
||||
name: umamiEventName,
|
||||
},
|
||||
type: 'event',
|
||||
};
|
||||
|
||||
// remove trailing slash from path
|
||||
if (umamiEvent.payload.url.slice(-1) === '/') {
|
||||
umamiEvent.payload.url = umamiEvent.payload.url.slice(0, -1);
|
||||
}
|
||||
|
||||
console.log(umamiEvent)
|
||||
|
||||
fetch("https://stats.jonaharagon.net/api/send", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(umamiEvent),
|
||||
headers: {
|
||||
"Content-type": "application/json",
|
||||
}
|
||||
})
|
||||
.then((response) => console.log(response));
|
||||
|
||||
feedback.firstElementChild.disabled = true
|
||||
|
||||
var note = feedback.querySelector(
|
||||
".md-feedback__note [data-md-value='" + data + "']"
|
||||
)
|
||||
if (note)
|
||||
note.hidden = false
|
||||
})
|
@ -22,14 +22,14 @@ function getCookie(cname) {
|
||||
|
||||
var consent = __md_get("__consent")
|
||||
if (!consent) {
|
||||
__md_set("__consent", {"umami":true,"github":true});
|
||||
__md_set("__consent", {"analytics":true,"github":true});
|
||||
if (getCookie('resolution') == '') {
|
||||
const resolution = `${window.screen.width}x${window.screen.height}`;
|
||||
setCookie('resolution', resolution, 30);
|
||||
}
|
||||
}
|
||||
|
||||
if (consent && consent.umami) {
|
||||
if (consent && consent.analytics) {
|
||||
if (getCookie('resolution') == '') {
|
||||
const resolution = `${window.screen.width}x${window.screen.height}`;
|
||||
setCookie('resolution', resolution, 30);
|
||||
|
Reference in New Issue
Block a user