Last active
September 24, 2020 06:37
-
-
Save alecbw/2db7be664a567ee6cc50b892a05d1e1f to your computer and use it in GitHub Desktop.
A JS script that listens for a series of buttons and makes an API call to increment a counter
This file contains hidden or 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
feedbackButtons = document.getElementsByClassName("feedbackButton") | |
for (i = 0; i < feedbackButtons.length; i++) { | |
feedbackButtons[i].addEventListener("click", trackClick); | |
} | |
function trackClick(event) { | |
var page = window.location.pathname | |
var button = event.target.id | |
fetch('https://foobar.execute-api.us-west-1.amazonaws.com/prod/feedback?page=' + page + '&button=' + button) | |
} | |
// example button: | |
// <button onclick="location.href = 'http://yoursite.com/followup-questions';" id="good" class="feedbackButton" >Good</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment