1

I am trying to implement mixpanel to my website. Is generating a user_id via javascript and storing it on the database is the only or recommended way to generate unique user_id. (consult the database to ensure that id's generated are unique) ?

1 Answers1

0

You absolutely don't want to store an ID for each one of your visitors in your database. If you think about tracking all your visitors, you can generate a unique identifier in Javascript (UUID) and store it in a cookie on the user's browser.

Generate UUID : https://stackoverflow.com/a/8809472/3667380

Work with cookies : http://www.w3schools.com/js/js_cookies.asp
or if you prefer using JQuery : http://plugins.jquery.com/cookie/

However, if you want to track your registered users, you should consider using the database to prevent registered users from cleaning their cookies. By using your database, you ensure that every logged in user will always get the same id.

You can abslolutely use the two options together : UUID and cookies for your unregistered visitors and Database ID (hashed maybe) to identify your registered users.

Community
  • 1
  • 1
TimmyCarbone
  • 405
  • 2
  • 10