Cookies 101: How user tracking works

Cookies 101: How user tracking works

cookies

If you are a digital marketer, you’ve likely heard of browser cookies. Cookies help you to track visitors, delineate between multiple page views and single visits, personalize landing pages and allow users to stay logged in.

But how do cookies actually work? and why should I care?

Imagine you’re building a customer data platform (CDP). It’s important to understand cookies because you will be using them to identify your customers and prospects, unify their identities across multiple channels and touchpoints, and deliver better, more personalized experiences.

So, what exactly is a cookie? In plain english: A cookie is a piece of text stored in the browser.

That’s it.

Surely there must be more to it than that?

Well yes, glad you asked. Cookies are sent to your browser when you visit a domain, like google.com or amazon.com. They are used to locally store information about you and your preferences, so that various settings don’t have to be reconfigured each time you visit that domain.

Want to see your own cookies? If you’re reading this in Chrome, simply go to chrome://settings/cookies and voila! You can see all your cookies set for different domains.

Get Treasure Data blogs, news, use cases, and platform capabilities.

Thank you for subscribing to our blog!

How are cookies generated?


Here’s what’s going on in the above animation:

  1. When you type the URL of a Web site into your browser, your browser sends a request to the Web site for the page. For example, if you type the URL http://www.cnn.com, your browser contacts CNN’s server and request its home page.
  2. When the browser does this, it will look on your computer or mobile device for a cookie file that CNN has set. If you just recently cleared your cookies, visit the website for the first time, or are using the browser in the private mode, you will have no cookie set.  
  3. If it finds a CNN cookie, your browser will send your cookie to CNN’s server along with the request for its home page.
  4. CNN’s server reads your request, along with the included cookie and returns a response to your browser.
  5. Your browser then parses the server’s response.
    1. What you see inside your browser is the body of the request.
    2. What you don’t see is the header. This part contains contains metadata (or data that describes information about data) and, if there were cookies for you, instructions on how to set the cookie for CNN.com.

The next time you visit cnn.com, the cookies set in the previous session are shipped with your new request. cnn.com reads your cookie and knows that you are a returning visitor.

If you visit chrome://settings/cookies in Chrome and type in blog.treasuredata.com, you’ll see something like this:
td_cookies

How are my cookies used?

  1. Keeping users logged in: Most web apps like Facebook and Gmail don’t prompt you to log in every time. That’s because they use your previously set cookie to identify you! Of course, it would not be secure to let the cookie persist forever, so they typically set an expiration on the cookie. This way, as long as you are visiting facebook.com regularly, you won’t be asked to log in every time, but if you go on a month-long social media break and come back, Facebook prompts you to log in again because your cookie has expired.
  2. Tracking user sessions and segmenting users: Cookies can be used to identify the visitor uniquely. Thus, it can be used to track each user’s visits even if they haven’t actively identified themselves, i.e., logged into the E-commerce store or web app.
  3. Landing page personalization and A/B testing: Have you wondered how A/B testing services like Optimizely and landing page personalization tools like Instapage show the same variation to the same user every time? You guessed it! Cookies.
    1. By using cookies, sites can keep track of which cookie ID (and which visitor) has seen which variation of their site, so that the next time the same visitor comes back to the site, they can look up that user and make sure to serve the same variant.
    2. Cookies contain information about your visit that you may want the site to remember as well, like your preferred language. This makes your next trip to the site more personalized (like you enjoy watching comedies) and easier (like the ability to add to your shopping cart without logging in)

Cookies also come in handy when it comes to online advertising, which brings us to our next topic…

Cookies 102: How cookies are used in advertising

Learn the latest on how cookies are used for advertising and what’s going to happen when they go away.

Customer Data Types:

Learn about the difference between first party, second party and third party data types as well!

Kiyoto Tamura
Kiyoto Tamura
Kiyoto began his career in quantitative finance before making a transition into the startup world. A math nerd turned software engineer turned developer marketer, he enjoys postmodern literature, statistics, and a good cup of coffee.