The websites would always want to know what are the habits of their user. They would want to know how often a user visit their site, how long they stay and which page they usually view. All this data will allow them optimize their website in order to give the best user experiences to their users. Cookies working mechanism are quite wonderful where it will be send to you by the server of the website to your browser and it will be stored in your hard drive. Most of the cookies will contain the name, value and of course, the expiration dates of the cookie where it will delete itself after it reaches certain time.
E-commerce sites such as Amazon implemented the idea of shopping carts by utilizing the concept of cookies and the cookie contains an ID and enables the site to keep track of the things you have browsed and add to your cart. When you add an item to your cart, the information is stored along with your ID in the database of the site. The site knows what is in your cart when you check out.