Hello, I am an Engineering Manager at Facebook with 13+ years in Ad Technology, Natural Language Processing and Data mining. (Learn More)
by Pravin Paratey

Cookie Mapping in Advertising

Picture your daily activities on the internet. You search for things, you browse some news articles - perhaps commenting on a few; you watch a few videos - perhaps liking a couple and you post to your favourite social network.

Everything you do online leaves a trail on the websites you visit or on the tools you interact with. This data is invaluable to advertisers who build extremely complex models to understand you and to predict what products or services you would be interested in at any point in time.

Milk n Cookie

However, this data is heavily partitioned into silos. In most cases, the only way of identifying you is by storing an identifier in the browser cookie. This identifier is typically a string of randomly generated characters which is unique to you. Every time you visit a page on that website, your identifier is read from the cookie and the website stores your visit to that url in their logs.

Advertising companies partner with websites to access their log level data. However, there is a caveat. There is no way of telling who user 123 on that website is on the advertisers system. Cookie mapping is a process with which this information can be shared.

If that didn’t make sense

Let me give you an example to illustrate what I just said. Let’s assume all you do in a day is visit your local store and the cinema.

Visiting a shop

The local store knows a fair bit about you. It has an itemised list of food you buy and how much you spend. Your cinema knows the kind of films you watch and what popcorn and soft drink you enjoy. For an advertiser, this is data that it can use to build a profile on you.

Remember the caveat I mentioned earlier? Neither the store, the cinema or the advertiser know your name. They can’t ask you for your real name because you will be uncomfortable revealing that information and may choose not to shop at their store! So they store stuff about you under a pseudonym. The owner of the store calls you “the cute redhead” and files their copy of the receipt in a folder. The ticketmaster at the movies notes the movies you watch under the name “red shoes” while the advertiser calls you “customer 29”.

Going to the movies

Now, although each party has bits of information about you, the information is partitioned. The owner of the store only knows what you have done in their store. The ticketmaster at the movies only knows the kind of movies you watch and the beverages you consumed. While the advertiser has no way of knowing that “customer 29” is the same as “red shoes” and “the cute redhead”. Without this crucial piece of information, all the data from the store and the cinema is worthless to the advertiser!

To solve this, the advertiser comes up with an innovative way. He employs a bunch of errand boys who stand with a notepad at the store and the cinema. Now, every time a new customer is named with a pseudonym, the errand boys look up their notepad and write that pseudonym against their customer id. At the end of the day, when the advertiser picks up the folder from the store owner and the ticketmaster, he can match the pseudonyms against his own customer list using the errand boys’ notepad.

Back to where we were

So coming back, although an advertiser has access to log level data from all the websites he works with, the data is no good without a way of mapping their cookie ids to his own.

The job of the errand boy is done by a process called Cookie mapping or Cookie syncing. This enables the advertiser to track a user across several websites and internet tools.

How

Visiting a shop

So how does this process actually work? When you vist a website, there is a tiny pixel down on the page called a mapping pixel. For this example assume this is an image pixel of the form http://website.com/1x1.gif. Do note that at the backend, the 1x1.gif is NOT a static image but a script that looks like,

<?php
$user_id = $_COOKIE['user_id']; // Read the user cookie
// Set the user_id in the advertiser url
$advertiser_url = "http://advertiser.com/map?user_id=$user_id";
header("Location: $advertiser_url"); // Mapping call (302 redirect) to the advertiser 
?>

When the browser tries to get the image pixel resource, the php code redirects the browser to the advertisers’ server. A script on the advertisers’ server reads the user_id from the user_id parameter and stores the mapping in a database using a script like,

<?php
// Read the user cookie. This is the cookie id set by the advertiser
// It is different from the user_id above
$user_id = $_COOKIE['user_id']; 
$website_id = $_GET['user_id']; // Get the website's user id from the URL.

// Store the $user_id and $website_id in the database
store_mapping($user_id, $website_id);

header("Location: http://advertiser.com/1x1.gif"); // 302 redirect to a 1x1 image pixel
// Alternatively, just return the 1x1 pixel here.
?>

Now, at the end of the day when the advertiser receives log files from website.com, he can use the mapping table in the database to translate website user_ids into advertisers’ user_ids.

And that folks, is the how and the why of mapping calls.