Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do tracking cookies work?

Tags:

cookies

We're trying to figure out how common web tracking software works, like Google Analytics.

We've noticed that much tracking Javascript code from around the web creates multiple cookies on the visitor's system, usually three cookies-- one that expires at the end of the day, one that expires at the end of the week, and one that expires at the end of the month.

Our team has been debating why this is common and we have been tearing our hair out to figure out why one might do this.

The only thing we can think of is performance: this way you can calculate whether a visitor is repeat per day, week, or month without having to do heavy queries on the OLTP database all the time. But we can conceive of ways to make it work anyway.

What are the advantages to creating the tracking cookies in this way, and how do you think they're being used by others?

like image 452
RibaldEddie Avatar asked May 15 '09 23:05

RibaldEddie


People also ask

Should I worry about tracking cookies?

Most of the time, cookies are no big deal. There are a few occasions, though, where you should decline cookies. Don't worry—if you find yourself in a situation where you need to decline or simply want to decline for whatever reason, most websites will work just fine without collecting your information.

What information do tracking cookies collect?

Definition: Tracking cookies are text files set by websites on a user's browser to collect data about the user. They collect data such as clicks, shopping preferences, device specifications, location, and search history.

Can cookies see my browsing history?

A website can track which of its own webpages a user has visited, which probably isn't too surprising. However, a website can also track a user's browsing history across other websites by using third-party cookies, as long as each site loads the cookie from the same domain.


2 Answers

They likely are using cookies in this manner to determine the frequency of visits to the domain. If you visit the site and it notes that you still have the day-expiring cookie, then that is significant in terms of your frequency of visitation. If all you have are the weekly and monthly, then it is clear that you haven't visited the site for at least a day, and last within the week.

There is no rule that says that this is the only way to do this. One could track with a single cookie and store statistics on the server.

like image 150
Demi Avatar answered Sep 28 '22 15:09

Demi


Very interesting question. I think that this is the solution to the hotel problem. Let's take a look from a DB query perspective. If a single cookie is sent to the user (with expiry date e.g. equal to one year), the number of daily visits for the site would be something like this:

SELECT COUNT(DISTINCT CookieId) FROM Visits 
WHERE VisitDate = '2009-01-01' AND SiteId = 548

With multiple cookie system, you have to store only number of cookies issued per day per site and increment it every time you send a new cookie:

SELECT NoOfVisits FROM Visits 
WHERE VisitDate = '2009-01-01' AND SiteId = 548

This is a clear performance advantage when having hundred of millions of cookies issued each year.

like image 42
bbmud Avatar answered Sep 28 '22 14:09

bbmud