Skip to content

Commit

Permalink
Add feedback buttons to pages
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Abraham <[email protected]>
Signed-off-by: Justin Rivera <[email protected]>
  • Loading branch information
cjyabraham authored and jriv01 committed Dec 12, 2023
1 parent cc1b50b commit 5cd37f6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions website/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ sidebar_search_disable = false
[params.ui.feedback]
enable = true
# The responses that the user sees after clicking "yes" (the page was helpful) or "no" (the page was not helpful).
yes = 'Glad to hear it! Please <a href="https://github.com/cncf/cartografos/issues/new">tell us how we can improve</a>.'
no = 'Sorry to hear that. Please <a href="https://github.com/cncf/cartografos/issues/new">tell us how we can improve</a>.'
yes = 'Glad to hear it! Please <a href="https://github.com/cncf/tag-security/issues/new">tell us how we can improve</a>.'
no = 'Sorry to hear that. Please <a href="https://github.com/cncf/tag-security/issues/new">tell us how we can improve</a>.'

# Adds a reading time to the top of each doc.
# If you want this feature, but occasionally need to remove the Reading time from a single page,
Expand Down
17 changes: 17 additions & 0 deletions website/layouts/_default/content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="td-content">
<h1>{{ .Title }}</h1>
{{ with .Params.description }}<div class="lead">{{ . | markdownify }}</div>{{ end }}
{{ if (and (not .Params.hide_readingtime) (.Site.Params.ui.readingtime.enable)) }}
{{ partial "reading-time.html" . }}
{{ end }}
{{ .Content }}
{{ if (and (not .Params.hide_feedback) (.Site.Params.ui.feedback.enable)) }}
{{ partial "feedback.html" .Site.Params.ui.feedback }}
<br />
{{ end }}
{{ if (.Site.Params.DisqusShortname) }}
<br />
{{ partial "disqus-comment.html" . }}
{{ end }}
<div class="text-muted mt-5 pt-3 border-top">{{ partial "page-meta-lastmod.html" . }}</div>
</div>
19 changes: 8 additions & 11 deletions website/layouts/partials/feedback.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,18 @@ <h2 class="feedback--title">Feedback</h2>
noButton.disabled = true;
};
const sendFeedback = (value) => {
if (typeof ga !== 'function') return;
const args = {
command: 'send',
hitType: 'event',
category: 'Helpful',
action: 'click',
label: window.location.pathname,
value: value
};
ga(args.command, args.hitType, args.category, args.action, args.label, args.value);
if (typeof gtag !== 'function') return;
gtag('event', 'page_helpful', {
'event_category': 'Helpful',
'event_label': window.location.href,
'value': value
});
};
yesButton.addEventListener('click', () => {
yesResponse.classList.add('feedback--response__visible');
disableButtons();
sendFeedback(1);
{{ $maxValue := .max_value | default 100 -}}
sendFeedback({{ $maxValue }});
});
noButton.addEventListener('click', () => {
noResponse.classList.add('feedback--response__visible');
Expand Down

0 comments on commit 5cd37f6

Please sign in to comment.