Launched in 2018, Facebook’s Ad Library allows you to search through all the political ads that pages have paid Facebook to serve. The Ad Library was one of Facebook’s responses to allegations that foreign ads were used to influence 2016’s US election, and UK Brexit referendum.

The core premise behind the Ad Library is simple. Input a page and it’ll give you details on the 5,000 most recent ads which that page has run.

The Ad Library doesn’t just tell you what each of the ads looked like, it also gives you some rough performance metrics. It gives you estimates of the number of times each ad was seen, and how much money was spent delivering that ad.

You can also ask Facebook for the demographic and geographic distributions users that each ad was served to. Aggregating this data can give you an intimate look at what political advertisers consider to be their target audience.

The Ad Library API

As great as the Ad Library is for political transparency, it’s difficult to pull any insights out of it unless you access its API. Without using the API, it’s difficult to pull any of the above statistics at scale, which is what you need in order to be able to find trends and insights in the data.

To be able to visualise these trends, I started by trying to pull Ad Library data into Google sheets via the Facebook API. I set up a script which pulled statistics on the one thousand most recent ads from each of the major UK political advertisers. These were:

The Conservatives

The Labour Party

The Liberal Democrats

The Brexit Party

To those familiar with UK politics, the Brexit party may stand out from the others in that it’s not typically considered a major political party (it doesn’t even have any members of parliament). I included it nevertheless because it spends a huge amount on Facebook Ads, often more than any of the other 3 parties on my list above.

Estimations & Assumptions

Once I had the ad data from each of the parties, I had to do some estimation. Facebook doesn’t give you precise values for the spend and impressions (the number of times an ad was seen) of each ad. Instead, it gives you ranges. A particular ad might have had somewhere between £0 and £99 spent on it, or received somewhere between 5,000 and 9,999 impressions.

One way I could’ve gotten around this would have been to assume that the expected value for each range was its midpoint. This is equivalent to saying that for an ad with spend between £0 and £99, we should expect its spend to be about £50.

While in most cases this seems like a sensible approach, I think there’s some reason to be hesitant of it when it comes to ads. Most Facebook advertisers create a huge number of ads, all with slightly different images or messages. Having such a large number of ads means that the majority of ads will receive just a small amount of spend.

Because of this, I speculated that the expected value for each range would be somewhere closer to its minimum. It’s impossible to tell how close, so I made the assumption that it would be 1/3rd of the way from a range’s minimum value to its maximum value. For example, if an ad had spend in the range of £0 to £99, I assigned it a spend of £33.

One of the things I was keen to look at in the data was how advertising spend changes over time. This was somewhat tricky to pull out of the Ad Library data, as you’re not able to split it by date. What you get is one row per ad, with fields for the start date and end date of that ad.

In order to be able to construct a time series of the data, I assumed that each ad’s metrics accumulated linearly. If an ad had an estimated spend of £33 (i.e. it’s actual range was between £0 and £99), and there were 11 days between its start date and end date, I assumed that it’s spend per day was £3.

Making this assumption made it possible to create tables of the ads metrics broken down by day. This in turn lets us see how the parties’ advertising varied over time.

After making the above assumptions, I set about incorporating the demographic and geographic distributions which the Ad Library provides you with. The API will tell you what proportion of people who saw an ad belonged to each gender, age range, and section of the UK.

By multiplying spend figures by these proportions, I was able to estimate what the parties were spending on each of these segments.

The Results

Once I had processed the data as outlined above, all in Google Sheets, I sent this data over to Data Studio to visualise it.

I built a report around it, with a little bit of narrative discussing what each of the graphs show. The data is live, updating each morning, so the commentary is left open to changes in the behaviour of these parties.

You can view the final report here.

Feedback

The dashboard is and will continue to be a work in progress. If you have any feedback, or ideas for additions, please do let me know in the responses below!