Skip to content

Commit

Permalink
Update javascript loading for feedback (#3495)
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel authored Sep 23, 2024
1 parent 2bcbf6b commit 7381939
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 62 deletions.
65 changes: 65 additions & 0 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,68 @@ async function initAndClick() {
}

// Userflow END

// Feedback form START
const yesButton = document.querySelector('.feedback--answer-yes');
const noButton = document.querySelector('.feedback--answer-no');
const yesResponse = document.querySelector('.feedback--response-yes');
const noResponse = document.querySelector('.feedback--response-no');
const yesFeedback = document.querySelector('#yes-feedback-text');
const noFeedback = document.querySelector('#no-feedback-text');
const yesSubmitButton = document.querySelector('#yesSubmitButton');
const noSubmitButton = document.querySelector('#noSubmitButton');
const tyResponse = document.querySelector('.feedback-ty');
const feedbackPrompt = document.querySelector('.feedback--prompt')
if (yesButton) {
const sendFeedback = (value) => {
if (typeof gtag !== 'function') return;
const args = {
event_category: 'docs_helpful',
event_label: window.location.pathname,
value: value
};
gtag('event', 'click', args);
};
async function sendFeedbackText (value, text) {
async function logJSONData(data) {
return fetch("https://feedback-43tn7xos3a-uc.a.run.app", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
mode: "cors",
credentials: "omit",
body: JSON.stringify(data)
});
}
let data = {
value: value,
feedback: text,
url: "{{.Permalink}}"
};
let res = await logJSONData(data);
};
yesButton.addEventListener('click', () => {
feedbackPrompt.remove();
yesResponse.classList.add('feedback--response__visible');
sendFeedback(1);
sendFeedbackText(1, "Helpful")
});
noButton.addEventListener('click', () => {
feedbackPrompt.remove();
noResponse.classList.add('feedback--response__visible');
sendFeedback(0);
sendFeedbackText(0, "Not Helpful")
});
yesSubmitButton.addEventListener('click', () => {
yesResponse.remove();
tyResponse.classList.add('feedback--response__visible');
sendFeedbackText(1, yesFeedback.value);
});
noSubmitButton.addEventListener('click', () => {
noResponse.remove();
tyResponse.classList.add('feedback--response__visible');
sendFeedbackText(0, noFeedback.value);
});
}
// Feedback form END
62 changes: 0 additions & 62 deletions layouts/partials/feedback.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,3 @@
</div>
<div class="feedback--response feedback-ty"><p>Thank you!</p></div>
</div>
<script>
const yesButton = document.querySelector('.feedback--answer-yes');
const noButton = document.querySelector('.feedback--answer-no');
const yesResponse = document.querySelector('.feedback--response-yes');
const noResponse = document.querySelector('.feedback--response-no');
const yesFeedback = document.querySelector('#yes-feedback-text');
const noFeedback = document.querySelector('#no-feedback-text');
const yesSubmitButton = document.querySelector('#yesSubmitButton');
const noSubmitButton = document.querySelector('#noSubmitButton');
const tyResponse = document.querySelector('.feedback-ty');
const feedbackPrompt = document.querySelector('.feedback--prompt')
const sendFeedback = (value) => {
if (typeof gtag !== 'function') return;
const args = {
event_category: 'docs_helpful',
event_label: window.location.pathname,
value: value
};
gtag('event', 'click', args);
};
async function sendFeedbackText (value, text) {
async function logJSONData(data) {
return fetch("https://feedback-43tn7xos3a-uc.a.run.app", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
mode: "cors",
credentials: "omit",
body: JSON.stringify(data)
});
}
let data = {
value: value,
feedback: text,
url: "{{.Permalink}}"
};
let res = await logJSONData(data);
};
yesButton.addEventListener('click', () => {
feedbackPrompt.remove();
yesResponse.classList.add('feedback--response__visible');
sendFeedback(1);
sendFeedbackText(1, "Helpful")
});
noButton.addEventListener('click', () => {
feedbackPrompt.remove();
noResponse.classList.add('feedback--response__visible');
sendFeedback(0);
sendFeedbackText(0, "Not Helpful")
});
yesSubmitButton.addEventListener('click', () => {
yesResponse.remove();
tyResponse.classList.add('feedback--response__visible');
sendFeedbackText(1, yesFeedback.value);
});
noSubmitButton.addEventListener('click', () => {
noResponse.remove();
tyResponse.classList.add('feedback--response__visible');
sendFeedbackText(0, noFeedback.value);
});
</script>

0 comments on commit 7381939

Please sign in to comment.