James Kennedy

James Kennedy

Personal Blog

© 2022

Back-of-the-envelope Facebook Election Ads Northern Ireland

As part of their transparency agenda Facebook launched their Ad Library reporting tool in March 2019 which gives users a view on ads relating to political and social issues in their country. Ads data in the repository starts from May 2018 and since that date you can query ads currently being run as well as those no longer active. In addition to the reporting tool they have an API for the Ad Library . You’ll need register as a developer and they send you out a code in the post prior to granting an access token.

I decided to have a rudimentary look at how the Northern Irish political parties used Facebook during their election campaigns for the poll on the 12th December 2019. Facebook have a python wrapper for the API here but there isn’t any docs yet, there is also a nice CLI script here which I used as reference when creating my own here, minus the command line - feel free to reuse.

The response format of the API is pretty disjointed but after massaging you get decent information on each ad. I’m interested only in ads that ran from the 6th of November, the official start date of the election, until polls closed. Sinn Fein & the UUP didn’t advertise during the election window so I’m left with the DUP, SDLP and Alliance.

There are many ways to query the data, I used the id from each party’s official Facebook page to return all the ads commissioned from that page - there may be more ads run from the candidates pages but I’m running on the assumption that the bulk of the ads are coordinated centrally.

For each ad you get a range for the cost and the impressions made. Everytime a user is presented with an advertisement on their feed, or the side of their page etc, an impression gets registered. Facebook will tell you that an ad cost between £0-99 or £200-299 and made 3000-3999 or 4000-4999 impressions so I took the average of the range and used that as a tally.

Ok - so how much did each party spend and how many impressions did their campaign make?

png

Alliance top the spend with £8600 with DUP next at £4400. SDLP are a non starter through this medium, their campaign priorities must be elsewhere. Unsurprisingly there is a near perfect correlation between spend and impressions.

You also get data on the percentage breakdown by demographic of the impressions made by each ad. So of the total impressions made during the campaign what was the demographic breakdown?

png

Alliance targeted the younger votes. I would expect the demographic profile for the DUP’s campaign to be older and these results don’t disprove that given this is only the targeted audience through facebook which itself is a forum for younger people.

The last item of interest is the message being conveyed to voters through the ad. I used the methodology laid out here for bag of words NLP. Simplistically this process sanitises each ad removing punctuation & non-alphabetic characters, it breaks each ad into a collection of words and for each word we extract it’s root so votes, voted, voting all output vote. This process works more or less… I then removed stop words, commonly used words that don’t convey anything substantive - the, of, and, etc. Scaling by impressions we can tally the words used during the campaign and visualise them by order of frequency.

png

If you followed the campaign the results don’t tell you anything you didn’t already know.

One final thought, instead of aggregating solely by party I split the data by demographic with the thinking that the message may be different between older and younger voters.

png

Nothing stands out, ah well. The NI parties don’t advertise through Facebook on the same scale as the UK parties, they are small fish in terms of resources & funding. So we don’t get a large dataset and the bag of words approach is somewhat naive given it doesn’t address sentence semantics.

My final thoughts are that the data released is insightful enough to warrant analysis and it would be interesting to monitor ads in real time over the next big election, the US presidential election would be a good candidate if it goes ahead.