googleanalytics / autotrack

Automatic and enhanced Google Analytics tracking for common user interactions on the web.
Other
4.92k stars 560 forks source link

outboundFormTracker clashes with default form submission halting behaviour on IE11 and iOS < v11.3 #230

Open bestdamnfriend opened 6 years ago

bestdamnfriend commented 6 years ago

We are using the analytics.js method on our websites, with outboundFormTracker, and are unable to halt a form's submit() event to do some more processing if we are also using the Outbound Form Tracker. This issue only seems to come to light on IE 11, and earlier versions of iOS (pre 11.3). Unfortunately, a lot of our users need these browsers.

Google code:

<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXXXX-XX', 'auto');
ga('require', 'outboundFormTracker');
ga('require', 'outboundLinkTracker');
ga('send', 'pageview');
</script>
<script async src="https://www.example.com/google/js/analytics.js"></script>
<script async src="https://www.example.com/google/js/autotrack.js"></script>

Form code:

$('form').on('submit', function(e) {
    e.preventDefault();
});

This code works perfectly on most browsers, but is ignored on the aforementioned. return false is also ignored. The only way we can get it to work is to comment out the outboundFormTracker require.