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. ;)