Detect Return Users with Local Storage

A nifty feature to have available on any website is being able to differentiate between, new and returning users. Such a feature opens doors to providing more personalised features on your website or application. Previously you could do this using cookies, but that involves working with a server. Luckily, modern day javascript offers a really simple and easy alternative that can be executed completely on the client side. Take a look at the demo below:

See the Pen pLVarY by My Weekend Project (@MWP) on CodePen.

If the output is New User, try refreshing this page. The output, should say "Return user", cool right? Let's break down what's happening here:

  • First of all we check to see if the browser supports local storage
  • so then we read the stored data to determine if there's a boolean set called "return_user".
  • "return_user" is true, we output "Return User" else we output that the user is visiting for the first time.

That's it! Easy right? A simple way to detect returning users on your site . If you found this helpful be sure to share!

Before we get started...

This website uses cookies to ensure you get the best possible experience. By clicking the button below you give direct consent to receive cookies from this site.

*You can change your mind at any time. Learn More