1

I have a javascript web application and I want to know if users are returning to it or just visiting it one time. Is there some identifier for each device (computer, phone, etc.) that I can record, so that I can check if a user has made repeated visits?

I do not want users to have to manually provide any information to me (like an email).

I can't record their IP address because that is not unique per device.

Lahav
  • 781
  • 10
  • 22
  • I could be wrong, the only truly unique identifier I know of for a machine would be a MAC address, which isn't accessible for security reasons [see this post](https://stackoverflow.com/questions/3385/mac-addresses-in-javascript), you COULD generate a random value (like a UUID or something) and save it as a cookie then check that way... but you run the risk of a user deleting said cookie (doesn't have to be a UUID if you don't need to differentiate between users) – Patrick Barr Jun 08 '17 at 20:33
  • Set a cookie on their computer. Will only work if the user allows cookies. – Andreas Jun 08 '17 at 20:34
  • Google analytics also keeps track of users but I believe they too use cookies – Andreas Jun 08 '17 at 20:36
  • Easiest: cookies, difficultest: based on ip, browser and ping – Jonas Wilms Jun 08 '17 at 20:36

2 Answers2

0

you can use cookies, or localStorage

Peter
  • 1,742
  • 15
  • 26
0

Probably the most popular way (without getting into creepy, borderline unethical types of big data tracking) is to simply store a cookie on their first visit. When they come back, check if they have the cookie. If they do, they've visited before. If not, they're either coming for the first time or have cleared their cookies (which would only be a small number of users).

Setting the cookie:

document.cookie = 'visited=1';

Reading the cookie:

Boolean(document.cookie.split(';').filter(cookie => cookie === 'visited=1').length);

When you set a cookie, you just set it on document.cookie. When you read them back, it gives you all cookies for the current domain, and you have to split them apart and check yourself.

There are more sophisticated, big data analyzing types of ways, but they are borderline unethical and illegal, not to mention super creepy and scumming, so I won't be diving into those methods. ;)

samanime
  • 25,408
  • 15
  • 90
  • 139