Google Analytics - Track Event on Page Exit (Excep

2019-06-08 06:13发布

I'm using the following code to track when a user exits a page on my site:

//track on page exit
function storeData(){
    _gaq.push(['_trackEvent', 'Application Form', 'exit-form_application_', '', 4, false]);
}
$(window).on('unload',storeData);

However, I don't want to trigger the event when the form is submitted, therefore how could I prevent this?

1条回答
混吃等死
2楼-- · 2019-06-08 06:46

This worked for me:

$(window).bind('beforeunload', function() {
           _gaq.push(['_trackEvent', 'Application Form', 'exit-form_application_', '', 4, false]);
        });

        $("#formID").submit(function(){
            $(window).unbind('beforeunload');
        });
查看更多
登录 后发表回答