diff --git a/assets/js/index.js b/assets/js/index.js index d182ff9311..7aeba547f8 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -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 \ No newline at end of file diff --git a/layouts/partials/feedback.html b/layouts/partials/feedback.html index 4a58e60f08..a777dbe159 100644 --- a/layouts/partials/feedback.html +++ b/layouts/partials/feedback.html @@ -22,65 +22,3 @@

Thank you!

-