-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
feedback.html
70 lines (69 loc) · 2.45 KB
/
feedback.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{{ $ga := site.Params.marketing.analytics.google_analytics | default "" }}
{{ $show_feedback := .Params.feedback | default true }}
{{ if hugo.IsProduction | and $ga | and $show_feedback }}
<style>
.btn-feedback {
display: inline-block;
}
.btn-feedback-negative {
margin-left: 1em;
}
.feedback--response {
display: none;
margin-top: 1em;
}
.feedback--response__visible {
display: block;
}
</style>
<div class="d-print-none widget--feedback">
<h2 class="feedback--title">{{ i18n "feedback_widget_title" | default "Feedback" }}</h2>
<p class="feedback--question">{{ i18n "feedback_widget_question" | default "Was this page helpful?" }}</p>
<p class="feedback--response feedback--response-positive">
{{ (site.Params.features.feedback.responses.positive | default "🙏") | markdownify | safeHTML }}
</p>
<p class="feedback--response feedback--response-negative">
{{ (site.Params.features.feedback.responses.negative | default "🙏") | markdownify | safeHTML }}
</p>
<button class="btn btn-primary mb-4 btn-feedback btn-feedback-positive">
{{ i18n "feedback_widget_answer_positive" | default "😍 Yes" }}
</button>
<button class="btn btn-primary mb-4 btn-feedback btn-feedback-negative">
{{ i18n "feedback_widget_answer_negative" | default "😡 No" }}
</button>
</div>
<script>
const btnYes = document.querySelector('.btn-feedback-positive');
const btnNo = document.querySelector('.btn-feedback-negative');
const responseYes = document.querySelector('.feedback--response-positive');
const responseNo = document.querySelector('.feedback--response-negative');
const disableButtons = () => {
btnYes.disabled = true;
btnNo.disabled = true;
};
const sendFeedback = (value) => {
if (typeof gtag !== 'function') return;
gtag('event', 'click', {
'event_category': 'page_rating',
'event_label': window.location.pathname,
'value': value,
'transport_type': 'beacon',
'event_callback': function () {
console.debug(`✅ Feedback sent ${value}`);
}
});
};
btnYes.addEventListener('click', () => {
console.debug('Feedback response: 😍');
responseYes.classList.add('feedback--response__visible');
disableButtons();
sendFeedback(1);
});
btnNo.addEventListener('click', () => {
console.debug('Feedback response: 😡');
responseNo.classList.add('feedback--response__visible');
disableButtons();
sendFeedback(0);
});
</script>
{{ end }}