Google Analytics Event Tracking on Page Exit

时光总嘲笑我的痴心妄想 提交于 2020-01-23 04:12:51

问题


I have a javscript code wich record visitors interaction with the website (like calculating max scroll position, mouse movement in pixels, etc). However, these statistics are valid, only if the user stops interacting with the page. (he leaves, clicks a link, closes the browser, etc)

Is it possible to do a _gaq_push when this happens? If so, how?


回答1:


This should work.

<script>
    window.onbeforeunload = storeData;
    function storeData(){
        _gaq.push(['_trackEvent', 'Visitor Info', 'Scrolling', 'Up', 200, true]);
    }
</script>

However, it's worth noting by pushing an event to Google Analytics, it affects bounce rate calculation, which in your case would cause it to appear that users never bounced. So you must include that last parameter, and set it to true.




回答2:


Have you tried adding your push calls to the window.onunload event?



来源:https://stackoverflow.com/questions/7866666/google-analytics-event-tracking-on-page-exit

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