You could write a function that does the analytics call and add it to the onsubmit or onclick event in your html. You would have one that runs automatically when the page loads and the onclick or onsubmit one in a function that only gets called when the button is clicked.