Google Analytics - Track Event on Page Exit (Except form submission)

∥☆過路亽.° 提交于 2019-12-08 09:27:08

问题


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:


This worked for me:

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

        $("#formID").submit(function(){
            $(window).unbind('beforeunload');
        });


来源:https://stackoverflow.com/questions/16565433/google-analytics-track-event-on-page-exit-except-form-submission

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!