How do websites track users
Cookie is a small piece of data(key-value pairs). When you visit a website, the server will send a cookie to you to persist in your device. The next time you visit a website, it will send this cookie alone with the request so the server knows if you are a new or returning visitor, and also customize the experiences for you.
The relative new way of tracking and identifying users is based on the new HTML5 feature of
canvas, when your browser load the canvas, it can detect the settings(like font, color) and use these as unique fingerprints of the users.
When you send the request to the server you need to attach your IP address so the server knows where to send the response. So IP can be used to identify user and even geo location.
However if you use a VPN, it can effectively hide your true IP.