How to handle and gather webpage data after user leaves a site in Javascript?

41 views   Javascript  2021.01.03


I am adding some interactive features to my webpage with Javascript but I want to collect the data about how each page is accessed and used by site visitors (for analytical reasons) How to handle that task by using and applying those events. Please help me with a real-life example.

Answers, ideas and Comments

» 1 idea

gadrawin • 2 weeks ago
Use unload event it will get all your jobs done for you. Briefly call unload event which triggers when user leaves the page. Lets take a real-life example, You built site like Quora and you want to collect data about scrolls, page views, user session (time spent) and more data (window.onunload) will help.

let analyticsData = {

};

window.addEventListener("unload", function() {
  navigator.sendBeacon("/analytics", JSON.stringify(analyticsData));
};
 »

0 



In order to go deep, share any relevant idea or posting solution to some questions, You have to sign in or create a new account if you don't have one. And get Donnekted(connected)




Log in now  Join the Team

This site is for sharing topics, questions, answers, experiences or other contents related to different stuffs, especially technology. For existing users, They can make any topic(post) to discuss about in hope for ideas or any result from other people from different communities. In order to get involved, Get donnekted(connected) by Joining us here!

Posted under this group »
This community is about sharing contents such as questions and answers discussing about Javascript and TypeScript, ES5, ES6


66 people joined this donnektish


Maintain social distancing, to avoid Covid19