0

I have a website and I need to know which device is used by my users.

Is there a way to know which device is used by a user on a website?

I know some website like webkay.robinlinus can demonstrate all a browser knows about a user.

The best will be to have the device (iPhone/Android) and the type of iPhone (8/XR,etc..) would be perfect.

Thank you for your advices

AbdurrahmanY
  • 692
  • 8
  • 16
userHG
  • 513
  • 2
  • 21
  • https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent – UnholySheep Aug 21 '20 at 12:23
  • Does this answer your question? [What is the best way to detect a mobile device?](https://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device) – UnholySheep Aug 21 '20 at 12:25

2 Answers2

1

Is there a way to know which device is used by a user on a website?

No, there is not - this is by-design and is to protect the privacy of web users.

What you can do is use long-life'd cookies or use localStorage to track users on your own sites (origins) - though you'll need to ensure you comply with relevant privacy laws in your jurisdiction.

For web-applications accessed from a desktop browser, you can ask your users to manually download and install software that would run a broker-process or other helper utility that runs a webserver on localhost which your web-application could communicate with to identify the client - but be very careful as this may introduce security and privacy risks and vulnerabilities. This approach is used by Dell to allow their website to read your computer's Service-Tag through the web-browser, and by some of Microsoft's support websites as well. But I stress the importance of exercising extreme caution when implementing this because you don't want other websites or applications using your client-side program.

Dai
  • 110,988
  • 21
  • 188
  • 277
0
var x = "User-agent header sent: " + navigator.userAgent;

Send navigator.userAgent in the head tag

This saves the device and browser of the user

For More Reference Check W3schools

https://www.w3schools.com/jsref/prop_nav_useragent.asp

  • 2
    `navigator.userAgent` is not useful anymore: see the latest Chrome developments: https://www.infoq.com/news/2020/03/chrome-phasing-user-agent/ - and `w3schools.com` is not an authoritative source. – Dai Aug 21 '20 at 12:23
  • 1
    Dai, I still use that on all my websites and get the data. Plus I check before I answer and its definitely working . – Sarthak Kuchhal Aug 21 '20 at 12:26
  • It works **right now** - yes, but later this year it will be useless. People have been wanting to kill-off the `User-Agent` header and device-fingerprinting techniques for years though. – Dai Aug 21 '20 at 12:27
  • 1
    use some better documentation sites like https://developer.mozilla.org/en-US/docs/Learn – Ifaruki Aug 21 '20 at 12:29