How to save multiple partial views on a submit?

How can you create different Google Analytics page views on HTML form submit, depending on values in the form?

  • The problem is the landing page can not be changed depending on the result, so I have to try and record the page views on the form page rather than the form success page.

  • Answer:

    Google Analytics code is just JavaScript, so you can run the trackPageview function, and pass whatever value you like within form validation JavaScript that runs onSubmit. Something like this (assuming you are using the non-asynchronous code, and have already tracked a pageview when the form loaded): <form action="success.php" onsubmit="validateForm()">    <input type="checkbox" id="test" value="1"> </form>. <script> function validateForm(){    if(document.getElementById("test").checked=true){       pageTracker._trackPageview('/form/checked');    }    else{       pageTracker._trackPageview('/form/not-checked');    } } </script>

Mike Wheeler at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.