Quickly clearing out your Facebook advert ‘interests’

October 4, 2018 27 By addshore

2020 EDIT: This solution is now packaged up as a nice browser extension. Click here to read the new post for details and links to the browser extension.

Over the past years, Facebook have had a few privacy related issues. First came the ‘scandal’ with Cambridge Analytica and more recently a bug (or series of bugs) that apparently affected 50 million accounts allowing peoples access tokens to be stolen. Oh, and there was also the story about Facebook using your 2 factor authentication phone number for targeting advertising.

With all of the goings on recently, as well as the new GDPR (General Data Protection Regulation) in the EU, Facebook have attempted to make the data that they have about an individual easier to see, understand and edit or remove. One such section of this data covers your “ad preferences“.

Screenshot of Facebook ad preferences

What is actually included here?

Starting at the bottom, there are three pretty fine grained tabs “Hide ad topics”, “Ad settings” and “Your information” that provide you with some control controls and in theory limit some of the data that Facebook will use while targeting.

The top two sections are far more general and contain multiple categories and elements within the categories. “Your interests” includes various interests that Facebook has decided that you have and should be targeting using. “Advertisers you’ve interacted with” shows any interaction with advertisers, including website visits, advert clicks, and advertisers manually adding your contact details it would seem.

Having a little scroll through all of the information here can be quite interesting. I struggle to see how Facebook has made some of the links that it has recorded here for my account, but I have been using Facebook for many years. What on earth is “The Suburban Collection” and why am I apparently interested in it?

Usability for removal

The two larger sections definitely look nice, but are they really that useable? No not really.

My interests section is split over 10 separate categories, each with their own tab for access. Each tab also does not display all interests at once, instead the user is forced to repeatedly click the “See more” link and scroll down the page, tens or hundreds of times. And then I have to target a small X in the top right of each interest box to remove it. No, there is no select all. At least there is no confirmation… It’s almost like Facebook doesn’t want to make removing this stuff easy.

A little bit of JavaScript

I figured rather than spending my time clicking on the thousands of elements that I would need to in order to removal all interests and advertisers that I have interacted with I would knock up a little bit of JavaScript.

I worked on a few different iterations but didn’t want to spend too much time on the problem so I ended up with the small functions below.

2020 EDIT: This solution is now packaged up as a nice browser extension. Click here to read the new post for details and links to the browser extension.

The code below was last updated on 15 October 2019 with an alteration from a comment. Using the browser extension linked above is recommended.

NOTE: Please only run this code if you know what you are doing/understand the code below. This code is licensed with the Unlicense.

// This is free and unencumbered software released into the public domain.
// For more information, please refer to <http://unlicense.org/>

// Find and return the position of the element given
function findPos(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        do {
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    return [curtop];
    }
}

// Click on the "See more" link
// Updated from https://addshore.com/2018/10/quickly-clearing-out-your-facebook-advert-interests/#comment-386
function clickSeeMore() {
    found = true
    while(found == true) {
        var seeMore = document.evaluate('//div[text()=\'See More\']', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
        if(seeMore) {
            window.scroll(0,findPos(seeMore)-200);
            seeMore.click();
        } else {
            found = false;
        }
    }
}

// Click on all X / Remove buttons currently on the page
function clickAllX(){
	var allX = document.evaluate('//button[@data-tooltip-content=\'Remove\']', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
	
	for (i=0; i<allX.snapshotLength; i++) {
		var next  = allX.snapshotItem(i);
		window.scroll(0,findPos(next)-200);
		next.click();
	}
}

// Combination, Click "See more" and then click all "Remove" buttons
function seeMoreAndClickXs() {
	clickSeeMore()
	clickAllX()
}Code language: JavaScript (javascript)

This can be directly copy and pasted into the developer console while browsing the “Ads interests” page. Then to run one iteration of the code that will click on “See more” once, followed by clicking on all “Remove” buttons currently visible just run the  seeMoreAndClickXs() function with the following:

seeMoreAndClickXs()

Of course you will probably have to run this function multiple times. If you run it and still see the “See more” link at the bottom of the section, then run it again!

Whats next?

Of course the developer console is going to warn you about the possibility of XSS attacks. Running things like this in the developer console isn’t ideal for the masses. Please only do things your comfortable with, give https://www.facebook.com/selfxss a read. Maybe I should turn this into a browser extension…

Ideally Facebook would just make their UX a little better. Why isn’t there just a “Remove all” button?

It would also be nice if this could be a single click thing, rather than having to run this function multiple times. But I couldn’t really get that done in the 15 minutes I dedicated to this task.

Interestingly although all of these interests are “Removed”, facebook still has this data about you, as it continues to list all of the removed interests. I wonder if they go away after a period of time? I imagine not. I wonder if GDPR allows for requests for specific information like this to be removed?

I also have no idea if Facebook was actually using this data in the first place, given my “Ad settings” specify that various types of Ads are already not allowed.