How does ad targeting work — in practice

Emil Hein
Ad-tech
Published in
5 min readMar 6, 2023

I’m here to give you a better understanding of how the technical implementation of targeting is done and what it unlocks — seen from the supply side.

Supply and demand in the ad space

Intro

In online advertisement, the game is supply and demand. Supply is the website(s) and by extension, the users, and the demand is the advertisement.

If I’m selling a car, and I want to show some ads to people interested in cars, it means that I'm on the demand side and have to find the correct users to show my ad to.

If I'm owning a website that displays ads, so I can keep my content free, it means that I'm on the supply side. I want to find the advertisers that want to pay the most to be displayed on my website.

Therefore we will mainly investigate this part of the system (the supply side):

Supply-side

Supply-side implementation

As a publisher (website owner or similar), your job is to “find” the advertisers that want to pay the most to be shown on your site. Contacting them in person is not a scaleable solution, so if you're depending on other revenue streams (programmatic) than direct partnerships with advertisers, you have to use an “Ad exchange”.

For the following examples, we are going to assume we are working with Google Ad Manager as our Ad Exchange. The documentation is clear. You can either set ad-unit-wise or site-wise targeting.

Site-wise targeting is set with this method

googletag.pubads().setTargeting('interests', 'basketball');

Ad-unit-wise targeting is set like this

googletag
.defineSlot('/6355419/Travel/Asia', [728, 90], 'banner-ad-1')
.addService(googletag.pubads())
.setTargeting('color', 'red') //
.setTargeting('position', 'atf');

With these two snippets, we are ready to expand the information we are sending to the Ad exchange to help it decide what advertisers whats to pay the most. At a technical level, most of all targeting works like this. You use some sort of library to send the targeting values to your Ad Exchange. As with many other things on the internet, it is all about HTTP requests/responses between clients (websites) and servers (Ad Exchange)

Our initial example looks like this:

Initial targeting v1

If we open my first example and look at the network requests, we can see the following:

Network requests for example v1

As you can see above, the HTTP request between the website and our AD Exchange directly includes the values, we have hardcoded on the page. This is great.
Now the Ad Exchange can pass on this information, so advertisers can know that this specific impression, has some information attached to it.

The advertiser now knows the following

  • A lot of automatically set keys &values (by Google). This includes some cookie values
  • Any consent Google is able to sniff up before the ad request
  • The publisher defined key/value of interest=sport, color=red & position=atf

This is

Enrich the impression

Now that we know how to send along targeting keys and values, we need some ideas as to how we can send as much data to the Ad Exchange so that we get the highest price per impression, while at the same time not sending evading the privacy of the user. And luckily there are a few ways

3rd party data!!!

I’ll start with this solution, as I will only say that this is not the future. It relies heavily on 3rd party providers to set cookies, so they can track users and share information with each other. This will be a practice that most browsers won’t allow, so we should not concern ourselves with this.

Contextual targeting

Contextual targeting is, well, something you can infer from the context the user is in. This can be anything from very simple to extremely advanced. Let’s see a simple example!

I have modified example v1 to now have a meta tag in the header of the page with a little description of the content.

<meta name="keywords" content="cars, trucks, car-reapir" />

By reading the above tag in Javascript, we can now pass that information along to the Ad exchange, so advertisers that sell cars, trucks, or auto-repair, might be more willing to pay a higher price.

The values are read by a simple method like this:

  const getMeta = (metaName) => {
const metas = document.getElementsByTagName('meta');
for (let i = 0; i < metas.length; i++) {
if (metas[i].getAttribute('name') === metaName) {
return metas[i].getAttribute('content');
}
}
return '';
};

We can now examine our new example page (v2) (https://web-platform-7jasot.stackblitz.io/)

Network requests for example v2

More context could be inferred than just some meta tags. One could decide to parse the whole article/page and try to decode some keywords based on the text or images.

More demand!

By using technologies like prebid, as I wrote about here (for beginners) it’s possible to “ask” other Ad exchanges before asking your final ad server. As the price is controlled by supply and demand, this will help increase your revenue. And how is this implemented, you might ask? — Via targeting.

Below here is an example of how prebid would look in regard to the final HTTP request to the Ad server

Network requests for example v3

Note on the above network request, that there is a targeting value = 1.50.
This is with the exact same method as all the other targeting, but this lets the final Ad Exchange know, that whatever advertisement you have to choose, has to pay more than 1.50$.

Browser Apis

With the phasing out of 3rd party cookies, newer and potentially better and more secure ways are being invented to emulate some of the 3rd party cookie's abilities.

With the new Topics API (currently experimental in Chrome), you could be able to determine a user's interests across multiple sites, even though the final stage of that API is not finalized.

1st party data

1st party data

This has the potential to be the most valuable data. This is data that you as a website have on your users.

The more data you can gather about your users, the better user profile you can create for them. This is somehow scary, but is also what keeps Facebook, Google, Snapchat, etc… in business.

When you know all your user's interests, across devices (with login), and maybe even their husband's/wife's interests, then you can start making very precise assumptions about what kind of ads would be relevant.

/Stay relevant

--

--

Emil Hein
Ad-tech

Fullstack developer. I enjoy prototyping and testing new services. I like working with JavaScript, Nodejs, AWS and Vue, Browser API's, adtech, Go + more