-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Feedback mechanism that Dapr docs use
- Loading branch information
1 parent
afe033c
commit a4c6bd6
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<style> | ||
.feedback--title { | ||
margin-top: 3rem; | ||
} | ||
.feedback--answer { | ||
display: inline-block; | ||
} | ||
.feedback--answer-no { | ||
margin-left: 1em; | ||
} | ||
.feedback--response { | ||
display: none; | ||
margin-top: 1em; | ||
} | ||
.feedback--response__visible { | ||
display: block; | ||
} | ||
</style> | ||
<div class="d-print-none"> | ||
<h2 class="feedback--title">Feedback</h2> | ||
<p class="feedback--question">Was this page helpful?</p> | ||
<button class="btn btn-primary mb-4 feedback--answer feedback--answer-yes">Yes</button> | ||
<button class="btn btn-primary mb-4 feedback--answer feedback--answer-no">No</button> | ||
<p class="feedback--response feedback--response-yes"> | ||
{{ .yes | safeHTML }} | ||
</p> | ||
<p class="feedback--response feedback--response-no"> | ||
{{ .no | safeHTML }} | ||
</p> | ||
</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 disableButtons = () => { | ||
yesButton.disabled = true; | ||
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); | ||
}; | ||
yesButton.addEventListener('click', () => { | ||
yesResponse.classList.add('feedback--response__visible'); | ||
disableButtons(); | ||
sendFeedback(1); | ||
}); | ||
noButton.addEventListener('click', () => { | ||
noResponse.classList.add('feedback--response__visible'); | ||
disableButtons(); | ||
sendFeedback(0); | ||
}); | ||
</script> |