I am trying to fix a time of site visitor exit. Tried almost everything like beforeunload, visibilitychange for mobile with detecting mobile devices. Nothing work properly especially for mobile devices.
Is there any more effective way for fixation exit of site visitors for mobile and PC?
There is no foolproof way. After all, the device can just be hard-powered-off, the app can be force-terminated at the OS level, etc.
It may not be the events you're using as much as what you're doing in the event handlers. The best you can do in terms of actively sending a notification to your server when the user leaves the page is to send a Beacon from visibilitychange and also (probably) from onunload and/or onbeforeunload.
The advantage to beacons is that they're designed for this use case, whereas if you're doing standard ajax, the browser may well never send the request to your server.