DEV Community

Cover image for How cookies track you around the Internet
Prajwol Shrestha
Prajwol Shrestha

Posted on

How cookies track you around the Internet

What are cookies?

Cookies are small text files that a website stores in your browser. Cookies are utilized to recall things about sites: your login data, what you have in your shopping basket, what language you prefer. They are generated by websites and remain in your browser until they expire.

Different Types of Cookies

Cookies are classified based on their different characteristics:

  1. Based on their function, cookies are divided as necessary and unnecessary. The necessary cookies are crucial for the functioning of a website, and the unnecessary cookies are the ones that are added additionally by the website and are not so crucial for the functioning of the website.

  2. Based on their source, cookies are divided into first-party and third-party cookies. First-party cookies are set by the site that the user is visiting presently, say, to check whether or not the user is logged in. Whereas third-party cookies are set by other websites that track the user for showing related advertisements.

  3. Based on their span, cookies are classified as persistent and session cookies. Session cookies are set when the user begins a session and are temporary cookies. They terminate once the browser is closed and the session ends. Whereas Persistent cookies stay on the user’s browser for a long period and expire when they reach their expiration period.

Can cookies track you around the internet?

Yes, cookies can be used to invade your privacy and track you around the internet. Most browsers only allow websites to store a maximum of 300 cookies and they cannot store a lot of data. Cookies set by one website cannot be accessed by that other site. And that raises a question, How can cookies be used to track us around the internet, especially if cookies from one website cannot be accessed by another? For instance, How can Facebook track what website we visit?

The whole process starts when you log into Facebook, to remember that you are logged in Facebook, it stores a cookie on your browser, many other websites do the same thing. This cookie is bound to the Facebook domain name, meaning that nobody else besides facebook.com can read what’s inside the cookie. Let’s now assume, you are visiting another website, this website cannot access Facebook cookies and vice versa. But let’s assume that the owner of another website places a Facebook like button on his website, to show this like button your browser has to download some content from the Facebook servers. And when it’s talking to Facebook.com, it sends along with the cookie that Facebook had stored in your browser. Facebook now knows who you are and that you visited this site.

Many other companies also use this technique to track you around the internet. The trick is easy, convince as many as websites to place some of your code in their websites.

What can you do to prevent cookies from tracking you?

You can prevent cookies from tracking you by:

  1. Using browser extensions like Privacy Badger, Ghostery, etc.
  2. Switching to a browser that has built-in privacy protection tools like Brave or safari.
  3. Enable Do Not Track (DNT) on browsers. Even though not all websites respect the DNT setting, it is one feature that users can use.

Top comments (0)