-
-
Save 4briang/069dd70e05df7fb1b8e03b2b5e6610ad to your computer and use it in GitHub Desktop.
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
| <script type="text/javascript"> | |
| jQuery(document).ready(function($){ | |
| window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; | |
| ga('create', 'UA-xxxxxxxxx-x', 'auto'); // change UA-xxxxxxxxx-x to be your tracking UA. | |
| $("#contact form").each(function() { | |
| var jqForm = $(this); | |
| var jsForm = this; | |
| var action = jqForm.attr("action"); | |
| jqForm.submit(function(event) { | |
| event.preventDefault(); // prevent the form from submitting so we can sent the tracking code, then continue with the submission later. | |
| ga('send', { | |
| hitType: 'event', | |
| eventCategory: 'Form Submits', // add any name for the category | |
| eventAction: 'Form Submitted', // add any name for the action | |
| hitCallback : function () { | |
| console.log("event sent ok"); | |
| } | |
| }); | |
| setTimeout(function() { // now wait 300 milliseconds... | |
| jsForm.submit(); // ... and continue with the form submission | |
| },300); | |
| }); | |
| }); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment